One of my pet peeves: Rather than
e=. (lhood state) + state prior state
ne=. (lhood nstate) + nstate prior state
I would write:
e =. (lhood state ) + state prior state
en=. (lhood staten) + staten prior state
With the second version I can more readily tell
what's different and what's the same between the
two lines.
----- Original Message -----
From: "Jacobs, Jan" <[EMAIL PROTECTED]>
Date: Thursday, December 14, 2006 2:46 am
Subject: RE: [Jgeneral] Recursive function
> 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)
>
> Can this process be done more elegant?
> Thanks in advance,
> Jan.
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [EMAIL PROTECTED] On Behalf Of John Randall
> Sent: donderdag 14 december 2006 0:27
> To: General forum
> Subject: Re: [Jgeneral] Recursive function
>
> Jacobs, Jan wrote:
> > Ls,
> > I need to evaluate gn =: f^:n (g0) where g0 is an gray-level image.
> > f is a recurrent relation g(n+1)=f(g(n)) but needs the iteration
> > count, one out of 0..n-1, for indexing in a global array.
> > I managed to do this by f^:n (g0,0) and splitting the argument
> in an
> > image and index by 'state index'=.y. and construct at the end
> (f
> > state);>:index but this is not elegant.
> > How do I this the right way?
> > Jan.
> >
> I don't completely understand the question, but I think you need
> to look
> at the Vocabulary page for ^: . You can assemble a specified
> number of
> iterates into an array, and get all the iterates up to a fixed point:
>
> s=:_2 0 1&p.
> newton=:1 : ']- u%u d. 1'
> f=:s newton
>
> f^:(i.10) 2 NB. first 10 iterates
> 2 1.5 1.41667 1.41422 1.41421 1.41421 1.41421 1.41421 1.41421 1.41421
> f^:(<10) 2 NB. first 10 iterates
> 2 1.5 1.41667 1.41422 1.41421 1.41421 1.41421 1.41421 1.41421 1.41421
> f^:(<_) 2 NB. iterates to fixed point
> 2 1.5 1.41667 1.41422 1.41421 1.41421
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm