-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better documentation of the type of user information and additional M…
…atlab example (fixes #67)
- Loading branch information
1 parent
79bb94a
commit 01c78a2
Showing
5 changed files
with
49 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
function linear_regression() | ||
% Example of the Matlab binding of the Gpufit library implementing | ||
% Levenberg Marquardt curve fitting in CUDA | ||
% https://github.com/gpufit/Gpufit | ||
% | ||
% 1D linear regression with custom x values given as user information | ||
% http://gpufit.readthedocs.io/en/latest/bindings.html#matlab | ||
|
||
% x values for the 1D linear regression model must be single | ||
x = single(0:10); | ||
parameters = single([0;1]); | ||
y = single(parameters(1)+parameters(2)*x'); | ||
|
||
% fit parameter | ||
tolerance = 1e-9; | ||
max_n_iterations = 1000; | ||
estimator_id = EstimatorID.LSE; | ||
model_id = ModelID.LINEAR_1D; | ||
initial_parameters = single([0;1]); % should result in correct parameters with only 1 iteration | ||
|
||
% with user info | ||
[parameters, states, chi_squares, n_iterations, time] = gpufit(y, [], ... | ||
model_id, initial_parameters, tolerance, max_n_iterations, [], estimator_id, x); | ||
fprintf('first fit with user info: fitted parameters = [%.2f, %.2f]\n', parameters); | ||
|
||
% without user info | ||
[parameters, states, chi_squares, n_iterations, time] = gpufit(y, [], ... | ||
model_id, initial_parameters, tolerance, max_n_iterations, [], estimator_id); | ||
fprintf('first fit without user info: fitted parameters = [%.2f, %.2f]\n', parameters); | ||
|
||
% now more meaningful | ||
x = single([1,3,4,5,5.5]); | ||
y = single(parameters(1)+parameters(2)*x'); | ||
[parameters, states, chi_squares, n_iterations, time] = gpufit(y, [], ... | ||
model_id, initial_parameters, tolerance, max_n_iterations, [], estimator_id, x); | ||
fprintf('second fit with user info: fitted parameters = [%.2f, %.2f]\n', parameters); | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters