given these two functions:
rema:{[tau;x] alpha:: 1%tau; mu::exp(-1*alpha); upsilon::(1-mu)%alpha; :upsilon ema x; }; iema:{[n;tau;x] rema1:: rema[tau;x]; $[n=1f; :rema1 ;[show "recursion"; .z.s[n-1f;tau;rema1]] ]; };
when I try to run
c:iema[2f;10f; 1 2 3 4 5 6 7 8 9]
it returns
c:iema[2;10f;1 2 3 4 5 6 7 8 9]1 1.951626 2.949286 3.949173 4.949167 5.949167 6.949167 7.949167 8.949167"recursion"1 1.905592 2.898798 3.898362 4.898335 5.898334 6.898334 7.898334 8.898334
but c returns nothing when evaluated while rema1 evaluates as:
rema11 1.905592 2.898798 3.898362 4.898335 5.898334 6.898334 7.898334 8.898334
Any idea on why the function is not returning rema1?
This bit returns a value:
.z.s[n-1f;tau;rema1]]
but the trailing semi-colon on that line ultimately suppresses the return value, e.g.:
q)foo:{1}
q)foo
1
q)foo:{1;}
q)foo
q)
even if i try to remove that trailing ; it still doesnt work
Try removing the c: assignment as this will also suppress output.
rema:{[tau;x]
alpha:: 1%tau;
mu::exp(-1*alpha);
upsilon::(1-mu)%alpha;
:upsilon ema x;
};
iema:{[n;tau;x]
rema1:: rema[tau;x];
$[n=1f; :rema1 ;[show “recursion”; .z.s[n-1f;tau;rema1]] ]
};
iema[2f;10f; 1 2 3 4 5 6 7 8 9]
thanks removing the trailing ; worked.
Attila
6
note that in newer versions there is a builtin and as such more performant ema function
you mean the ema function? I am utilizing it here I had wrapped it to allow for nested emas, any ideas on how to do it better?
Try this:
c:iema[2f;10f; 1 2 3 4 5 6 7 8 9]c~2 rema[10f]/1+til 9
Attila
9
right, i missed that you’ve already used ema
you can also compute once upsilon
q)h:{(1-exp neg a)%a:1%x}
q)c~2 ema[h 10]/1 2 3 4 5 6 7 8 9
1b
in general it’s best to avoid global assignment (::) inside functions whenever possible