forked from tsdev/spinw
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add new lm minimiser #208
Merged
Merged
Add new lm minimiser #208
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
959c38f
Optional inital cost_val and return jacobuan in estimate_hessian
RichardWaiteSTFC 65d0cfc
Add function to evaluate weighted residuals in cost func wrapper
RichardWaiteSTFC 2474a3a
Add LM minimiser (currently only supports scalar functions)
RichardWaiteSTFC d8b14e9
Support least_squares residuals in lm4
RichardWaiteSTFC 7bf3529
Improve inversion for ill-conditioned matrices
RichardWaiteSTFC b94c4c7
Add missing factors of 2
RichardWaiteSTFC d1e8605
Fix bug in finite difference not resetting parameter vector
RichardWaiteSTFC e284a58
Fix bug with diff step length if parameters fixed
RichardWaiteSTFC 40c9095
Fix bug where absolute and fracatinal step confused if 1 parameter
RichardWaiteSTFC b00c3d3
Add lm4 to optimiser to unit test
RichardWaiteSTFC dd978e2
Merge branch 'master' into add_new_LM_minimiser
RichardWaiteSTFC 44a6290
Add support for function handles returning residal arrays
RichardWaiteSTFC 3dc3f2f
Support resid_handle option in sw_fitpowder
RichardWaiteSTFC 520e53c
Support resid_handle in bg fitting of pwader class
RichardWaiteSTFC e579fe2
Correct doc-strings for simplex and lm4
RichardWaiteSTFC 5c3f460
Change nu_dn default to 5 after benchmarking with NIST datasets
RichardWaiteSTFC 8cb0a1a
Use lsqnonlin method to reset invalid parameters within bounds
RichardWaiteSTFC 5b72585
Add vary arg to simplex and lm4 (and tests)
RichardWaiteSTFC 1fc202a
Fix typos in doc string
RichardWaiteSTFC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
end | ||
|
||
properties (TestParameter) | ||
optimiser = {@ndbase.simplex}; | ||
optimiser = {@ndbase.simplex, @ndbase.lm4}; | ||
poly_func = {@(x, p) polyval(p, x), '@(x, p) polyval(p, x)'} | ||
end | ||
|
||
|
@@ -18,14 +18,23 @@ function test_optimise_data_struct(testCase, optimiser, poly_func) | |
dat = struct('x', 1:3, 'e', ones(1,3)); | ||
dat.y = polyval(linear_pars, dat.x); | ||
[pars_fit, cost_val, ~] = optimiser(dat, poly_func, [-1,-1]); | ||
testCase.verify_val(pars_fit, linear_pars, 'abs_tol', 1e-3); | ||
testCase.verify_val(cost_val, 2.5e-7, 'abs_tol', 1e-8); | ||
testCase.verify_val(pars_fit, linear_pars, 'abs_tol', 2e-4); | ||
testCase.verify_val(cost_val, 0, 'abs_tol', 5e-7); | ||
end | ||
|
||
function test_optimise_residual_array_lm(testCase, optimiser) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test should also run for |
||
linear_pars = [2, 1]; | ||
x = 1:3; | ||
y = polyval(linear_pars, x); | ||
[pars_fit, cost_val, ~] = optimiser([], @(p) y - polyval(p, x), [-1,-1], 'resid_handle', true); | ||
testCase.verify_val(pars_fit, linear_pars, 'abs_tol', 2e-4); | ||
testCase.verify_val(cost_val, 0, 'abs_tol', 5e-7); | ||
end | ||
|
||
function test_optimise_rosen_free(testCase, optimiser) | ||
[pars_fit, cost_val, ~] = optimiser([], testCase.rosenbrock, [-1,-1]); | ||
testCase.verify_val(pars_fit, testCase.rosenbrock_minimum, 'abs_tol', 1e-3); | ||
testCase.verify_val(cost_val, 0, 'abs_tol', 1e-6); | ||
testCase.verify_val(cost_val, 0, 'abs_tol', 2e-7); | ||
end | ||
|
||
function test_optimise_rosen_lower_bound_minimum_accessible(testCase, optimiser) | ||
|
@@ -48,10 +57,9 @@ function test_optimise_rosen_upper_bound_minimum_accessible(testCase, optimiser) | |
end | ||
|
||
function test_optimise_rosen_upper_bound_minimum_not_accessible(testCase, optimiser) | ||
% note intital guess is outside bounds | ||
[pars_fit, cost_val, ~] = optimiser([], testCase.rosenbrock, [-1,-1], 'ub', [0, inf]); | ||
testCase.verify_val(pars_fit, [0, 0], 'abs_tol', 1e-3); | ||
testCase.verify_val(cost_val, 1, 'abs_tol', 1e-6); | ||
testCase.verify_val(cost_val, 1, 'abs_tol', 1e-4); | ||
end | ||
|
||
function test_optimise_rosen_both_bounds_minimum_accessible(testCase, optimiser) | ||
|
@@ -62,7 +70,7 @@ function test_optimise_rosen_both_bounds_minimum_accessible(testCase, optimiser) | |
|
||
function test_optimise_rosen_both_bounds_minimum_not_accessible(testCase, optimiser) | ||
% note intital guess is outside bounds | ||
[pars_fit, cost_val, ~] = optimiser([], testCase.rosenbrock, [-1,-1], 'lb', [-0.5, -0.5], 'ub', [0, 0]); | ||
[pars_fit, cost_val, ~] = optimiser([], testCase.rosenbrock, [-1,-1], 'lb', [-2, -2], 'ub', [0, 0]); | ||
testCase.verify_val(pars_fit, [0, 0], 'abs_tol', 1e-3); | ||
testCase.verify_val(cost_val, 1, 'abs_tol', 1e-6); | ||
end | ||
|
@@ -74,13 +82,26 @@ function test_optimise_rosen_parameter_fixed_minimum_not_accessible(testCase, op | |
testCase.verify_val(cost_val, 1, 'abs_tol', 1e-6); | ||
end | ||
|
||
function test_optimise_rosen_parameter_fixed_minimum_not_accessible_with_vary_arg(testCase, optimiser) | ||
% note intital guess is outside bounds | ||
[pars_fit, cost_val, ~] = optimiser([], testCase.rosenbrock, [0,-1], 'lb', [nan, -0.5], 'ub', [nan, 0], 'vary', [false, true]); | ||
testCase.verify_val(pars_fit, [0, 0], 'abs_tol', 1e-3); | ||
testCase.verify_val(cost_val, 1, 'abs_tol', 1e-6); | ||
end | ||
|
||
function test_optimise_rosen_parameter_all_fixed(testCase, optimiser) | ||
% note intital guess is outside bounds | ||
[pars_fit, cost_val, ~] = optimiser([], testCase.rosenbrock, [-1,-1], 'lb', [0, 0], 'ub', [0, 0]); | ||
testCase.verify_val(pars_fit, [0, 0], 'abs_tol', 1e-3); | ||
testCase.verify_val(cost_val, 1, 'abs_tol', 1e-6); | ||
end | ||
|
||
function test_optimise_rosen_parameter_all_fixed_with_vary_arg(testCase, optimiser) | ||
% note intital guess is outside bounds | ||
[pars_fit, cost_val, ~] = optimiser([], testCase.rosenbrock, [0, 0], 'vary', [false, false]); | ||
testCase.verify_val(pars_fit, [0, 0], 'abs_tol', 1e-3); | ||
testCase.verify_val(cost_val, 1, 'abs_tol', 1e-6); | ||
end | ||
|
||
end | ||
end | ||
% do parameterised test with all minimisers | ||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is wrong? It doesn't look like you've set any bounds here, just fixed the parameter values?
Looks like this was copied from
test_init_with_fcost_no_bounds_with_fixed_param_using_ifix
which also has the same (erroneous?) comment in line 96.