Skip to content

Commit

Permalink
Fix error where error metric is not computed for unconditional selection
Browse files Browse the repository at this point in the history
  • Loading branch information
bakerjw committed Aug 23, 2016
1 parent ac7ad45 commit 651676f
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions compute_spectrum_error.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@
% spectrum



% Calculate the deviation from the target
if selectionParams.optType == 0
if selectionParams.cond == 1 || (selectionParams.cond == 0 && selectionParams.isScaled == 0)
% Compute deviations from target
sampleMean = sum(sampleSmall)/size(sampleSmall,1);
sampleVar = sum((sampleSmall - ones(size(sampleSmall,1),1)*sampleMean).^2) / size(sampleSmall,1);
devMean = sampleMean - targetSa.meanReq;
devSig = sqrt(sampleVar) - targetSa.stdevs;
devTotal = selectionParams.weights(1) * sum(devMean.^2) + selectionParams.weights(2) * sum(devSig.^2);
end
if selectionParams.optType == 0 % computed weighted sum of squared errors of mean and standard deviation
% Compute deviations from target
sampleMean = sum(sampleSmall)/size(sampleSmall,1);
sampleVar = sum((sampleSmall - ones(size(sampleSmall,1),1)*sampleMean).^2) / size(sampleSmall,1);
devMean = sampleMean - targetSa.meanReq;
devSig = sqrt(sampleVar) - targetSa.stdevs;
devTotal = selectionParams.weights(1) * sum(devMean.^2) + selectionParams.weights(2) * sum(devSig.^2);

% Penalize bad spectra (set penalty to zero if this is not required)
if selectionParams.penalty ~= 0
for m=1:size(sampleSmall,2) % for each period
devTotal = devTotal + sum(abs(exp(sampleSmall(:,m))>exp(targetSa.meanReq(m)+3*targetSa.stdevs(m)))) * selectionParams.penalty;
end
end

elseif selectionParams.optType == 1
elseif selectionParams.optType == 1 % compute Kolmogorov-Smirnov error metric
sortedlnSa = [min(sampleSmall); sort(sampleSmall)];
norm_cdf = normcdf(sortedlnSa,repmat(targetSa.meanReq,selectionParams.nGM+1,1),repmat(targetSa.stdevs,selectionParams.nGM+1,1));
emp_cdf = linspace(0,1,selectionParams.nGM+1);
Expand Down

0 comments on commit 651676f

Please sign in to comment.