![]() ![]() The Profile package in Julia lists which code runs the most, but not how long it takes. This makes it easy to find where to spend time optimizing. In MATLAB the profiler ranks code by the total length of time it takes to execute. It is possible the the Optim package has a better solver and I can try to use that, but to start, I was trying to write comparable code. Here is the two curve fitting functions:įit = leastsq(residuals, p0, args=(y, x), maxfev=2000)īoth functions claim to use Levenberg-Marquardt. The problem is either in the interpolation functions, the model or the curve fitting function. What is strange is that the Python code runs in about 40 msec and the equivalent Julia code runs in 500 msec. Since the fits can be shifted left or right, I get errors without extrapolation. The data has both magnitude and time variance since it is real data. The actual data I’m using is much higher resolution than the example I posted. Pval(x,p) = p*fitA(x.+p).+p*fitB(x.+p) Įach fit function models experimentally obtained dye responses (fluorescence lifetimes). That said, I sort of need the extrapolation since the model for the curve fitting looks like this: I gather the (x,) transposes the x vector for use with 1D fitting. ![]() Was helpful and I didn’t find it in the docs. Itp2 = interpolate((x,), y, Gridded(Linear())) For example your explanation with the code: The default method used by interp1 is linear, which works best with your condition because you do not want the 'nearest' neighbor but the first lower or equal neighbor (as far as I understand. I found the documentation for Interpolations too terse. of -inf 0 10 15 190 inf 1 0 0 1 1 0' t2 0 5 14 16 indexfloor (interp1 (of (:,1), (1:size (of,1))',t2')) outputof (index,:) Hope it helps. Julia appeals to me as I have a lot of experience in MATLAB which I no longer use (too expensive now that I don’t have a company buying it). ![]() Just for my own interest, I decided to recreate this code in Julia. This is why I don’t share my code unmodified. Just to provide some context, I’m using Python to do some consulting work for a client. Thank you so much for the timely responses. The performance shootout picture for Interpolations here claims it’s better at this too. Julia> fit2 = LinearInterpolation(x2, y,extrapolation_bc=Flat()) To be fair Interpolations is cheating a bit here because Dierckx isn’t using the fact that the grid is uniformly spaced. So it looks like Interpolations is a bit faster than Dierckx for me. I get using Interpolations, Dierckx, BenchmarkToolsįit1 = Spline1D(x,y,w=ones(length(x)), k=1, bc="nearest", s=0.0) įit2 = LinearInterpolation(x, y,extrapolation_bc=Flat()) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |