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]
[mailto:[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

John


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


This message and attachment(s) are intended solely for use by the addressee and 
may contain information that is privileged, confidential or otherwise exempt 
from disclosure under applicable law.

If you are not the intended recipient or agent thereof responsible for 
delivering this message to the intended recipient, you are hereby notified that 
any dissemination, distribution or copying of this communication is strictly 
prohibited.

If you have received this communication in error, please notify the sender 
immediately by telephone and with a 'reply' message.
  
Thank you for your co-operation.


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

Reply via email to