加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
load_generic_norm_dist_data.m 2.87 KB
一键复制 编辑 原始数据 按行查看 历史
Roemer Vlasveld 提交于 2013-07-30 10:55 . Move documentation to top
% LOAD_GENERIC_NORM_DIST_DATA Generate data following normal distributions
%
% [DATA, CP] = LOAD_GENERIC_NORM_DIST_DATA(SIZE, TYPE)
%
% The SIZE indicates the length of the requested data sequence (default
% 100)
%
% The TYPE sets the type of segments/distributions. The options are:
% - 'alternating: (default) generate with alternating variances of 5 and
% 1, mean 0
% - 'paper': Use the patern of the paper on CUSUM by Inclan and Tiao.
% Mean 0 and variances in segment [1 : 391] -> 1, [391 : 518] -> 0.365
% and [518 : 700] -> 1.033
% - 'homogeneous': single segment with mean 0 and variance 1.
% - 'single': two segments with mean 0 and variances 1 and 2
%
% The vector CHANGE_POINTS containts the data times at which the pattern
% changed
function [ data, change_points ] = load_generic_norm_dist_data(size,type)
if nargin < 2
type = 'alternating';
if nargin < 1
size = 100;
end
end
% Determine which generation function to use
switch type
case 'alternating'
[data, change_points] = AlternatingVariance(size, 5, [1, 5, 1, 5, 1]);
case 'paper'
[data, change_points] = PaperExample();
case 'homogeneous'
[data, change_points] = AlternatingVariance(size, 1, 1);
case 'single'
[data, change_points] = AlternatingVariance(size, 2, [1, 2]);
otherwise
warning('Unexpected function type.');
end
change_points(1) = [];
end
function [values, change_points] = AlternatingVariance(size, segments, variances)
% ALTERNATING_VARIANCE Generate a sequence of data with alternating
% variance. Mean is fixed at 0.
fprintf('Generating alternating variance data \n');
change_points = ones(segments-1,1);
if nargin < 3
variances = [1, 3, 1];
if nargin < 2
segments = 3;
if nargin < 1
size = 100;
end
end
end
values = zeros(1, size);
per_segment = size / segments;
j = 1;
for segment = 1:segments
variance = variances(segment);
fprintf(' new segment at %i with variance %i \n', j, variance );
change_points(segment) = j;
for i = 1:per_segment
values(j) = normrnd(0, variance);
j = j + 1;
end
end
end
function [values, change_points] = PaperExample()
fprintf('Generating data following the scheme in the paper: \n');
fprintf(' [1 : 391]: 1 \n');
fprintf(' [391 : 518]: 0.365 \n');
fprintf(' [518 : 700]: 1.033 \n');
change_points = [1, 391 518 700];
values = zeros(1,700);
for i=1:391
values(i) = normrnd(0, 1);
end
for i=392:518
values(i) = normrnd(0, 0.365);
end
for i=519:700
values(i) = normrnd(0,1.033);
end
end
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化