Jacobs, Jan wrote:
> John,
> In my function f I have to access a global array (Gh and T) and I do
need the iteration count for that. The context is stochastic image
processing and I use a Simulated Annealing scheme.
> My f looks like:
> f=:3 : 0
>       'state index'=.y.
>       nstate=.index{Gh
>       TEMP=.index{T
>       e=. (lhood state) + state prior state
>       ne=. (lhood nstate) + nstate prior state
>       de=. ne - e
>       accept=. de <: - TEMP * ^. ALPHA
>       state=.(nstate*-.accept)+state*accept
>       state;>:index
> )
> And I call it e.g. by:
> f^:n (g0;0)
>
Jan:

If you want to get rid of explicitly mentioning index when you call the
function, I suggest the following, which allows you to get your result as

>{: F^:n (< g0)

First modify f so that index is a left hand argument and state is an
unboxed right hand argument.  Then define a verb F which operates on

g0;(f g0);...;(f^:(n-1) g0)

by

F=:3 : 'y; (<:#y) f > {: y'

This appends the next iterate, while supplying index as the argument to f.

F keeps track of index by actually retaining the prior iterates.  I
imagine that your images might be quite big.  You can also count using
empty boxes except for the last:

F=:3 : 0
index=:<:#y
last=:>{:y
(}:y),a:,< index f last
)

Best wishes,

John






----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to