Skip to content

Commit

Permalink
Adds extrapolation method to calls to "interp1" (#233)
Browse files Browse the repository at this point in the history
* Adds extrapolation method to calls to "interp1"

* Replaces "interp1q" with "interp1" in "cornerPlot.m"
  • Loading branch information
DrPaulSharp authored Jun 3, 2024
1 parent 77fb001 commit 3fb3de1
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 18 deletions.
6 changes: 3 additions & 3 deletions minimisers/NS/parseBayesResults.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
[csu, iu, ju] = unique(cs);

% get lower bound on the interval
values(par,2) = interp1(csu, bins(iu), 0.5-(probarea/2));
values(par,2) = interp1(csu, bins(iu), 0.5-(probarea/2),'linear','extrap');

% get upper bound on the interval
values(par,3) = interp1(csu, bins(iu), 0.5+(probarea/2));
values(par,3) = interp1(csu, bins(iu), 0.5+(probarea/2),'linear','extrap');

%get best value
%values(par,1) = mean(max(postvals));
Expand Down Expand Up @@ -95,7 +95,7 @@
% referenceRef = thisRef;
% groupRefs{i}(:,n) = referenceRef(:,2);
% else
newRefy = interp1(thisRef(:,1),thisRef(:,2),bestFit{i}(:,1));
newRefy = interp1(thisRef(:,1),thisRef(:,2),bestFit{i}(:,1),'linear','extrap');
groupRefs{i}(:,n) = newRefy;
%end
end
Expand Down
2 changes: 1 addition & 1 deletion minimisers/generalUtils/bayesStats/processBayes.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
bestFitMean.data = result.shiftedData;

% 2. Reflectivity and SLD shading
predInts = refPercentileConfidenceIntervals(bayesOutputs,problemStruct,problemCells,problemLimits,controls,result,confidenceIntervals);
predInts = refPercentileConfidenceIntervals(bayesOutputs,problemStruct,problemCells,problemLimits,controls);

% ---------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function allPredInts = percentileConfidenceIntervals(bayesOutputs,problemStruct,problemCells,problemLimits,controlsStruct,result,parConfInts)
function allPredInts = refPercentileConfidenceIntervals(bayesOutputs,problemStruct,problemCells,problemLimits,controlsStruct)

% Need to deal slightly differently with SLDs if there are domains
if strcmpi(problemStruct.TF, coderEnums.calculationTypes.Domains)
Expand Down Expand Up @@ -117,12 +117,12 @@

if ~domains
thisSldXVal = sldXVals{n};
thisSLDYval = interp1(thisSld{n}(:,1),thisSld{n}(:,2),thisSldXVal);
thisSLDYval = interp1(thisSld{n}(:,1),thisSld{n}(:,2),thisSldXVal,'linear','extrap');
sldYVals{n}(i,:) = thisSLDYval;
else
for m = 1:2
thisSldXVal = sldXVals{n,m};
thisSLDYval = interp1(thisSld{n,m}(:,1),thisSld{n,m}(:,2),thisSldXVal);
thisSLDYval = interp1(thisSld{n,m}(:,1),thisSld{n,m}(:,2),thisSldXVal,'linear','extrap');
sldYVals{n,m}(i,:) = thisSLDYval;
end
end
Expand Down
4 changes: 2 additions & 2 deletions minimisers/generalUtils/bayesStats/refPredInterval.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@

% Get the calculated curves
thisCalcRef = result.reflectivity{n};
thisInterpCalc = interp1(thisCalcRef(:,1),thisCalcRef(:,2),xData);
thisInterpCalc = interp1(thisCalcRef(:,1),thisCalcRef(:,2),xData,'linear','extrap');
allCalcsRef(:,i) = thisInterpCalc(:);

thisCalcSld = result.sldProfiles{n};
thisInterpCalcSld = interp1(thisCalcSld(:,1),thisCalcSld(:,2),xDataSld);
thisInterpCalcSld = interp1(thisCalcSld(:,1),thisCalcSld(:,2),xDataSld,'linear','extrap');
allCalcsSld(:,i) = thisInterpCalcSld(:);

% msgBoxTest('update','',currentVal);
Expand Down
3 changes: 0 additions & 3 deletions targetFunctions/common/resampleLayers/SLDFunction.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,4 @@
sldVal = belowY - deltaY;
end

%sldVal = interp1(z,rho,x);
end


2 changes: 1 addition & 1 deletion targetFunctions/common/resampleLayers/resampleLayersReIm.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

% Now interpolate the imaginary profile so that it is on the same x points
% as the resampled real one....
newYIm = interp1(sldProfileIm(:,1),sldProfileIm(:,2),newX);
newYIm = interp1(sldProfileIm(:,1),sldProfileIm(:,2),newX,'linear','extrap');

layers = zeros(length(newX)-1,4);

Expand Down
6 changes: 3 additions & 3 deletions tests/nonPolarisedTFReflectivityCalculation/DPPCCustomXY.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
st = sld_x(1);
en = sld_x(end);
newSldX = linspace(st,en,length(sld_y));
newSldY = interp1(sld_x,sld_y,newSldX);
newSldY = interp1(sld_x,sld_y,newSldX,'linear','extrap');
new_sld = [newSldX(:) newSldY(:)];

%also filter....
Expand All @@ -160,7 +160,7 @@
st = filt_x(1);
en = filt_y(end);
newFiltX = linspace(st,en,length(filt_y));
newFiltY = interp1(filt_x,filt_y,newSldX);
newFiltY = interp1(filt_x,filt_y,newSldX,'linear','extrap');
new_filt = [newFiltX(:) newFiltY(:)];

%Need to pad the edge of the signal with zeros. Do this by padding out
Expand Down Expand Up @@ -261,7 +261,7 @@
extendedY = [yLeftPad(:) ; Y(:) ; yRightPad(:)];

%Interpolate them onto z....
newY = interp1(extendedX,extendedY,z);
newY = interp1(extendedX,extendedY,z,'linear','extrap');

% Debug plot
if debug == 1
Expand Down
3 changes: 2 additions & 1 deletion utilities/plotting/cornerPlot.m
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ function plotContours(x,y,ax)
NN = N/sum(N(:));
NS = sort(NN(:));

levels = interp1q(cumsum(NS),NS,[0.015 0.1 0.3 0.65 0.9]')';
[c, ind, ~] = unique(cumsum(NS),'stable');
levels = interp1(c, NS(ind), [0.015 0.1 0.3 0.65 0.9],'linear','extrap');

contourf(C{1},C{2},NN',levels,'parent',ax);

Expand Down
2 changes: 1 addition & 1 deletion utilities/plotting/shade.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@

% crossings
x0 = [x(1) zcross(x,y{1} - y{2}) x(end)];
y0 = interp1(x,y{1},x0);
y0 = interp1(x,y{1},x0,'linear','extrap');

% for each zero-crossing
for j = 0:length(x0)-2
Expand Down

0 comments on commit 3fb3de1

Please sign in to comment.