2%% Example: UBR sliding-window change-point detection (open network)
4% Service demand changes from D=0.3 to D=0.6 at t=100.
5% A sliding window of size W
is used to estimate demands online.
7% Copyright (c) 2012-2026, Imperial College London
11model = Network(
'model');
13node{1} = Delay(model,
'Delay');
14node{2} = Queue(model,
'Queue1', SchedStrategy.FCFS);
15node{3} = Source(model,
'Source');
16node{4} = Sink(model,
'Sink');
18jobclass{1} = OpenClass(model,
'Class1', 0);
20node{1}.setService(
jobclass{1}, Exp.fitMean(1.0));
21node{2}.setService(
jobclass{1}, Exp(NaN));
22node{3}.setArrival(
jobclass{1}, Exp(1.0));
24P = model.initRoutingMatrix;
25P{1,1} = [0,1,0,0; 0,0,0,1; 1,0,0,0; 0,0,0,0];
28%% Generate data with change point
31D1 = 0.3; % demand before change
32D2 = 0.6; % demand after change
37arvr_samples = lambda*ones(n,1) + randn(n,1)*noise;
39% Utilization and response time change with demand
40util_samples = zeros(n,1);
41respt_samples = zeros(n,1);
48 U = lambda * D + randn(1)*noise;
49 U = max(0.01, min(0.95, U));
51 respt_samples(t) = D / (1 - U) + randn(1)*noise*0.1;
54%% Sliding-window estimation
56estimates = zeros(n - W + 1, 1);
61 node{2}.setService(jobclass{1}, Exp(NaN));
64 estoptions = ParamEstimator.defaultOptions;
65 estoptions.method = 'ubr
';
66 se = ParamEstimator(model, estoptions);
68 se.addSamples(SampledMetric(MetricType.ArvR, ts(idx), arvr_samples(idx), node{2}, jobclass{1}));
69 se.addSamples(SampledMetric(MetricType.Util, ts(idx), util_samples(idx), node{2}));
71 estVal = se.estimateAt(node{2});
72 estimates(t - W + 1) = estVal(1);
77fprintf(1,
'\n=== UBR Change-Point Detection ===\n');
78fprintf(1,
'True demand: D=%.1f (t<=100), D=%.1f (t>100)\n', D1, D2);
79fprintf(1,
'Window size: %d\n\n', W);
81% Report estimates at key time points
82checkpoints = [W, 50, 80, 100, 110, 120, 130, 150, 180, 200];
83fprintf(1,
'%6s %10s %10s\n',
't',
'Estimated',
'True');
84fprintf(1,
'%6s %10s %10s\n',
'------',
'----------',
'----------');
85for i = 1:length(checkpoints)
88 est = estimates(t - W + 1);
94 fprintf(1,
'%6d %10.4f %10.4f\n', t, est, trueD);
100plot(tAxis, estimates,
'b-',
'LineWidth', 1.5); hold on;
101yline(D1,
'r--', sprintf(
'D=%.1f', D1),
'LineWidth', 1);
102yline(D2,
'r--', sprintf(
'D=%.1f', D2),
'LineWidth', 1);
103xline(changeT,
'k:',
'Change point',
'LineWidth', 1);
105ylabel(
'Estimated Demand');
106title(
'UBR Sliding-Window Change-Point Detection');
107legend(
'UBR estimate',
'Location',
'southeast');