[Jprogramming] Matrix calculations
Robert O'Boyle
bcubed at accesswave.ca
Mon Jan 18 01:14:34 HKT 2010
Thanks, Aai
The output for this example is what I am looking for but I don't think that
I can use tacits for my ultimate purpose. My test function is actually a
small example of a larger class of equations that I wish to apply to each
list of each plane in successive order. I was thinking that if I could get
this small example to work, the larger class would work. Going to tacit will
likely not work on the larger class. In the larger class, each list is a
boxed list of 5 - 10 lists (that's why I used boxing). I read these in,
apply a series of equations to these (some involving Newton-Raphson root
solutions and other non-linear optimizations) and estimate one output list
(my out noun) that is then used as the input to the calculations of the next
list, and so on down each plane of the 3-D matrix. Also, the a is the 5 - 10
lists while the b is a list of scalars that can change from time step to
time step. I have found it convenient in the 2-D situation to keep a and b
in separate boxes. The 10 20 30 is quite arbitrary but would be the same for
each plane.
Basically, I am fiddling around with the array power of J to solve Monte
Carlo (MC) simulations of natural populations. My input is a starting
population at age list which is then modified by birth, mortality and growth
processes, as provided in the 5 - 10 lists (the a noun) and under different
human impacts (the b noun), at each time step (e.g. year) which is each row
of each plane. The output of these calculations is the starting population
at age for the next time step (row). I was thinking that each plane
(ultimately 1,000 - 5,000 or so, depending on the problem) would have a
different starting population at age, as generated from sampling off a
parent distribution. Each plane's calculations is then one run of the MC
simulation. Up to now, I have used looping but it is slow i.e. have one 2 -D
matrix which I loop through different starting populations at age.
I thought that Roger's approach would work but my rank combos have failed to
produce the desired matrix which you indicated below.
I am still trying different rank permutations but open to all suggestions.
Bob
-----Original Message-----
From: programming-bounces at jsoftware.com
[mailto:programming-bounces at jsoftware.com] On Behalf Of Aai
Sent: January 17, 2010 8:00 AM
To: Programming forum
Subject: Re: [Jprogramming] Matrix calculations
If I understand correctly, you want something like:
0 1 2 3
4 15 26 37
48 159 270 381
0 1 2 3
4 25 46 67
88 509 930 1351
0 1 2 3
4 35 66 97
128 1059 1990 2921
This can be done by using a (non reducing modifying) fold. I will also
use non-boxed data.
data=: (3 3 4$i.12),"1 0 (10 20 30)
I don't use the noun 'out', because the first row of each plane will
serve as the initial element. I also separate the modifier verb, so it
is easy to compose another modifier.
NB. a + out * b
modify=: }:@[ + {:@[*}:@]
NB. modify fold a plane
domodify=: 13 :'(]`,:@.(1=#@$)y), x modify {:`]@.(1 = #@$) y'
Though I'm not very happy with this 'ugly' verb, because of the left and
right gerunds to handle the initial state. Perhaps this will serve as a
start for a better solution by the J-experts.
([: }:"1 domodify/@|.)"2 data
0 1 2 3
4 15 26 37
....
...
But only, if this is what you want :-)
Hallo Robert O'Boyle, je schreef op 16-01-10 21:00:
> Hi all
>
>
>
> I am doing some probabistic population projections and have come up with a
> problem. I have an arbitrary 3 x 3 x 2 matrix
>
>
>
> data =. (3 3 4$i.12);"1 0 (10 20 30)
>
>
>
> and a noun out =. 0 0 0 0
>
>
>
> What I would like to do is separately for each plane of data to apply a
verb
> TEST
>
>
>
> TEST =: 3 : 0
>
> 'a b' =: y
>
> out =: a+out*b
>
> )
>
>
>
> which multiplies out by the second row scalar, adds this to out and then
> reassigns out.
>
>
>
> This works great for a simple matrix
>
>
>
> TEST"_1 (0{data)
>
>
>
> But when I try
>
>
>
> TEST"_2 data I get (sorry for the formatting)
>
>
>
> 0 1 2 3
>
> 4 25 46 67
>
> 128 759 1390 2021
>
>
>
> 1280 7591 13902 20213
>
> 25604 151825 278046 404267
>
> 768128 4.55476e6 8.34139e6 1.2128e7
>
>
>
> 7.68128e6 4.55476e7 8.34139e7 1.2128e8
>
> 1.53626e8 9.10952e8 1.66828e9 2.4256e9
>
> 4.60877e9 2.73286e10 5.00483e10 7.27681e10
>
>
>
> It applies the verb sequentially through all the lists of the 3 planes.
What
> I would like is the verb to be applied separately to each plane. In this
> case, I would have the same output for each plane. Ultimately, I will be
> sampling the first row of each plane from a population distribution and
then
> undertaking, say, 500 -1000 projections (each of these being a plane in
> data).
>
>
>
> I have tried a number of rank conjunctions formulations to no avail. I'm
> sure it is simple to do but I am just learning the nuances of the rank
> conjunction.
>
>
>
> Any help would be most appreciated.
>
>
>
> Bob
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
>
--
Met vriendelijke groet,
=@@i
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list