-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialization of repo based on initial MatLab code base
- Loading branch information
0 parents
commit 0efa25d
Showing
7 changed files
with
5,232 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function p = allpaths(A,start,last) | ||
% find all direct paths from start to last | ||
% A is (n x 2) each row is an edges | ||
A = sortrows(A); | ||
b = true(size(A,1),1); | ||
p = gapengine(A,b,start,last); | ||
end | ||
function p = gapengine(A,b,start,last) | ||
% recursive engine | ||
if start==last | ||
p = {last}; | ||
else | ||
bs = A(:,1) == start; | ||
next = A(bs & b,2); | ||
p = {}; | ||
b(bs) = false; | ||
for k=1:length(next) | ||
i = next(k); | ||
pk = gapengine(A,b,i,last); | ||
pk = cellfun(@(p) [start, p], pk, 'unif', 0); | ||
p = [p, pk]; | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
function pd1 = cost_cdfdist(c1,c2) | ||
|
||
% Force all inputs to be column vectors | ||
c1 = c1(:); | ||
c2 = c2(:); | ||
|
||
% Prepare figure | ||
clf; | ||
hold on; | ||
LegHandles = []; LegText = {}; | ||
|
||
|
||
% --- Plot data originally in dataset "c1 data" | ||
% This dataset does not appear on the plot | ||
|
||
% Get data limits to determine plotting range | ||
XLim = [0.8*min(c1),1.2*max(c1)]; | ||
|
||
% Create grid where function will be computed | ||
XLim = XLim + [0 1] * 0.01 * diff(XLim); | ||
XGrid = linspace(XLim(1),XLim(2),100); | ||
|
||
|
||
% --- Create fit "fit 1" | ||
pd1 = fitdist(c1,'kernel','kernel','normal','support','unbounded'); | ||
YPlot1 = cdf(pd1,XGrid); | ||
hLine = plot(XGrid,YPlot1,'Color',[0 0 0],... | ||
'LineStyle','-', 'LineWidth',2,... | ||
'Marker','none', 'MarkerSize',6); | ||
LegHandles(end+1) = hLine; | ||
LegText{end+1} = 'Tentative cost CDF'; | ||
|
||
hold on | ||
|
||
|
||
a=find(YPlot1>0.999); | ||
if length(a)>0 | ||
a=a(1); | ||
text(XGrid(a),0.96,1,strcat('cost=',num2str(round(XGrid(a)))),'Color','red','FontSize',14); | ||
|
||
plot(XGrid(a),1,'o','MarkerSize',10,'LineWidth',2); | ||
end | ||
|
||
hold on | ||
|
||
% --- Plot data originally in dataset "c2 data" | ||
% This dataset does not appear on the plot | ||
|
||
% Get data limits to determine plotting range | ||
XLim = [0.8*min(c2), 1.2*max(c2)]; | ||
|
||
% Create grid where function will be computed | ||
XLim = XLim + [0 1] * 0.01 * diff(XLim); | ||
XGrid = linspace(XLim(1),XLim(2),100); | ||
|
||
xlabel('cost (Euros)','FontSize',20) | ||
ylabel('Cumulative probability','FontSize',20) | ||
bx = gca; | ||
bx.FontSize = 20; | ||
|
||
% --- Create fit "fit 2" | ||
pd2 = fitdist(c2,'kernel','kernel','normal','support','unbounded'); | ||
YPlot2 = cdf(pd2,XGrid); | ||
hLine = plot(XGrid,YPlot2,'Color',[0.7 0.7 0.7],... | ||
'LineStyle','-', 'LineWidth',2,... | ||
'Marker','none', 'MarkerSize',6); | ||
LegHandles(end+1) = hLine; | ||
LegText{end+1} = 'Permanent cost CDF'; | ||
% Adjust figure | ||
box on; | ||
grid on; | ||
hold off; | ||
|
||
% Create legend from accumulated handles and labels | ||
hLegend = legend(LegHandles,LegText,'Orientation', 'vertical', 'FontSize', 18, 'Location', 'northwest'); | ||
set(hLegend,'Interpreter','none'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
function pd1 = cost_pdfdist(c1,c2) | ||
|
||
% Force all inputs to be column vectors | ||
c1 = c1(:); | ||
c2 = c2(:); | ||
|
||
% Prepare figure | ||
clf; | ||
hold on; | ||
LegHandles = []; LegText = {}; | ||
|
||
%% | ||
% Get data limits to determine plotting range | ||
XLim = [0.8*min(c1),1.2*max(c1)]; | ||
|
||
% Create grid where function will be computed | ||
XLim = XLim + [0 1] * 0.01 * diff(XLim); | ||
XGrid = linspace(XLim(1),XLim(2),100); | ||
|
||
%% | ||
% --- Plot data originally in dataset "c1 data" | ||
[CdfF,CdfX] = ecdf(c1,'Function','cdf'); % compute empirical cdf | ||
BinInfo.rule = 1; | ||
[~,BinEdge] = internal.stats.histbins(c1,[],[],BinInfo,CdfF,CdfX); | ||
[BinHeight,BinCenter] = ecdfhist(CdfF,CdfX,'edges',BinEdge); | ||
hLine = bar(BinCenter,BinHeight,'hist'); | ||
set(hLine,'FaceColor','none','EdgeColor',[0 0 0],... | ||
'LineStyle','-', 'LineWidth',1); | ||
|
||
LegHandles(end+1) = hLine; | ||
LegText{end+1} = 'Tentative cost histogram'; | ||
|
||
hold on | ||
|
||
%% | ||
% --- Create fit "pdf1" | ||
pd1 = fitdist(c1,'kernel','kernel','normal','support','unbounded'); | ||
YPlot = pdf(pd1,XGrid); | ||
hLine = plot(XGrid,YPlot,'Color',[0 0 0],... | ||
'LineStyle','-', 'LineWidth',3,... | ||
'Marker','none', 'MarkerSize',6); | ||
LegHandles(end+1) = hLine; | ||
LegText{end+1} = 'Tentative cost PDF'; | ||
|
||
hold on | ||
|
||
%% | ||
% Get data limits to determine plotting range | ||
XLim = [0.8*min(c2), 1.2*max(c2)]; | ||
|
||
% Create grid where function will be computed | ||
XLim = XLim + [0 1] * 0.01 * diff(XLim); | ||
XGrid = linspace(XLim(1),XLim(2),100); | ||
%% | ||
% --- Plot data originally in dataset "c2 data" | ||
[CdfF,CdfX] = ecdf(c2,'Function','cdf'); % compute empirical cdf | ||
BinInfo.rule = 1; | ||
[~,BinEdge] = internal.stats.histbins(c2,[],[],BinInfo,CdfF,CdfX); | ||
[BinHeight,BinCenter] = ecdfhist(CdfF,CdfX,'edges',BinEdge); | ||
hLine = bar(BinCenter,BinHeight,'hist'); | ||
set(hLine,'FaceColor','none','EdgeColor',[0.7 0.7 0.7],... | ||
'LineStyle','-', 'LineWidth',1); | ||
xlabel('cost (Euros)','FontSize',20) | ||
ylabel('PDF','FontSize',20) | ||
LegHandles(end+1) = hLine; | ||
LegText{end+1} = 'Permanent cost histogram'; | ||
bx = gca; | ||
bx.FontSize = 20; | ||
|
||
hold on | ||
|
||
%% | ||
% --- Create fit "pdf2" | ||
|
||
pd2 = fitdist(c2,'kernel','kernel','normal','support','unbounded'); | ||
|
||
YPlot = pdf(pd2,XGrid); | ||
hLine = plot(XGrid,YPlot,'Color',[0.7 0.7 0.7],... | ||
'LineStyle','-', 'LineWidth',2,... | ||
'Marker','none', 'MarkerSize',6); | ||
LegHandles(end+1) = hLine; | ||
LegText{end+1} = 'Permanent cost PDF'; | ||
|
||
% Adjust figure | ||
box on; | ||
hold off; | ||
|
||
% Create legend from accumulated handles and labels | ||
hLegend = legend(LegHandles,LegText,'Orientation', 'vertical', 'FontSize', 20, 'Location', 'northeast'); | ||
set(hLegend,'Interpreter','none'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
function fitting(y_opt,y_all,y_0,y_0_nouncertainty,T_pl) | ||
rng('default'); % for reproducibility | ||
|
||
% Force all inputs to be column vectors | ||
y_opt = y_opt(:); | ||
y_all = y_all(:); | ||
y_0 = y_0(:); | ||
y_0_nouncertainty=y_0_nouncertainty(:)+1; | ||
|
||
% Prepare figure | ||
clf; | ||
hold on; | ||
LegHandles = []; LegText = {}; | ||
|
||
%Data boundaries adjustment | ||
[CdfY,CdfX] = ecdf(y_all,'Function','cdf'); % compute empirical function | ||
a=CdfX(1)-2; | ||
b=CdfY(1); | ||
[CdfY,CdfX] = ecdf(y_0,'Function','cdf'); % compute empirical function | ||
c=CdfX(end)+2; | ||
d=CdfY(end); | ||
|
||
|
||
%% | ||
% --- Plot data originally in dataset "y_0_nouncertainty data" | ||
[CdfY,CdfX] = ecdf(y_0_nouncertainty,'Function','cdf'); % compute empirical function | ||
|
||
CdfX=[a;CdfX;c]; | ||
CdfY=[b;CdfY;d]; | ||
|
||
hLine = plot(CdfX,CdfY,'lineWidth',2,'Color' , [0.7 0.7 0.7],'DisplayName','Orig Dur'); | ||
|
||
hold on; | ||
|
||
%% | ||
% --- Plot data originally in dataset "y_0 data" | ||
[CdfY,CdfX] = ecdf(y_0,'Function','cdf'); % compute empirical function | ||
%hLine = stairs(CdfX,CdfY,'Color',[0 0 0],'LineStyle','-', 'LineWidth',1); | ||
%hold on; | ||
|
||
% --- Create fit for "y_0 data" | ||
CdfX(1)=CdfX(1)-1; | ||
CdfX=[a;CdfX;c]; | ||
CdfY=[b;CdfY;d]; | ||
x=CdfX; | ||
xq2 = linspace(CdfX(1),CdfX(end),200); | ||
p1 = pchip(x,CdfY,xq2); | ||
plot(xq2,p1,':','lineWidth',2,'Color' , [0.7 0.7 0.7],'DisplayName','NoMit') | ||
hold on | ||
|
||
%% | ||
% --- Plot data originally in dataset "y_all data" | ||
[CdfY,CdfX] = ecdf(y_all,'Function','cdf'); % compute empirical function | ||
%hLine = stairs(CdfX,CdfY,'Color',[0.333333 0.666667 0],'LineStyle','-', 'LineWidth',1); | ||
|
||
% --- Create fit for "y_all data" | ||
CdfX(1)=CdfX(1)-1; | ||
CdfX=[a;CdfX;c]; | ||
CdfY=[b;CdfY;d]; | ||
|
||
x=CdfX; | ||
xq2 = linspace(CdfX(1),CdfX(end),200); | ||
p2 = pchip(x,CdfY,xq2); | ||
plot(xq2,p2,'--','lineWidth',2, 'Color' , [0.7 0.7 0.7],'DisplayName','Permanent') | ||
hold on; | ||
|
||
%% | ||
% --- Plot data originally in dataset "y_opt data" | ||
[CdfY,CdfX] = ecdf(y_opt,'Function','cdf'); % compute empirical function | ||
%hLine = stairs(CdfX,CdfY,'Color',[0.333333 0 0.666667],'LineStyle','-', 'LineWidth',1); | ||
|
||
% --- Create fit for "y_opt data" | ||
CdfX(1)=CdfX(1)-1; | ||
CdfX=[a;CdfX;c]; | ||
CdfY=[b;CdfY;d]; | ||
x=CdfX; | ||
xq2 = linspace(CdfX(1),CdfX(end),200); | ||
p3 = pchip(x,CdfY,xq2); | ||
plot(xq2,p3,'lineWidth',2,'Color' , 'k','DisplayName','Tentative') | ||
|
||
hold on; | ||
|
||
a=find(x>=T_pl); | ||
if length(a)>0 | ||
a=a(1); | ||
text(T_pl,CdfY(a)-0.05,1,strcat('Target duration=',num2str(T_pl)),'Color','red','FontSize',14); | ||
plot(T_pl+1,CdfY(a)+0.006,'o','Color','red','MarkerSize',10,'LineWidth',2,'DisplayName','Planned duration'); | ||
end | ||
%% | ||
% Create grid where function will be computed | ||
XLim = get(gca,'XLim'); | ||
XLim = XLim + [-1 1] * 0.01 * diff(XLim); | ||
XGrid = linspace(XLim(1),XLim(2),800); | ||
xlabel('Duration (days)','FontSize',20) | ||
ylabel('Cumulative probability','FontSize',20) | ||
bx = gca; | ||
bx.FontSize = 20; | ||
|
||
% Adjust figure | ||
box on; | ||
hold off; | ||
|
||
% Create legend from accumulated handles and labels | ||
legend('Orig Dur','No Mit','Permanent','Tentative'); | ||
hLegend = legend(LegHandles,LegText,'Orientation', 'vertical', 'FontSize', 18, 'Location', 'northeast'); | ||
set(hLegend,'Interpreter','none'); | ||
|
||
|
||
grid on |
Oops, something went wrong.