Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8193

this computation is just too slow (vrs. 8.0.4)

From Chris <kristophs.post@web.de>
Newsgroups comp.soft-sys.math.mathematica
Subject this computation is just too slow (vrs. 8.0.4)
Date 2012-01-26 08:37 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jfr3bh$nna$1@smc.vnet.net> (permalink)

Show all headers | View raw


Hi

I'm not really a good programmer (see below) and do appreciate any
help. What I'm basically trying to do is to find the root of two
equations with two unknowns. Each of the two expressions is the sum of
functions, which I call "huberF" and "epanKern". However, I do this
"n" times via a For loop.

Here is the problem in more detail:

(*some random data*)
n=300;
xData=RandomReal[{-1,1},n];
yData=RandomReal[{-1,1},n];

(*functions I need*)
huberF[x_Real]:=Max[-1.,Min[x,1.]];

epanKern=Compile[{{u,_Real},{bw,_Real}},
If[Abs[u/bw]<1.,.75 (1.-(u/bw)^2),0.]
,RuntimeAttributes->{Listable}
,"RuntimeOptions"->"Speed"];

(*a simple parameter*)
bw=StandardDeviation[xData] leg^(-1/5);

(*finding the root*)
list=Reap[With[{epanKern=epanKern},
For[j=1,j<=leg,j++,
val1=Sum[huberF[yData[[i]]-b0-b1(xData[[i]]-xData[[j]])]
epanKern[xData[[i]]-xData[[j]],bw],{i,1,n}];
val2=Sum[huberF[yData[[i]]-b0-b1(xData[[i]]-xData[[j]])] (xData[[i]]-
xData[[j]])epanKern[xData[[i]]-xData[[j]],bw],{i,1,n}];
val= FindRoot[{val1,val2},{{b0,.01},{b1,.01}}][[1,2]];
Sow[val]
]
]
];//AbsoluteTiming
list=list[[2,1]]


I tried computing "list" using matrices. The idea was to construct two
matrices, such that multiplying the relevant rows with the relevant
columns gave two vectors with element "i" according to "val1" and
val2".

It indeed was very quick! However, when I tried finding the root, in a
similar loop as above, calling for each "i" the relevant terms from
the vectors above it was only half as fast as the above loop. Which
astonished me.

Thanks in advance. I do appreciate any help.
Cheers,
Chris

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

this computation is just too slow (vrs. 8.0.4) Chris <kristophs.post@web.de> - 2012-01-26 08:37 +0000

csiph-web