MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Programming / Design question

  • To: mathgroup at
  • Subject: [mg111608] Programming / Design question
  • From: ngry <nikita.kozlov at>
  • Date: Sat, 7 Aug 2010 01:32:14 -0400 (EDT)

Task: Compute "histogram feature" for certain object properties.
Object is represented by 2D point set. Histogram position(offset) and
integral object feature to compute is formalized separately.
My solution (mathematica code):

(* offset computation, single point update *)
PointUpdateResult[res_, x_, y_, Order_] := Block[ {offset = MyOffset[x, y, Order] },
   ++res[[offset,1]]; (* count *)
     res[[offset,2]] += Sqrt[x^2 + y^2]; (* "integral feature" *)
SetAttributes[PointUpdateResult, {HoldFirst}];

(* Per-point iteration *)
UpdateResult[res_, x_, y_, Order_, r_] := For[cr=0, cr<r, ++cr;
PointUpdateResult[res, x+cr, y, Order] ];
SetAttributes[UpdateResult, {HoldFirst}];

(* object processing *)
SectorFeatures[x_, Order_]:= Block[ { params=Runs[x], second_params Mec[x], resTable[{0,0},Order] (* Histogram "memory allocation" *)}, UpdateResult[res,second_params,Order,#] & /@ params;
  res // MatrixForm

As it can be seen, I have to simulate "pass by reference" for cyclic
accumulation of needed feature. Is there any hints to simplify
iteration for computing such histograms?
Or, something to simulate object identification by its key (I've used
unique offset in histogram)?

  • Prev by Date: Strange slow performance on macbook pro
  • Next by Date: Re: Format
  • Previous by thread: Strange slow performance on macbook pro
  • Next by thread: > classroom combinatorics