On Wed, Mar 24, 2010 at 4:09 PM, Chris Barber <[email protected]> wrote:
> 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.
Putting them in separate files makes sense to me.
That said, you can do something like this:
NB. joint_prior mu;B;Q;L
''1 :0
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.
)
Here, I encapsulate the definition of joint_prior in an
invocation of anonymous adverb, so the local names
vanish.
FYI,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm