Skip to content

Commit

Permalink
Renames target functions and minimisers (#176)
Browse files Browse the repository at this point in the history
* Renames "standardTF" to "nonPolarisedTF"

* Tidies up Paramonte functions

* Tidies up code in minimisers

* Renames "NSMain" as "NS"

* Updates paths

* Addresses review comments
  • Loading branch information
DrPaulSharp authored Nov 27, 2023
1 parent 756e64a commit 6f82749
Show file tree
Hide file tree
Showing 78 changed files with 158 additions and 192 deletions.
21 changes: 6 additions & 15 deletions 3rdParty/paramonte/pmLogFunction.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@

function logFuncVal = get(obj,pars)

problem = obj.problemDef;
control = obj.controls;
cells = obj.problemDefCells;
limits = obj.problemDefLimits;
priors = obj.priors;

problem = obj.problemDef;
problem.fitpars = pars;

if obj.scaled
if obj.scaled
problem = unscalePars(problem);
end

problem = unpackparams(problem,control);
problem = unpackparams(problem,obj.controls);

[outProblem,results] = reflectivityCalculation_mex(problem,cells,limits,control);
[outProblem,~] = reflectivityCalculation_mex(problem,obj.problemDefCells,obj.controls);
chi = outProblem.calculations.sum_chi;
logFuncVal = -chi/2;

Expand All @@ -42,14 +37,10 @@
% Now apply the priors where necessary.
priorfun = @(th,mu,sig) sum(((th-mu)./sig).^2);

val = priorfun(problem.fitpars,priors(:,1),priors(:,2));

logFuncVal = logFuncVal + val;
val = priorfun(problem.fitpars,obj.priors(:,1),obj.priors(:,2));

%end

logFuncVal = logFuncVal + val;

end
end
end

27 changes: 11 additions & 16 deletions 3rdParty/paramonte/pmPars.m
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
classdef pmPars < handle


properties

covMat = []
delayedRejectionCount = []
name = ''
scalefactor = 1e-3
chainSize = 10000
chainTrim = 0.25 % Use only the last part of chain...
mpi = false;

end




properties

covMat = []
delayedRejectionCount = []
name = ''
scalefactor = 1e-3
chainSize = 10000
chainTrim = 0.25 % Use only the last part of chain...
mpi = false;

end

end
8 changes: 2 additions & 6 deletions 3rdParty/paramonte/processParamonteRuns.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@

function [outProblemDef,result,pmpd] = processFits(problem,controls,chainName,chainTrim)
function [outProblemDef,result,pmpd] = processParamonteRuns(problem,controls,chainName,chainTrim)

% problem = load(name);
% problem = problem.twentyMNProblem;
%
% controls = controlsClass();

[problemDef,problemDefCells,problemDefLimits,priors,controls] = parseClassToStructs(problem,controls);
problemDefInput = problemDef;
[problemDef,problemDefCells,problemDefLimits,~,controls] = parseClassToStructs(problem,controls);

[problemDef,fitNames] = packparams(problemDef,problemDefCells,problemDefLimits,controls.checks);
nDims = length(problemDef.fitpars);

pm = paramonte();
pmpd = pm.ParaDRAM();
Expand Down Expand Up @@ -50,7 +47,6 @@
[problemDef,outProblemStruct,result,bayesResults] = processBayes(bayesOutputs,allProblem);
bayesResults.chain = unscaledChain;


result = parseResultToStruct(outProblemStruct,result);

if isfield(problemDef,'fitpars')
Expand Down
2 changes: 1 addition & 1 deletion 3rdParty/paramonte/runParamonte.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
logFunc.NDIM = nDims;
logFunc.scaled = true;

% Create a paraMonte object
% Create a paramonte object
pm = paramonte();

% create a ParaDRAM simulation object
Expand Down
5 changes: 3 additions & 2 deletions 3rdParty/paramonte/scalePars.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
function problem = scalePars(problem)


limits = problem.fitconstr;
vals = problem.fitpars;

scaled = (vals(:) - limits(:,1))./(limits(:,2)-limits(:,1));

problem.fitpars = scaled;
%problem.unscaledPars = vals;
%problem.unscaledPars = vals;

end
4 changes: 3 additions & 1 deletion 3rdParty/paramonte/unscalePars.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

unscaled = (scaled.*(limits(:,2)-limits(:,1)))+limits(:,1);

problem.fitpars = unscaled;
problem.fitpars = unscaled;

end
4 changes: 2 additions & 2 deletions addPaths.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
fullfile(root,'minimisers','DE');
%fullfile(root,'minimisers','mcmcstat_new');
%fullfile(root,'minimisers','mcmcstat_new','src');
fullfile(root,'minimisers','NSMain');
fullfile(root,'minimisers','NS');

fullfile(root,'targetFunctions' );
fullfile(root,'targetFunctions','common');
Expand All @@ -50,7 +50,7 @@
fullfile(root,'targetFunctions','common','resampleLayers');
fullfile(root,'targetFunctions','common','resolutionFunctions','simpleGaussian');

fullfile(root,'tests','standardTFReflectivityCalculation');
fullfile(root,'tests','nonPolarisedTFReflectivityCalculation');
fullfile(root,'tests','domainsTFReflectivityCalculation');
fullfile(root,'tests','testCommonFunctions');
fullfile(root,'tests','testProjectConversion');
Expand Down
2 changes: 1 addition & 1 deletion compile/reflectivityCalculation/setCompilePaths.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function setCompilePaths(which)
function setCompilePaths()

% This function sets the paths for compiling, depending on whether a mex
% file of source code is being generated.
Expand Down
2 changes: 1 addition & 1 deletion minimisers/DREAM/diagnostics/raftery.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
q = 0.0;
i1 = find(runs == 0); i2 = find(runs == 1);
ct1 = size(i1); ct2 = size(i2);
if (ct1+ct2 ~= n), error('raftery needs 0s and 1s in runs'); end;
if (ct1+ct2 ~= n), error('raftery needs 0s and 1s in runs'); end
work = runs;
q = sum(runs);
q = q/n;
Expand Down
2 changes: 1 addition & 1 deletion minimisers/DREAM/functions/DREAM.m
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@


% Store the model simulations (if appropriate)
storeDREAMResults ( DREAMPar , fx , Meas_info , 'a+' );
storeDREAMResults(DREAMPar,fx,Meas_info,'a+');
end

% Check whether we update the crossover values
Expand Down
2 changes: 1 addition & 1 deletion minimisers/DREAM/functions/gelman.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
% Step 2: Compute the variance of the various chain
for zz = 1:DREAMPar.N
var_chain(zz,:) = var(chain(:,:,zz));
end;
end

% Step 2: Calculate the average of the within _chainuence variances
W = mean(var_chain);
Expand Down
2 changes: 1 addition & 1 deletion minimisers/DREAM/functions/initializeDREAM.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
X = [x log_PR_x(:) log_L_x];

% Store the model simulations (if appropriate)
% storeDREAMResults ( DREAMPar , fx , Meas_info , 'w+' );
% storeDREAMResults(DREAMPar,fx,Meas_info,'w+');

% Set the first point of each of the DREAMPar.N chain equal to the initial X values
chain(1,1:DREAMPar.d+2,1:DREAMPar.N) = reshape(X',1,DREAMPar.d+2,DREAMPar.N);
Expand Down
4 changes: 2 additions & 2 deletions minimisers/DREAM/functions/initializeDREAMForRAT.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
otherwise

error('unknown initial sampling method');
end;
end

% If specified do boundary handling ( "Bound","Reflect","Fold")
if isfield(Par_info,'boundhandling')
Expand All @@ -54,7 +54,7 @@
X = [x log_PR_x log_L_x];

% Store the model simulations (if appropriate)
storeDREAMResults ( DREAMPar , fx , Meas_info , 'w+' );
storeDREAMResults(DREAMPar,fx,Meas_info,'w+');

% Set the first point of each of the DREAMPar.N chain equal to the initial X values
chain(1,1:DREAMPar.d+2,1:DREAMPar.N) = reshape(X',1,DREAMPar.d+2,DREAMPar.N);
Expand Down
2 changes: 0 additions & 2 deletions minimisers/DREAM/functions/multrnd.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,11 @@
m = 1;
else
error('You need to input at least two arguments.');
return,
end
end

if (length(n)~=1) | (fix(n) ~= n) | (n < 0)
error('n must be a positive integer.');
return,
end

P = sum(p);
Expand Down
2 changes: 1 addition & 1 deletion minimisers/DREAM/functions/ratDREAM.m
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
% store the distance between the simualted and observed signatures

% Store the model simulations (if appropriate)
% storeDREAMResults ( DREAMPar , fx , Meas_info , 'a+' );
% storeDREAMResults(DREAMPar,fx,Meas_info,'a+');
end

% Check whether we update the crossover values
Expand Down
4 changes: 2 additions & 2 deletions minimisers/DREAM/functions/storeDREAMResults.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function storeDREAMResults ( DREAMPar , fx , Meas_info , id )
function storeDREAMResults(DREAMPar,fx,Meas_info,id)
% Stores the results of DREAM to binary files

% Append current model simulations of X to file "fx.bin"
Expand All @@ -9,4 +9,4 @@ function storeDREAMResults ( DREAMPar , fx , Meas_info , id )
fwrite(fid_fx,fx,'double');
% Now close file
fclose(fid_fx);
end;
end
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

% check condition number of C (eps = 2.2204e-16)
if rcond(C)<eps || isnan(rcond(C))
if DEBUG; fprintf('bad condition number!\n'); end;
if DEBUG; fprintf('bad condition number!\n'); end
flag = 1;
return;
end
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion minimisers/NSMain/drawMCMC.m → minimisers/NS/drawMCMC.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [sample, logL] = drawMcmc(livepoints, cholmat, logLmin, ...
function [sample, logL] = drawMCMC(livepoints, cholmat, logLmin, ...
prior, data, likelihood, model, Nmcmc, parnames, extraparvals)
% This function will draw a multi-dimensional sample from the prior volume
% for use in the nested sampling algorithm. The new point will have a
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions minimisers/NSMain/mchol.m → minimisers/NS/mchol.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,34 @@
E=zeros(n);
theta = zeros(n);

for j=1:n,
for j=1:n
bb=[1:j-1];
ee=[j+1:n];

%
% Calculate the jth row of L.
%
if (j > 1),
if (j > 1)
L(j,bb)=C(j,bb)./diag(D(bb,bb))';
end;
end
%
% Update the jth column of C.
%
if (j >= 2),
if (j < n),
if (j >= 2)
if (j < n)
C(ee,j)=G(ee,j)-(L(j,bb)*C(ee,bb)')';
end;
end
else
C(ee,j)=G(ee,j);
end;
end
%
% Update theta.
%
if (j == n)
theta(j)=0;
else
theta(j)=max(abs(C(ee,j)));
end;
end
%
% Update D
%
Expand All @@ -119,7 +119,7 @@
C(ind)=C(ind)-(1/D(j,j))*C(ee,j).^2;


end;
end

%
% Put 1's on the diagonal of L
Expand All @@ -143,7 +143,7 @@
pneg=L'\rhs;
else
pneg=[];
end;
end


return
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

problemDef = data{1};
controls = data{2};
problemDefLimits = data{3};
problemDefCells = data{4};

% Removed use of cells....
problemDef.fitpars = p;

problemDef = unpackparams(problemDef,controls);
[problemDef,result] = reflectivityCalculation(problemDef,problemDefCells,controls);
[problemDef,~] = reflectivityCalculation(problemDef,problemDefCells,controls);

fval = (-problemDef.calculations.sum_chi/2);
end
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function results = parseBayesResults(chain,problemDef,problemDefCells,problemDefLimits,controls)
function results = parseBayesResults(chain,problemDef,problemDefCells,controls)
debug = 1;

numPars = size(chain,2)-1;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

% check flags
if flag1 || flag2
if DEBUG; fprintf('CANT SPLIT!!\n'); end;
if DEBUG; fprintf('CANT SPLIT!!\n'); end
nosplit = 1;
break
end
Expand Down Expand Up @@ -137,14 +137,14 @@

end

u1 = []; u2 = []; mu1 = []; mu2 = [];;
u1 = []; u2 = []; mu1 = []; mu2 = [];
n1 = m1;
n2 = m2;

u1 = u1new(1:n1,:);
u2 = u2new(1:n2,:);

u1new = []; u2new = [];;
u1new = []; u2new = [];

% update counter
counter = counter + 1;
Expand Down Expand Up @@ -172,6 +172,6 @@
VE1 = temp_VE1(idx);
VE2 = temp_VE2(idx);

if DEBUG; fprintf('SPLIT ELLIPSOID: min F(S) = %f\n', minFS); end;
if DEBUG; fprintf('SPLIT ELLIPSOID: min F(S) = %f\n', minFS); end

end
Loading

0 comments on commit 6f82749

Please sign in to comment.