Skip to content

Commit

Permalink
Output errors same length as parameters vector in powder fitting
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardWaiteSTFC committed Aug 14, 2024
1 parent 006571a commit 479e28f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions +sw_tests/+unit_tests/unittest_sw_fitpowder.m
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,9 @@ function test_calc_uncertainty(testCase)
out.fix_bg_parameters(1:2);
out.fix_scale()
out.set_bg_parameters(3, mean(out.y, 'all'));
[param_errors, ivary] = out.calc_uncertainty(out.params);
% test erros determined for only 1 parameter (const bg)
testCase.verify_val(param_errors, 0.3651, 'abs_tol', 1e-4);
testCase.verify_val(ivary, 4, 'abs_tol', 1e-4);
[param_errors, cov] = out.calc_uncertainty(out.params);
% test errors determined for only 1 parameter (const bg)
testCase.verify_val(param_errors, [0; 0; 0; 0.3651; 0], 'abs_tol', 1e-4);
end

function test_estimate_scale_factor(testCase)
Expand Down
8 changes: 4 additions & 4 deletions swfiles/sw_fitpowder.m
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,7 @@ function clear_cache(obj)
% ### Usage
%
% errors = sw_fitpowder_obj.calc_uncertainty(params)
% [errors, ipars] = sw_fitpowder_obj.calc_uncertainty(params)
% [errors, ipars, cov_mat] = sw_fitpowder_obj.calc_uncertainty(params)
% [errors, cov] = sw_fitpowder_obj.calc_uncertainty(params)
%
% ### See Also
%
Expand All @@ -518,8 +517,9 @@ function clear_cache(obj)
ndof = nbins - size(hess,1);
% calc errors
cov = inv(hess) * 2.0 * stats.cost_val/ ndof;
param_errors = sqrt(diag(cov));
varargout = {ivary, cov};
param_errors = zeros(size(params));
param_errors(ivary) = sqrt(diag(cov));
varargout = {cov};
end

function fit_background(obj, varargin)
Expand Down

0 comments on commit 479e28f

Please sign in to comment.