[Thread Prev][Thread Next][Index]

Re: forcing multiple evaluation of a function



Hi Brian,

Ferret's architecture assumes that for a given input you will always get
the same (reproducible) output. If you create an external function that
violates this results will be "unpredictable" (well, at least that will do
for terminology).

The typical way that you would achieve your goal in Ferret is to "seed"
your Monte Carlo calculation based upon something which does change in the
function call. For example, your function might be altered to have 3
arguments:
    OMEGASORT_EXC(OM,PR,SEED)
Then you could execute your loop as
    yes? repeat/l=1:2 list omegasort_exc(om,pr,`l`)

Note that the random number gererators supplied in Ferret -- RANDN(seed)
and RANDU(seed) -- also function this way.

    - steve

=======================================

Brian Rose wrote:

> Hi ferreters,
>
> As part of a Monte Carlo simulation, I've written an external function
> which operates on the given data based on some random numbers it
> generates.  I want to evaluate the function several times on the SAME
> data, but Ferret doesn't recognise that it needs to update the values.
> Here's an example:
> (The external function is called "omegasort_exc" and it returns two
> scalars indexed on the k axis)
>
> If I interactively LIST the result several times, the function gets
> re-evaluated:
>
> yes? list omegasort_exc(om,pr)
>              OMEGASORT_EXC(OM,PR)
>              LATITUDE: 3.8N to 5.7N
>  1 / 1: -0.001003
>  2 / 2:  0.000016
> yes? list omegasort_exc(om,pr)
>              OMEGASORT_EXC(OM,PR)
>              LATITUDE: 3.8N to 5.7N
>  1 / 1: -0.001054
>  2 / 2:  0.000014
>
> (the result changes)
>
> But within a loop:
>
> yes? repeat/l=1:2 list omegasort_exc(om,pr)
>              OMEGASORT_EXC(OM,PR)
>              LATITUDE: 3.8N to 5.7N
>  1 / 1: -0.001067
>  2 / 2:  0.000014
>              OMEGASORT_EXC(OM,PR)
>              LATITUDE: 3.8N to 5.7N
>  1 / 1: -0.001067
>  2 / 2:  0.000014
>
> (the result does not change)
>
> How can I force Ferret to re-evaluate the function on each pass through
> the loop?
>
> Thanks for any help,
>
> Brian Rose

--
Steve Hankin
NOAA/PMEL, 7600 Sand Point Way NE, Seattle, WA 98115-0070
ph. (206) 526-6080 -- FAX (206) 526-6744




[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement