Patrick -
I agree with Roger's implication that the real value of converting your
models to J is to better understand them. You might start by converting
parts of a model directly but the real value comes from reformulating
lengthy, loopy code into concise array expressions.
I've recently been working on validating some C++ code that has a set of
calculations something like this:
switch(tm)
{ case 1: ret[tm]= parm1;
break;
case 2: ret[tm]= parm1 + parm2*ret[tm-1];
break;
default: ret[tm]= parm1 + parm2*ret[tm-1] + parm3*ret[tm-2];
break;
}
The actual calculations are much more complex but are similar in that the
third case is the general form of which the first two are specific examples.
I mentioned to the developer that he could get rid of the case statements if
he simply initialized his return vector to begin with a pair of zeros and
started his loop counter on the third element. This is a nice
simplification because it collapses three pieces of duplicate code into one,
thus reducing the chance of error when modifying it.
This sort of re-factoring falls naturally out of treating arrays as
first-class citizens and thinking of problems in ways that require fewer
"moving parts". The limitations of C++ prevent us from taking the above
simplification a step further as in Roger's example, but is still helpful
even in that language.
Regards,
Devon
On Thu, Jul 24, 2008 at 11:23 AM, Roger Hui <[EMAIL PROTECTED]> wrote:
> I doubt that automatic conversion of the specifications into
> J is possible in all cases. However, because of the superior
> interactive array manipulations in J it is definitely worthwhile
> to explore your time-series data in J.
>
> In the particular example in your msg,
>
> Contribution=: +/\ 0, MonthlyContribution
>
> (Contributions are the partial sums of 0
> catenated to the monthly contributions.)
>
>
>
> ----- Original Message -----
> From: Patrick van Beek <[EMAIL PROTECTED]>
> Date: Thursday, July 24, 2008 8:05
> Subject: [Jprogramming] Converting time dependant variables to J
> To: Programming forum <[email protected]>
>
> > I have been using actuarial models for some time and a common
> > theme is that
> > functions (variables) are defined in the model using simple code.
> > Typically there is a dependance on time, usually denoted by the
> > system varaible 't' which represents yaers or months since start
> > of the
> > calculation.
> >
> > A typical function for a variable say "Contributons" might be
> > along the
> > lines of
> >
> > If t = 0 Then
> > Contributon = 0
> > Else
> > Contributon(t) = Contributon(t-1) + Mtly_Contributon
> >
> > Where Mtly_Contribution is a (scalar) input
> >
> > A sequencer and compiler then strings all such functions
> > together and
> > creates an executable which takes any inputs and calculates the
> > variablesfor each value of t from 0 to a system value and
> > outputs them.
> >
> > I want to know if it is feasible to try to port my code to J
> > since on the
> > one hand I have specification which requires sequencing and
> > compilation and
> > on the other hand J is interpreted. Ideally I would like
> > to write a
> > J script which converts my specification into a J script which I
> > can then
> > run on the inputs.
> >
> > I was thinking that I could establish a list for each variable
> > in J with the
> > index defining which value of t. Say ContributionsJ was a list
> > in J to
> > represent the Contribiton functions above. I think the
> > equivalent of
> > Contribution(t) would be t { ContributionJ
> >
> > I was thinking of writing a script with a "for do End" loop
> > which increments
> > t. The various functions would then be calculated as t gets
> > incremented
> > However I am a bit of a loss how I would I would determing the
> > sequencingorder where there is interdependance between the
> > various variables from
> > different time periods. Is this something that is worth even
> > trying to do in
> > J?
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm