Ah, yes.  Thanks Raul.

Perhaps this is a question for the programming list.  I seem to always write
functions like this:

<bunch of local tacit definitions>
<global tacit definition that references above local definitions>

And then I flatten the final function using f. in the global definition.
This makes these big long tacit definitions more readable.  I'm just
concerned with cluttering the namespace in a file with all those local
definitions.  If I'm writing functions like this, should I put them each in
a separate file?  Should I create a locale for every function?  Just
wondering if this is good practice to write functions like this, and if so
how to deal with the locals.  And since it's tacit, AFAIK I can't use the
locality of an explicit definition like 3 : 0.  And 13 : 0 only works on one
line.

An example follows my signature in case that wasn't clear.  There are two
functions, and they both locally try to define 'mu.'  Here it isn't a
problem because it just gets redefined.  It just creeps me out having the
local definitions accessible by both function definitions.  I am comfortable
putting these in separate files.  But it would be nice to know a way to put
them in the same file.

Thanks again!

Chris

NB. joint_prior mu;B;Q;L

  mu =. 0&{::@:]
  B =. 1&{::@:]
  Q =. 2&{::@:]
  L =. 3&{::@:]

  Pa =. */@:(2&{.)@:$@:B -@:<. #@:[
  mu_Pa =. Pa {. mu
  B_Pa =. Pa {."1 ,./@:B
  Q_Pa =. Pa {."1 Pa {. [

  mu_W_t =. [ , mu + (B_Pa (+/ .*) mu_Pa)

  s11 =. [
  s12 =. B_Pa (+/ .*) (Pa {. [)
  s21 =. |:@:s12
  s22 =. Q + (B_Pa (+/ .*) Q_Pa) (+/ .*) |:@:B_Pa
  sigma_W_t =. ((s11 , s12) ,. (s21 , s22)) f.

  mu_W =. mu (mu_W_t ^: (<:@:L@:])) ]
  sigma_W =. Q (sigma_W_t ^: (<:@:L@:])) ]

  joint_prior =: (mu_W ; sigma_W) f.


NB. condition_LCG mu;sigma;yidx;yval

  mu =. 0&{::
  sigma =. 1&{::
  yidx =. 2&{::
  xidx =. -.@:yidx
  yval =. 3&{::

  mux =. -.@:yidx # mu
  muy =. yidx # mu

  sxx =. xidx #"1 xidx # sigma
  sxy =. yidx #"1 xidx # sigma
  syx =. xidx #"1 yidx # sigma
  syy =. yidx #"1 yidx # sigma

  mu_x_given_y =. mux + sxy (+/ .*) %.@:syy (+/ .*) (yval - muy)
  sigma_x_given_y =. sxx - sxy (+/ .*) %.@:syy (+/ .*) syx

  condition_CLG =: (mu_x_given_y ; sigma_x_given_y) f.


On Tue, Mar 23, 2010 at 12:12 PM, Raul Miller <[email protected]> wrote:

> You have probably long since realized this, but, in:
>
> s11 =. [
> s12 =. padB@:[ (+/ .*) [
> s21 =. |:@:s12
> s22 =. ] + ((padB@:[ (+/ .*) [) (+/ .*) |:@:padB@:[)
> absorbNode =: ((s11 , s12) ,. (s21 , s22)) f.
>
> you could have instead used
>
> s22 =. ] + s12 (+/ .*) |:@:padB@:[
>
> (and those parenthesis are unnecessary.)
>
> FYI,
>
> --
> Raul
> ----------------------------------------------------------------------
> 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