Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User_Info Not Working Correctly in Matlab #67

Open
emrdig opened this issue Jul 26, 2018 · 4 comments
Open

User_Info Not Working Correctly in Matlab #67

emrdig opened this issue Jul 26, 2018 · 4 comments
Assignees

Comments

@emrdig
Copy link

emrdig commented Jul 26, 2018

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
@adrianjp88
Copy link
Collaborator

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).

@emrdig
Copy link
Author

emrdig commented Jul 27, 2018

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.

@jkfindeisen
Copy link
Collaborator

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.

@odewit8
Copy link

odewit8 commented Feb 25, 2022

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.

@superchromix superchromix reopened this Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants