How to use polyfit instead of fit for fitting an exponential. For GPU processing.

Ok, I've been fighting this for way too long, and I've posed a similar question to this months ago, but I still do not get the values I so desparately need.
How do I use polyfit to get the 'b' value in the output from fit(X,Y,'exp1')?
I've taken the natural log of every combination of value, used polyval in various ways, and still get nothing within 5 orders of magnitude to what I need. I've read many different answers to this same question in the community, so if you post a link to one, I've probably seen it.
This would be moot if I could use fit with a GPU.

6 comentarios

This would be moot if I could use fit with a GPU.
If you have a large batch of fits to do (otherwise, I don't see why GPU power would be necessary), you should probably use lsqcurvefit. This would allow you to do all the fits simultaneously and also use the GPU for the objective function evaluations.
Also, you could use your original noise model, instead of distorting it with log operations.
I'm glad it helped you, but I'm not really sure how. It doesn't look like you've used lsqcurvefit so far to do anything differently from what you were doing with fit().
SS = squeeze(squeeze(SSS(i,j,:)));
F0 = fit(TE, SS, 'exp1','StartPoint',[0 0]);
FIT_b(i,j,slice) = cell2mat({F0.b});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% LSQCURVEFIT SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%
fun = @(x,TE)x(1)*exp(x(2)*TE);
x0 = [0 0];
x = lsqcurvefit(fun,x0,TE,SS);
LSQFIT_b(i,j,slice) = x(2);
NM I got way too excited and thought lsqcurvefit could use CUDA. I give up....
You can use gpuArray operations inside the objective function. In doing so, you can potentially gain speed advantages from your GPU.
It is probably a good idea for you to describe the structure of TE and SSS so we can better delve into how you would optimize the computation time. Are you looping over i,j and computing a separate pair [x1,x2] for each one? What are the dimensions of TE and SSS?
If i and j are both scalars, then you only need one squeeze() there instead of 2. You could also use
SS = reshape(SSS(i,j,:), [], 1);

Iniciar sesión para comentar.

Respuestas (1)

Matt J
Matt J el 13 de Mzo. de 2019
Editada: Matt J el 13 de Mzo. de 2019
For example,
a=1;
b=2;
x=gpuArray.linspace(0,2,100);
y=a*exp(b*x);
p=polyfit(x,log(y),1);
b_fit=p(1),
produces the desired value,
b_fit =
2

6 comentarios

Kris Hoffman
Kris Hoffman el 13 de Mzo. de 2019
Editada: Kris Hoffman el 13 de Mzo. de 2019
What would determine a = 1 and b = 2? Is this always the case?
Also, I need to use the 'SS' variable as my 'y', however, it also contains negative values which gives me complex numbers. (and I can't take abs value before taking natural log)
Is there some statistical component I'm missing?
Any time you see major coefficients such as a crossing 0 in the confidence bounds for a fit, then you should understand the implication as being that the fit is undecideable to within the precision you are using -- at least given that starting point. There might not be a single solution, or the "basin of attraction" of the best solution might be relatively narrow.
Note that using [0 0] as a starting point is prone to failing in fitting: it is easy for the search to get stuck not being able to find a gradient because of the odd behavior that equations can have at 0 exactly. Sometimes it helps to give a slight non-zero value as the starting point.
The only time you can have an exponential fit to negative y values is if the y values are all negative (leading to a negative a coefficient).
If you have some y readings that are negative because of noise in the system, consider excluding them from the fit.
+1 of course. But note that you need not get exactly rthe same result as you would from fit. In the presence of noise, the result from fit will essentially be weighted differently, so the coefficients might differ somewhat.
that startpoint is not absolutely necessary. I've tried it without as well and I get within 2% of the same fit.
I am much more concerned about this workaround to DRASTICALLY reduce processing time. Right now it takes 1.5hrs to process each data set on a quad core 3.1 GHz i7. If I run this through a supercomputer utilizing 48 xeon cores it takes 15 minutes. Now, theoretically, if I could pump this data through thousands of CUDA cores, it should be much faster than 15 minutes.
I NEED the b value from the exponential fit output OR if fit could be made to work with CUDA.
I have yet to find any solution that produces even the same sign (+/-) between the two methods.
polyfit runs on GPU.
If you are requiring 1.5 hours to do the fit() or polyfit then I would worry you would exceed the memory capacity of your GPU.

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.

Productos

Versión

R2018b

Preguntada:

el 13 de Mzo. de 2019

Comentada:

el 13 de Mzo. de 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by