Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!sun-barr!ames!elroy.jpl.nasa.gov!jato!csi!sam
From: sam@csi.jpl.nasa.gov (Sam Sirlin)
Subject: Re: Stat workspaces for APL/J wanted
Message-ID: <1992Sep17.213736.20142@csi.jpl.nasa.gov>
Originator: sam@kalessin
Keywords: apl,stat,j
Sender: usenet@csi.jpl.nasa.gov (Network Noise Transfer Service)
Nntp-Posting-Host: kalessin
Organization: Jet Propulsion Laboratory, Pasadena, CA
References:  <russur.716752568@convex.convex.com>
Date: Thu, 17 Sep 1992 21:37:36 GMT
Lines: 85


In article <russur.716752568@convex.convex.com>, russur@convex.com (Russ Urquhart) writes:
|> If any has any apl/j workspaces containing statistics functions that are
|> either in the public domian or that they would be willing to share, I'b be
|> very grateful.

Ok, here are some rv generators that I recently setup for some optical
analysis. 

NB. for function setup
catb =. 'y.' : ' 1 |. y. ; x. '
com=. ' ''NB. '',y. ': ' 1 |. (com y.); x. '

NB. stuff for generating random signals
NB. gaussian stuff


NB. bounded gaussian distribution
a=. com   'bgauss y'
a=. a com ' parameters are (#, m, var, min, max)'
a=. a catb 'a=. erf (-/ 2 2$3 4 1 1{y.)%k=. (2{y.)*2^%2'
a=. a catb '(1{y.)+k*inverf (y*1{a)+(0{a)*1-y=. unif 0{y.'
bgauss=. a : ''

NB. error function
e=. 0.254829592 _0.284496736 1.421413741 _1.453152027 1.061405429
erf=. '(*y.) *1- (^-y.^2)*((%1+0.3275911*|y.)^/1+i.5)+/ . * e' :11

NB. inverse error function
a=. com 'x=. inverf y'
a=. a catb ' x=. y.'
a=. a catb 'loop) f=. y.-erf x'
a=. a catb ' x=. x+0.8862269255*f*^x^2'
a=. a catb ' $. =. ,> (1e_12 < >. /,|f){$.;loop'
a=. a catb 'x'
inverf=. a : ''

NB. uniform distribution
unif=. '(?y.$32767)%32766' : 11

NB. Poisson distributions

a=. com    'k =. poisson a'
a=. a com  ' poisson distributed k, parameter a'
a=. a catb 'u=. (^y.)*unif 1'
a=. a catb 'k=. 0'
a=. a catb 't=. 1'
a=. a catb 'h=. 1'
a=. a catb 'loop) $.=. ,> (h > u){$.;end'
a=. a catb 'h=. h + t=. t*y.%k=. k+1'
a=. a catb '$. =. loop'
a=. a catb 'end) k'
poisson=. a : ''

a=. com    'r=. poidc a'
a=. a com  '  poisson distribution table'
a=. a com  '  calculate enough so d > 0.999'
a=. a catb 'n=. 18+>. 1.18*y.'
a=. a catb 'i=. 1+i. n'
a=. a catb 'r=. (^-y.)*1, * scan (n$y.)%i'
a=. a catb 'r=. (0,i),r,: + scan r'
a=. a catb '(n,3){. |: r'
poidc=. a : ''

a=. com    'k=. n poissonn a'
a=. a com  '  Poisson distribution'
a=. a com  '  n values, parameter a'
a=. a catb '$. =. ,> (0 = ^-y.){ ok;$.'
a=. a catb 'print ''parameter too large (should be <714)'''
a=. a catb 'k=. i. 0'
a=. a catb '$. =. end'
a=. a catb 'ok)h=. poidc y.'
a=. a catb 'u=. unif x.'
a=. a catb 'k=. +/ (2{"1 h) </ u'
a=. a catb '$.=. ,> ( (>./k) < $ 0{"1 h) {$.; end'
a=. a catb 'print ''error: distribution not large enough'' '
a=. a catb 'end) k'
poissonn=. '' : a



-- 
Sam Sirlin
Jet Propulsion Laboratory         sam@kalessin.jpl.nasa.gov

