Robert - Just an initial test:
ts 'oblique test 55' |domain error: ProjRotate | projrotate`[email protected] POP;NV;QR Maybe it should be oblique=. 1 ? Also, unless you move the data initialization out of "test", you cannot compare results. So maybe you want to re-structure it to be something like: initData=: 3 : 0 POP=:((>:/)~i.y)*"2 (1000*i.2)+/(100*i.y)+/1+i.y NB. SERVICE AGE(?) NV=: (2, y+4,0) $,10000+(100*i.y+4)+/i.y NB. ANS AGE QR=: ((>:/)~i.y)*"2 (0.0001* (1000*i.2)+/(100*i.-y)+/1+i.-y) NB. SERVICE AGE POP;NV;QR ) test=: 4 : 0 NB. x: 0 for projection, 1 for rotation NB. y: service age, ans age, service age(?) projrotate`[email protected] (y) ) But even though my timings agree with what you showed: dat=. initData 55 ts '0 test dat' 0.16161181 97135616 ts '1 test dat' 0.65609685 62921152 The results are not the same: (0 test dat)-:1 test dat 0 Regards, Devon On Fri, Mar 20, 2009 at 1:51 PM, Robert Cyr <[email protected]> wrote: > Oblique results can be achieved by using rotate. The performance is quite > different. In a test example, > if > rotate =. 0 [ oblique =. 0 1 > then > ts 'rotate test 55' > 0.194581 9.71479e7 > > ts 'oblique test 55' > 0.870818 6.29288e7 > > For example, one can project the population of a given population by sex > age > and service. The estimation of the aging of a particular population and > its > consequences can then be estimated. The technique requires multiplication > along a 3d diagonal. > > test=: 3 : 0 > NB. x: 0 for projection, 1 for rotation > NB. y: number of age and service > : > POP=:((>:/)~i.y)*"2 (1000*i.2)+/(100*i.y)+/1+i.y NB. SERVICE AGE > QR=: ((>:/)~i.y)*"2 (0.0001* (1000*i.2)+/(100*i.-y)+/1+i.-y) NB. SERVICE > AGE > NV=: (2, y+4,0) $,10000+(100*i.y+4)+/i.y NB. ANS AGE > projrotate`[email protected] POP;NV;QR > ) > > ProjRotate=: 3 : 0 > NB. Population projection using rotation > NB. result by sex year age service will allow us to determine the probable > aging of our population. > NB. pop: number of active employees by sex(2), age(55=16 to 70), service(55 > = 0 to 54) > NB. new: number of new employees by sex(2), year of employment(50=years of > projection), age(55) > NB. srv: probability of survival (not dying,quitting or retiring) by > sex(2),age(55),service(55) > 'pop new srv'=.y > p=. pop,"2 3 (new,"1 (0)),"0 1"1 2 (0,"2 srv) NB. setup a matrix : > sex,year of projection, age,service > 'a n'=. (1 0)+ 1}.$new > r=. (,.)~i.a NB. to shift each slice to the left and to the top > by 1 for each year of projection > t=.-(0,0,a,a)+$p NB. to make space for our rotation > f=.2,a,1+n,n NB. to return to the original size > (-f){.(-r)|.!.0"1 2"2 3 */\"3 r |.!.1"1 2"2 3 t{.!.1 p > ) > > ProjOblique=: 3 : 0 > 'pop new srv'=.y > p=. pop,"2 3 (new,"1 (0)),"0 1"1 2 (0,"2 srv) > 'a n'=. (1 0)+ 1}.$new > r=. |."1|."2*//./.\"3|."2|."1 p NB. this is the 3d oblique > cumulative product, by year of projection > b=. (1+i.a)|."0 1 ((a,n)#0 1) NB. eliminate the unused rows of > the oblique > s=.|:n-(i.n)<./i.a NB. a rotation will position the > required results > n{."1 s|."0 1 " 2 3 b#"1 2"2 3 r NB. we retain the correct number of > columns > ) > ---------------------------------------------------------------------- > 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
