Hi All,
I am writing a program to generate two dimensional histograms but find that
the "out of memory" error is generated for reasonable sized datasets. So far
I have come up with the code below.
Is there an alternative to *. which would avoid the out of memory error
without doing an explicit
for loop? Would the problem be solved by using J64?
I just want to "and" each corresponding atom like in the following:
$mx
484 200000
$my
484 200000
mx*.my
|out of memory
| mx *.my
Also, how can I add x and y labels to the output of viewmat?
Thanks,
Matthew.
load 'viewmat'
histogram2D =: 4 : 0 "_ 2
bx =. (__ , ( 0{::x )) ,. _ ,~ ( 0{::x ) NB. cut boundaries
by =. (__ , ( 1{::x )) ,. _ ,~ ( 1{::x ) NB. cut boundaries
b =. _4 ]\ , bx ,"_1 _"_ _1 by NB. corners of grid boxes
lbx =. ([: 0&{ [) NB. verb to get lower bound from the pair of
bounds
ubx =. ([: 1&{ [) NB. verb to get upper bound from the pair of
bounds
lby =. ([: 2&{ [) NB. verb to get lower bound from the pair of
bounds
uby =. ([: 3&{ [) NB. verb to get upper bound from the pair of
bounds
mx =. b ( (] >: lbx ) *. ( ] < ubx) )"1 1 ( 0 {"1 y ) NB. mask for
datapoints in each boundaries
my =. b ( (] >: lby ) *. ( ] < uby) )"1 1 ( 1 {"1 y ) NB. mask for
datapoints in each boundaries
m =. mx *. my NB. each point is in one and only one box
hz =. (- # by ) ]\ ( [: (] % +/) +/"1 ) m
hx =. (2: %~ lbx + ubx)"1 b
hy =. (2: %~ lby + uby)"1 b
viewmat hz
hx;hy;hz
)
NB. example
((steps _4 4 20);(steps _4 4 20))histogram2D (((normalrand
100000),.(normalrand 100000)),.1)
NB. but this runs out of memory on line "m =. mx *. my "
((steps _4 4 20);(steps _4 4 20))histogram2D (((normalrand
200000),.(normalrand 200000)),.1)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm