Is there an error function in kdb as there is in C (supplied bymath.h)?http://en.wikipedia.org/wiki/Error\_function
User-Agent: G2/1.0
X-Google-Token: vLK8JgwAAACjAuFVXenHeabL3k6CYR0B
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US;
rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12 GTB6 GTBA,gzip(gfe),gzip(gfe)
Message-ID: <98be3673-f52b-41aa-862d-3834e8af4c9d@u16g2000pru.googlegroups.com>
Subject: Re: Error Function
From: aka_magnus <niall.rea>
To: “Kdb+ Personal Developers”
X-Google-Approved: charlie@kx.com via web at 2009-10-27 21:00:20
you’ve answered your question
// qerf.c
#include"k.h"
K qerf(K v){
float v1=erf((float)v->f);
return kf(v1);
}
// gcc -fPIC -shared qerf.c -o erf.so -lm
in q
q)erf:($":./erf") 2:(
qerf;1)
q)erf(1.1)
0.8802051
</niall.rea>
see for example http://www.gbkr.com/subjects/q/barrierdiffusion.html
the erf function there can be vectorized and improved a bit
q)erfV:{1&(z*y)*1+sum prds neg[z*z]*/:x}[(%)over .5 1 1.5+:til
42;2%sqrt acos -1]
q)x:(-200000+til 100000)%100000
q)erfV~erf each x
1b
q)\t erf each x
353
q)\t erfV x
66
but using C is of course faster
K1(erfM){R xt!=-KF?krr(“type”):kf(erf(xf));}
q)erfM::./erf 2:
erfM,1
q)\t erfM each x
22
q)erfV~erfM each x
q)1b
if you vectorize the C function you can get even more speed
K1(erfMV){P(abs(xt)!=KF,krr(“type”))if(xt<0)R kf(erf(xf));K r=ktn
(KF,xn);DO(xn,kF(r)[i]=erf(xF[i]))R r;}
q)erfMV::./erf 2:
erfMV,1
q)erfMV~erfM each x
1b
q)\t erfMV x
9
Regards,
Attila
On 27 Oct 2009, at 20:59, aka_magnus wrote:
>
> you’ve answered your question
>
> // qerf.c
>
> #include"k.h"
>
> K qerf(K v){
> float v1=erf((float)v->f);
> return kf(v1);
> }
>
> // gcc -fPIC -shared qerf.c -o erf.so -lm
>
>
>
> in q
> q)erf:($":./erf") 2:(
qerf;1)
> q)erf(1.1)
> 0.8802051
>
>
>
>
> On Oct 23, 11:51 am, Jamie Dumbill <jamie.dumb…> wrote:
>> Is there an error function in kdb as there is in C (supplied by
>> math.h)?
>>
>> http://en.wikipedia.org/wiki/Error_function
>
> >
–Apple-Mail-24–756243888
Content-Type: text/html
space; -webkit-line-break: after-white-space; “>-span” face=3D"Monaco" size=3D"3">“font-size: 12px;”>see for example q/barrierdiffusion.html">http://www.gbkr.com/subjects/q/barrierdiffusion.ht=
ml
<=
/span>
f function there can be vectorized and improved a bit
iv><=
font class=3D"Apple-style-span" face=3D"Monaco" size=3D"3">pple-style-span" style=3D"font-size: 12px;">q)erfV:{1&(z*y)*1+sum prds =
neg[z*z]*/:x}[(%)over .5 1 1.5+\:til 42;style-span" style=3D"border-collapse: separate; ">e-span" face=3D"Monaco" size=3D"3">=3D"font-size: 12px;">2%sqrt acos -1e-span" style=3D"border-collapse: collapse; ">an" face=3D"Monaco" size=3D"3">nt-size: 12px;">]
0)%100000
se faster
div>=3D"Apple-style-span" style=3D"font-size: 12px;">
div>
M,1
can get even more speed
(xf));K r=3Dktn(KF,xn);DO(xn,kF(r)[i]=3Derf(xF[i]))R r;}
1
fMV[x]~erfM each x
ct 2009, at 20:59, aka_magnus wrote:
=
font>
=3D"Monaco" size=3D"3"> 12px;">
you've answered your question
// qerf.c
#include"=
k.h"
K qerf(K v){
float v1=3Derf((float)v->f);
&nbs=
p;return kf(v1);
}
// gcc -fPIC -shared qerf.c -o erf.so -lm
<=
br>
in q
q)erf:(`$":./erf") 2:(`qerf;1)
q)erf(1.1)
0.880205=
1
Thanks guys, much appreciated, I didn’t know if this was alreadyimplemented.JamieOn Oct 28, 9:57?am, Attila Vrabecz <attila.vrab…> wrote:> see for examplehttp://www.gbkr.com/subjects/q/barrierdiffusion.html>> the erf function there can be vectorized and improved a bit>> q)erfV:{1&(zy)1+sum prds neg[zz]/:x}[(%)over .5 1 1.5+:til ?> 42;2%sqrt acos -1]> q)x:(-200000+til 100000)%100000> q)erfV~erf each x> 1b> q)\t erf each x> 353> q)\t erfV x> 66>> but using C is of course faster>> K1(erfM){R xt!=-KF?krr(“type”):kf(erf(xf));}>> q)erfM::./erf 2:
erfM,1> q)\t erfM each x> 22> q)erfV~erfM each x> q)1b>> if you vectorize the C function you can get even more speed>> K1(erfMV){P(abs(xt)!=KF,krr(“type”))if(xt<0)R kf(erf(xf));K r=ktn> (KF,xn);DO(xn,kF(r)[i]=erf(xF[i]))R r;}>> q)erfMV::./erf 2:
erfMV,1> q)erfMV~erfM each x> 1b> q)\t erfMV x> 9>> Regards,> ? ?Attila> On 27 Oct 2009, at 20:59, aka_magnus wrote:>>>>>> > you’ve answered your question>> > // qerf.c>> > #include"k.h">> > K qerf(K v){> > ?float v1=erf((float)v->f);> > ?return kf(v1);> > }>> > // gcc -fPIC -shared qerf.c -o erf.so -lm>> > in q> > q)erf:($":./erf") 2:(
qerf;1)> > q)erf(1.1)> > 0.8802051>> > On Oct 23, 11:51 am, Jamie Dumbill <jamie.dumb…> wrote:> >> Is there an error function in kdb as there is in C (supplied by> >> math.h)?>> >>http://en.wikipedia.org/wiki/Error_function</jamie.dumb…></attila.vrab…>