Skip to content

Commit

Permalink
Uses dynamic fieldnames in "unpackParams"
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPaulSharp committed Dec 3, 2024
1 parent 4f38b98 commit 71e329b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/runTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
# platform: [Windows, Linux, macOS]
platform: [Linux, macOS]
platform: [Linux]
runs-on: ${{ matrix.platform }}

steps:
Expand Down
1 change: 0 additions & 1 deletion minimisers/DREAM/runDREAM.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

% Put all the RAT parameters together into one array...
ratInputs.problemStruct = problemStruct;
%ratInputs.problemLimits = problemLimits;
ratInputs.controls = controls;
ratInputs.priors = priorList;

Expand Down
153 changes: 24 additions & 129 deletions minimisers/generalUtils/unpackParams.m
Original file line number Diff line number Diff line change
@@ -1,136 +1,31 @@
function problemStruct = unpackParams(problemStruct)

%Unpack the params out of the fitParams and otherParams arrays
%back into problem.params
% Unpack the params out of the fitParams and otherParams arrays
% back into problem.params

% Note that this order of parameters fields is hard-coded by this
% routine, packParams, packParamsPriors, and getFitNames
fields = {"params", "backgroundParams", "scalefactors", "qzshifts",...
"bulkIns", "bulkOuts", "resolutionParams", "domainRatios"};

unpacked_counter = 1;
packed_counter = 1;
uppars_counter = 1;

uppars = zeros(1,length(problemStruct.params));
for i = 1:length(problemStruct.checks.params)
if problemStruct.checks.params(i) == 1
uppars(uppars_counter) = problemStruct.fitParams(unpacked_counter);
unpacked_counter = unpacked_counter + 1;
uppars_counter = uppars_counter + 1;
else
uppars(uppars_counter) = problemStruct.otherParams(packed_counter);
packed_counter = packed_counter + 1;
uppars_counter = uppars_counter + 1;
end
end
problemStruct.params = uppars;

%Also the backgrounds
uppars = zeros(1,length(problemStruct.backgroundParams));
uppars_counter = 1;
for i = 1:length(problemStruct.checks.backgroundParams)
if problemStruct.checks.backgroundParams(i) == 1
uppars(uppars_counter) = problemStruct.fitParams(unpacked_counter);
unpacked_counter = unpacked_counter + 1;
uppars_counter = uppars_counter + 1;
else
uppars(uppars_counter) = problemStruct.otherParams(packed_counter);
packed_counter = packed_counter + 1;
uppars_counter = uppars_counter + 1;
end
end
problemStruct.backgroundParams = uppars;

%Scalefactors
uppars = zeros(1,length(problemStruct.scalefactors));
uppars_counter = 1;
for i = 1:length(problemStruct.checks.scalefactors)
if problemStruct.checks.scalefactors(i) == 1
uppars(uppars_counter) = problemStruct.fitParams(unpacked_counter);
unpacked_counter = unpacked_counter + 1;
uppars_counter = uppars_counter + 1;
else
uppars(uppars_counter) = problemStruct.otherParams(packed_counter);
packed_counter = packed_counter + 1;
uppars_counter = uppars_counter + 1;
end
end
problemStruct.scalefactors = uppars;

%qzshifts
uppars = zeros(1,length(problemStruct.qzshifts));
uppars_counter = 1;
for i = 1:length(problemStruct.checks.qzshifts)
if problemStruct.checks.qzshifts(i) == 1
uppars(uppars_counter) = problemStruct.fitParams(unpacked_counter);
unpacked_counter = unpacked_counter + 1;
uppars_counter = uppars_counter + 1;
else
uppars(uppars_counter) = problemStruct.otherParams(packed_counter);
packed_counter = packed_counter + 1;
uppars_counter = uppars_counter + 1;
end
end
problemStruct.qzshifts = uppars;

%Bulk In
uppars = zeros(1,length(problemStruct.bulkIns));
uppars_counter = 1;
for i = 1:length(problemStruct.checks.bulkIns)
if problemStruct.checks.bulkIns(i) == 1
uppars(uppars_counter) = problemStruct.fitParams(unpacked_counter);
unpacked_counter = unpacked_counter + 1;
uppars_counter = uppars_counter + 1;
else
uppars(uppars_counter) = problemStruct.otherParams(packed_counter);
packed_counter = packed_counter + 1;
uppars_counter = uppars_counter + 1;
end

for i = 1:length(fields)
uppars = zeros(1,length(problemStruct.(fields{i})));
uppars_counter = 1;
for j = 1:length(problemStruct.checks.(fields{i}))
if problemStruct.checks.(fields{i})(j) == 1
uppars(uppars_counter) = problemStruct.fitParams(unpacked_counter);
unpacked_counter = unpacked_counter + 1;
uppars_counter = uppars_counter + 1;
else
uppars(uppars_counter) = problemStruct.otherParams(packed_counter);
packed_counter = packed_counter + 1;
uppars_counter = uppars_counter + 1;
end
end
problemStruct.(fields{i}) = uppars;
end
problemStruct.bulkIns = uppars;

%Bulk Out
uppars = zeros(1,length(problemStruct.bulkOuts));
uppars_counter = 1;
for i = 1:length(problemStruct.checks.bulkOuts)
if problemStruct.checks.bulkOuts(i) == 1
uppars(uppars_counter) = problemStruct.fitParams(unpacked_counter);
unpacked_counter = unpacked_counter + 1;
uppars_counter = uppars_counter + 1;
else
uppars(uppars_counter) = problemStruct.otherParams(packed_counter);
packed_counter = packed_counter + 1;
uppars_counter = uppars_counter + 1;
end
end
problemStruct.bulkOuts = uppars;

%Resolutions
uppars = zeros(1,length(problemStruct.resolutionParams));
uppars_counter = 1;
for i = 1:length(problemStruct.checks.resolutionParams)
if problemStruct.checks.resolutionParams(i) == 1
uppars(uppars_counter) = problemStruct.fitParams(unpacked_counter);
unpacked_counter = unpacked_counter + 1;
uppars_counter = uppars_counter + 1;
else
uppars(uppars_counter) = problemStruct.otherParams(packed_counter);
packed_counter = packed_counter + 1;
uppars_counter = uppars_counter + 1;
end
end
problemStruct.resolutionParams = uppars;

%Domain Ratios
uppars = zeros(1,length(problemStruct.domainRatios));
uppars_counter = 1;
for i = 1:length(problemStruct.checks.domainRatios)
if problemStruct.checks.domainRatios(i) == 1
uppars(uppars_counter) = problemStruct.fitParams(unpacked_counter);
unpacked_counter = unpacked_counter + 1;
uppars_counter = uppars_counter + 1;
else
uppars(uppars_counter) = problemStruct.otherParams(packed_counter);
packed_counter = packed_counter + 1;
uppars_counter = uppars_counter + 1;
end
end
problemStruct.domainRatios = uppars;


end

0 comments on commit 71e329b

Please sign in to comment.