I think something like your last one is the most J-like.  One problem with
replicating the argument would be that a very large number of simulations,
say 100s of millions or more, would introduce unnecessary memory overhead.
However, in cases where I've done this sort of thing, I've just broken the
very large case into some number of smaller ones.  For simulations of a
million or so, this should not be much of a problem.

An advantage of replicating the argument is for doing more statistics on
the results than simply averaging them, e.g. calculating the standard
deviation or looking at the distribution, since your result is an array of
results of your simulation.

The exact details of how you would want to do this might depend on the
nature of your simulation.  So, using the power conjunction would make
sense if the input from one iteration of your simulation is the argument to
the next one.  You could force the use power in your case but it would
complicate the expression.

On Mon, Aug 13, 2018 at 1:04 PM Ulrich Vollert <[email protected]> wrote:

> Hello,
>
> for some weeks, I am learning J in my (very little) spare time. And I have
> a (beginner) question.
>
> After reading a lot (first place: „Learning J“) and doing some exercises,
> I am developing a small Monte Carlo simulation.
>
> I have a dyadic verb „play“ which does a simulation step (calling random
> generator, calculating) and answering a result. My first attempt to call
> this verb in a loop was:
>
>  simuls=: 1000  NB. count of simulations
>
>  i=. simuls
>  result=.0
>  while. i > 0 do.
>    result=.result + x play y
>    i=.i-1
>  end.
>  result % simuls
>
> But this doesnt look and feel as J style. My second attempt is to
> duplicate the second argument as often as I want to do the simulation:
>
>  (+/%#) x play_hand (simuls # y)
>
> or shorter:
>
>  (+/%#) @: play_hand simuls&#
>
> I am wondering whether this is a good solution (for instance: space
> efficiency)? Would a solution with Power (^:) a better approach?
>
> Thanks in advance for your comments.
> Ulrich
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm



-- 

Devon McCormick, CFA

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

Reply via email to