Skip to content

Commit

Permalink
Allow any non-finite value to indicate no bound
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardWaiteSTFC committed Oct 24, 2024
1 parent f8497bc commit f60fc5c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions +sw_tests/+unit_tests/unittest_ndbase_cost_function_wrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

properties (TestParameter)
bound_param_name = {'lb', 'ub'}
no_lower_bound = {[], [-inf, -inf]};
no_upper_bound = {[], [inf, inf]};
no_lower_bound = {[], [-inf, -inf], [NaN, -inf]};
no_upper_bound = {[], [inf, inf], [inf, NaN]};
errors = {ones(1,3), [], zeros(1,3), 'NoField'}
end

Expand Down
15 changes: 7 additions & 8 deletions swfiles/+ndbase/cost_function_wrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,18 @@
%
% `lb`
% : Optional vector of doubles corresponding to the lower bound of the
% parameters. Empty vector [] or vector of -inf interpreted as no lower
% bound.
% parameters. Empty vector [] or vector of non-finite elements
% (e.g. -inf and NaN) are interpreted as no lower bound.
%
% `ub`
% : Optional vector of doubles corresponding to the upper bound of the
% parameters. Empty vector [] or vector of inf interpreted as no upper
% bound.
% parameters. Empty vector [] or vector of non-finite elements
% (e.g. inf and NaN) are interpreted as no upper bound.
%
% `ifix`
% : Optional vector of ints corresponding of indices of parameters to fix
% (overides bounds if provided)
%
% ### Examples

properties (SetObservable)
% data
cost_func
Expand Down Expand Up @@ -125,8 +124,8 @@ function init_bound_parameter_transforms(obj, pars, lb, ub, ifix)
obj.ifixed = [];
ipars = 1:numel(pars); % used later
for ipar = ipars
has_lb = ~isempty(lb) && lb(ipar) > -inf;
has_ub = ~isempty(ub) && ub(ipar) < inf;
has_lb = ~isempty(lb) && isfinite(lb(ipar));
has_ub = ~isempty(ub) && isfinite(ub(ipar));
is_fixed = any(uint8(ifix) == ipar);
if has_lb && has_ub
% both bounds specified and parameter not fixed
Expand Down

0 comments on commit f60fc5c

Please sign in to comment.