-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBOCDm_restart.m
36 lines (31 loc) · 1.53 KB
/
BOCDm_restart.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
%% Bayesian Online Change-point Detection modified without restart and simple prior
% Inputs:
% -- NbrRuns:
% -- environment: vector of piece-wise Bernoulli distributions
% Outputs:
% -- ChangePointEstimations: vector of change-point estimations
function [ChangePointEstimations]= BOCDm_restart(environment, NbrRuns)
% ----------------- Initialization -------------------
Horizon = length(environment);
gamma = (1./Horizon);
ChangePointEstimations = [];
%----------- Launch the Online Change-point Detection procedure
display('Launching BOCD Modified with restart ...')
for run = 1:NbrRuns;
ForecasterDistribution = [1];
PseudoDist = [1]; like1 = 1;
alphas = [1]; betas = [1]; % Initialization for Laplace predictor
Restart = 1; % Position of last restart
CPEstimation = [];
for t = 1: Horizon
[~, BestForecaster] = max(ForecasterDistribution);
if (BestForecaster ~= 1) % Restart criterion
ForecasterDistribution = [1]; like1 = 1; alphas = [1]; betas = [1]; Restart = t+1; % Reinitialization
end
CPEstimation = [CPEstimation Restart]; %Change-point estimation
x = rand() < environment(t); % Get the observation from the environment
[ForecasterDistribution, PseudoDist,like1] = updateForecasterDistribution_m(ForecasterDistribution, PseudoDist, alphas,betas,x,gamma, like1);
[alphas, betas] = updateLaplacePrediction(alphas,betas, x);
end
ChangePointEstimations = [ChangePointEstimations; CPEstimation];
end