this computation is just too slow (vrs. 8.0.4)
- To: mathgroup at smc.vnet.net
- Subject: [mg124616] this computation is just too slow (vrs. 8.0.4)
- From: Chris <kristophs.post at web.de>
- Date: Thu, 26 Jan 2012 03:32:01 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
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