Just retry,the result is stable.my j version is j64-602a,os is debian
linux64,cpu is amd tl-58(dual core,1.8G).
ts '0.1 EMA i.1e6'
2.918746 314334976
ts '0.1 EMA1 i.1e6'
3.898926 67112192
ts '0.1 EMA2 i.1e6'
0.321607 50333696
9!:14 ''
j602/2008-03-03/16:45
2008/3/10, Roger Hui <[EMAIL PROTECTED]>:
> I can not reproduce your timings. The following is what I got:
>
>
> EMA=:((2 % [:>: #) $: ]) : (4 :'(((x * [) + (-.x) * ])/\.)&.|. y')
>
> EMA1=:((<a:;1)&{)@:((([EMAIL PROTECTED] , (*/@[) + (1- [EMAIL PROTECTED]) *
> {:@])/\.)&.|.)@:,.
> recur=:[ (] * [:+/\ [ % ]) [: */\ ]
> EMA2=:([EMAIL PROTECTED] , [ * [EMAIL PROTECTED]) recur (1, (<:@[EMAIL
> PROTECTED]) $ [EMAIL PROTECTED])
>
> ts=: 6!:2 , 7!:[EMAIL PROTECTED]
>
> ts '0.1 EMA i.1e6'
> 3.74642 1.61362e8
> ts '0.1 EMA1 i.1e6'
> 4.75599 6.29162e7
> ts '0.1 EMA2 i.1e6'
> 2.41342 4.61384e7
>
> EMA2 is faster, but not by a factor of 10.
>
>
>
>
> ----- Original Message -----
> From: Xu Zuoqian <[EMAIL PROTECTED]>
> Date: Saturday, March 8, 2008 20:34
> Subject: Re: [Jprogramming] Is there a tacit version EMA?
> To: Programming forum <[email protected]>
>
>
> > Oh,Mike,your solution is so beautiful!
> >
> > recur=:[ (] * [:+/\ [ % ]) [: */\ ]
> > EMA2=:([EMAIL PROTECTED] , [ * [EMAIL PROTECTED]) recur (1, (<:@[EMAIL
> PROTECTED]) $ [EMAIL PROTECTED])
> >
> > (0.1&EMA -: 0.1&EMA2) p:i.10
> > 1
> >
> > 6!:2 '0.1&EMA i.1e6'
> > 2.80876
> >
> > 6!:2 '0.1&EMA1 i.1e6'
> > 3.781998
> >
> > 6!:2 '0.1&EMA2 i.1e6'
> > 0.314285
> >
> > 2008/3/9, Mike Powell <[EMAIL PROTECTED]>:
> > > Xu,
> > >
> > > Your EMA question is related to algorithms for linear
> > recurrence> relations. There is a much loved algorithm
> > (probably because it's
> > > usually found to be lean and mean) that I first
> > encountered at IP
> > > Sharp in a newsletter quiz. We used it all over the place,
> > > particularly wherever a present value or discounted cash
> > flow was in
> > > play. Where it came from before that, I know not. It
> > goes like this.
> > >
> > > If you have a linear recurrence relation of the form:
> > >
> > > r[0] is m[0] times a[0]
> > > r[i] is a[i] + m[i] times r[i-
> > 1] (i >0)
> > >
> > > then this can be calculated in vector languages in the
> > following way:
> > >
> > > a recur m;t
> > > t is timesscan m
> > > r is t times plusscan a div t
> > >
> > > I'd be most interested to see a J algorithm for this,
> > particularly a
> > > tacit one. I note that we have a reflexive piece (t) and
> > that there
> > > may be an opportunity for an inverse (* and %).
> > >
> > > As far as the EMA is concerned, I suggest Xu's original
> > requirement is
> > > solved with:
> > >
> > > (y[0] , k times 1 drop y) recur (length y) replicate 1 - k
> > >
> > >
> > > Mike Powell
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm