Gpufit icon indicating copy to clipboard operation
Gpufit copied to clipboard

User_Info Not Working Correctly in Matlab

Open emrdig opened this issue 7 years ago • 4 comments

It seems that there is a bug with the call to gpufit within Matlab when including the user_info parameter. Using the included linear_1d model (which utilizes the user_info parameter), I created a simple program in Matlab to model the equation y=x from x=0 to x=10 and called gpufit on the data. This should return the parameters 0 and 1, but results in 4.3467 and 0.8711 instead.

Additionally, if I leave the user_info parameter empty when calling gpufit, it returns the correct values (since it uses x=point_index which would result in x from 0 to 10). This shows that there is a bug with the user_info parameter when calling gpufit from Matlab. A simple script showing this problem is included below.

x=0:10;
params=single([0;1]);
y=single(params(1)+params(2)*x');   % y=x;

tolerance=1e-9;
max_n_iterations=1000;
estimator_id = EstimatorID.LSE;
model_id = ModelID.LINEAR_1D;
init = single([0;1]);   % should result in correct parameters with only 1 iteration

[parameters,states,chi_squares,n_iterations,time]=gpufit(y,[],model_id,init,tolerance,max_n_iterations,[],estimator_id,x);
%[parameters,states,chi_squares,n_iterations,time]=gpufit(y,[],model_id,init,tolerance,max_n_iterations,[],estimator_id,[]);
parameters

emrdig avatar Jul 26 '18 20:07 emrdig

The 1D linear model requires the user_info parameter to be of type single. Since the default type in Matlab is double, the expression x = 0:10 in your example defines x as double. Try x = single(0:10).

adrianjp88 avatar Jul 27 '18 08:07 adrianjp88

Figured it out eventually. It should say this in the Matlab documentation instead of saying "arbitrary type" since the other inputs explicitly say they need to be singles.

emrdig avatar Jul 27 '18 15:07 emrdig

I improved the documentation in the last commit and took your code to create a new example in Matlab for the linear regression with custom x values.

jkfindeisen avatar Jun 08 '21 15:06 jkfindeisen

I had the same issue with the python binding. It worked when I set user_info to numpy.float32. Should change that part of the documentation as well.

odewit8 avatar Feb 25 '22 11:02 odewit8