Hi,
Just thought I'd share my beginning experiences.
Working on reimplementing a MATLAB application in J. The following snippet
performs about the same in J. And the MATLAB version is nearly as terse.
But I still thought it might be fun to look at a side-by-side. And I have a
few things to look forward to:
1. This was fun to implement. Usually I'm holding back vomit when I code in
MATLAB.
2. I think it will perform better in the long run. Higher-level parts of my
MATLAB code have some major for-loop action going on. I expect the J
version to be much more easily and intelligibly implemented in an array
style, and that it will perform better as a result. Hoping the tacit
implementation of this low-level function will pay off in the long run too.
Regards,
Chris
======= MATLAB =======
nonparents=mvn.sz-lcg.nparents;
if nonparents>=0
lcg.b=[zeros([lcg.sz nonparents]) lcg.b];
else
lcg.b=lcg.b(1-nonparents:end);
end
mvn2=newMVN(mvn.sz+lcg.sz);
mvn2.m=[mvn.m; lcg.b0+lcg.b*mvn.m];
mvn2.s(1:mvn.sz,1:mvn.sz)=mvn.s;
mvn2.s(mvn.sz+1:end,1:mvn.sz)=lcg.b*mvn.s;
mvn2.s(1:mvn.sz,mvn.sz+1:end)=mvn2.s(mvn.sz+1:end,1:mvn.sz)';
mvn2.s(mvn.sz+1:end,mvn.sz+1:end)=lcg.s+lcg.b*mvn.s*lcg.b';
========== J ==========
padB =. {."1&B@:-@:#
mu_W =: ,((padB mu)&(+/ .*)^:(i. L)) mu
s11 =. [
s12 =. padB@:[ (+/ .*) [
s21 =. |:@:s12
s22 =. ] + ((padB@:[ (+/ .*) [) (+/ .*) |:@:padB@:[)
absorbNode =: ((s11 , s12) ,. (s21 , s22)) f.
sigma_W =: absorbNode&Q^:(L-1) Q
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm