Question for Roger

A while back, I asked if there was a way to avoid loops when undertaking
sequential calculations through a matrix. I finally had a chance to look at
your approach in detail. I see what you are doing but didn't expect it. Your
verb sub appears to move through the n by 2 matrix in the desired sequence
(results of row n calculations used in row n+1). Does this depending upon
the execution order that J undertakes when processing matrices? I was under
the impression that it was better to be explicit about execution order as
different versions of J might employ different orders (see Henry Rich's JfC
"Order of Execution in Implied Loops"). Or maybe I have it all wrong and you
are using another construct. Anyway, enlightenment on this would be great as
it opens all sorts of other doors for my software projects. Thanks in
advance

Bob

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Roger Hui
Sent: April 28, 2008 4:07 PM
To: Programming forum
Subject: Re: RE: [Jprogramming] Calculations on matrices

Towards a more succinct solution:

sub=: 3 : 0
 'x y'=. y
 m=: {: x
 f ,: n=: ({.x) NVPA f=. y ,~ ({.x) FVPA^:_ ] 0.3
)

VPA=: 4 : 0
 y1 =.    >0{y
 y2 =. 0, >1{y
 n=: ({.x) NVPA y1
 1 0 2|:|.(y1,:n), sub"_1 }. (x ,:"1 nat_m) ;"_1 y2
)

   (naa ,: faa) -: caa VPA f_term;f_full_ages
1

It should be possible to avoid using globals.



----- Original Message -----
From: Robert O'Boyle <[EMAIL PROTECTED]>
Date: Sunday, April 27, 2008 7:11
Subject: RE: [Jprogramming] Calculations on matrices
To: 'Programming forum' <[email protected]>

> Here is the whole script. It is a work in progress so to speak. 
> 
> NB.============================================================
> caa=: 210796 26450 232147 49752 10592 1693 561 54 37
> caa=: caa,: 43630 270068 58591 308775 45479 13970 7722 1690 215
> caa=: caa, 47948 68430 238394 109814 159203 57948 4497 409 296
> caa=: caa, 751706 79933 65107 274518 72827 90617 31977 15441 5668
> caa=: caa, 70536 384467 118960 160723 110852 62506 22595 6345 2693
> caa=: caa, 106916 58166 285361 201097 120223 111911 41257 21271 7039
> caa=: caa, 144167 173662 106170 113561 75593 93620 50022 36618 7536
> caa=: caa, 649254 71984 148516 77207 75384 49065 48700 26055 13792
> caa=: caa, 29656 562616 109530 34422 25562 19361 17604 19836 9661
> caa=: caa, 118301 45600 616206 53199 15254 8120 5313 10964 5787 
> caa=: caa, 235590 158941 92356 384646 50599 9357 3239 3481 2842
> caa=: caa, 19922 161637 130597 72334 219788 18960 4967 3556 1835
> caa=: caa, 55634 19468 192823 106061 55066 150588 12466 2873 1253
> caa                   =: |."2 caa
> nat_m         =: 13 9$ 
> 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2
> f_term                =: (0.3 
> 0.41 0.76 0.9 1 1 1 1 1) * 0.4        
> full_ages     =: (7 8 9) - 0.2
> f_full_ages   =:      |. 0.139 0.351 0.372 0.525 0.340 0.514 0.562 0.773
> 0.564 0.358 0.389 0.352
> 
> NVPA  =: 4 : '(x*(y+m))%(y*(1-^-(y+m)))'
> 
> FVPA  =: 4 : '((}:x)*(y+}:m))%(((}.n)*^(y+}:m))*(1-^-(y+}:m)))'
> 
> BACKCAL =: 4 : 0
> n     =: x
> for_ccc. y
> do.
> m             =: ccc_index { mm
> f             =. ccc 
> (FVPA ^:_) 0.3
> f             =. f, 
> ccc_index { y2
> faa           =: faa, f
> n             =: ccc NVPA f
> naa           =: naa, n
> end.
> )
> 
> VPA   =: 4 : 0
> y1    =. > 0{y
> y2    =: > 1{y
> m     =: 0{ nat_m
> faa   =: ,: y1
> naa   =:      ,: (0{x) NVPA y1
> mm    =: }."2 nat_m
> (,naa) BACKCAL (}."2 x)
> naa   =: |. naa
> faa   =: |. faa
> )
> 
> caa VPA f_term;f_full_ages
> 
> NB.==================================================
> 
> The first bit is just data entry. VPA calls NVPA to set up the 
> startingconditions. Then it calls BACKCAL which undertakes the 
> row by row
> calculations, the main one (FVPA) being an iteration to find 
> roots. You will
> note that I have declared a number of variables global. This is 
> to speed up
> performance because this routine is part of a bigger 
> optimization which
> loops through these calculations literally thousands of times. 
> As I stated
> in my previous post, I initially configured BACKCAL to work with 
> insert /.
> This was OK if nat_m is a list, not a matrix as it is here. 
> Also, the speed
> gains were not great. Anyway, this code works. I'd just like to 
> know if
> there is a way in J to really speed up the row by row processing.
> 
> Bob
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

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

Reply via email to