LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
example_infer_ubr_changepoint.m
1clear node jobclass
2%% Example: UBR sliding-window change-point detection (open network)
3%
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.
6%
7% Copyright (c) 2012-2026, Imperial College London
8% All rights reserved.
9
10%% define model
11model = Network('model');
12
13node{1} = Delay(model, 'Delay');
14node{2} = Queue(model, 'Queue1', SchedStrategy.FCFS);
15node{3} = Source(model, 'Source');
16node{4} = Sink(model, 'Sink');
17
18jobclass{1} = OpenClass(model, 'Class1', 0);
19
20node{1}.setService(jobclass{1}, Exp.fitMean(1.0));
21node{2}.setService(jobclass{1}, Exp(NaN));
22node{3}.setArrival(jobclass{1}, Exp(1.0));
23
24P = model.initRoutingMatrix;
25P{1,1} = [0,1,0,0; 0,0,0,1; 1,0,0,0; 0,0,0,0];
26model.link(P);
27
28%% Generate data with change point
29n = 200;
30changeT = 100;
31D1 = 0.3; % demand before change
32D2 = 0.6; % demand after change
33lambda = 1.0;
34noise = 0.02;
35
36ts = (1:n)';
37arvr_samples = lambda*ones(n,1) + randn(n,1)*noise;
38
39% Utilization and response time change with demand
40util_samples = zeros(n,1);
41respt_samples = zeros(n,1);
42for t = 1:n
43 if t <= changeT
44 D = D1;
45 else
46 D = D2;
47 end
48 U = lambda * D + randn(1)*noise;
49 U = max(0.01, min(0.95, U));
50 util_samples(t) = U;
51 respt_samples(t) = D / (1 - U) + randn(1)*noise*0.1;
52end
53
54%% Sliding-window estimation
55W = 30; % window size
56estimates = zeros(n - W + 1, 1);
57
58for t = W:n
59 idx = (t-W+1):t;
60
61 node{2}.setService(jobclass{1}, Exp(NaN));
62 model.reset();
63
64 estoptions = ParamEstimator.defaultOptions;
65 estoptions.method = 'ubr';
66 se = ParamEstimator(model, estoptions);
67
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}));
70 se.interpolate();
71 estVal = se.estimateAt(node{2});
72 estimates(t - W + 1) = estVal(1);
73end
74
75%% Report results
76tAxis = (W:n)';
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);
80
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)
86 t = checkpoints(i);
87 if t >= W && t <= n
88 est = estimates(t - W + 1);
89 if t <= changeT
90 trueD = D1;
91 else
92 trueD = D2;
93 end
94 fprintf(1, '%6d %10.4f %10.4f\n', t, est, trueD);
95 end
96end
97
98%% Plot
99figure;
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);
104xlabel('Time');
105ylabel('Estimated Demand');
106title('UBR Sliding-Window Change-Point Detection');
107legend('UBR estimate', 'Location', 'southeast');
108grid on;