From 71e329becc495d389526b115d28120837390678e Mon Sep 17 00:00:00 2001 From: Paul Sharp <44529197+DrPaulSharp@users.noreply.github.com> Date: Tue, 3 Dec 2024 17:30:09 +0000 Subject: [PATCH] Uses dynamic fieldnames in "unpackParams" --- .github/workflows/runTests.yml | 2 +- minimisers/DREAM/runDREAM.m | 1 - minimisers/generalUtils/unpackParams.m | 153 ++++--------------------- 3 files changed, 25 insertions(+), 131 deletions(-) diff --git a/.github/workflows/runTests.yml b/.github/workflows/runTests.yml index 5cbdfc71..c86ccb78 100644 --- a/.github/workflows/runTests.yml +++ b/.github/workflows/runTests.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: # platform: [Windows, Linux, macOS] - platform: [Linux, macOS] + platform: [Linux] runs-on: ${{ matrix.platform }} steps: diff --git a/minimisers/DREAM/runDREAM.m b/minimisers/DREAM/runDREAM.m index ca639f7f..a1e35296 100644 --- a/minimisers/DREAM/runDREAM.m +++ b/minimisers/DREAM/runDREAM.m @@ -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; diff --git a/minimisers/generalUtils/unpackParams.m b/minimisers/generalUtils/unpackParams.m index 7c9d705f..79f1108a 100644 --- a/minimisers/generalUtils/unpackParams.m +++ b/minimisers/generalUtils/unpackParams.m @@ -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