-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathpschedclust.m
More file actions
65 lines (58 loc) · 1.76 KB
/
Copy pathpschedclust.m
File metadata and controls
65 lines (58 loc) · 1.76 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function pind = pschedclust(mu,f,p,tol1,tol2)
%PSCHEDCLUST Periodic clustering of scheduling sequence
% pind=pschedclust(mu,f,p,tol1,tol2) clusters the (quasi) scheduling sequence
% mu for periodic repetitions of p sized windows. It is intended as a
% preprocessor for pordvarx. The algortihm uses a divide and conqeur
% approach for sorting the p windowed vectors. After sorting the vectors
% are bined in group up to a tolerance tol.
%
% See also: pordvarx, pmodx, px2abck, px2abcdk.
% Ivo Houtzager
% Delft Center of Systems and Control
% Delft University of Technology
% The Netherlands, 2010
% assign default values to unspecified parameters
if (nargin < 5) || isempty(tol2)
tol1 = 1e-3;
end
if (nargin < 5) || isempty(tol1)
tol2 = 1e-3;
end
% check dimensions of inputs
if size(mu,2) < size(mu,1)
mu = mu';
end
N = size(mu,2);
s = size(mu,1);
% check the size of the windows
if f > p
error('Future window size f must equal or smaller then past window p. (f <= p)')
end
% clustering of scheduling periods
k = 0;
pvec = [];
MU = zeros((p+f)*s,N-p-f+1);
for i = 1:N-p-f+1
d = mu(:,i:i+p+f-1);
MU(:,i) = d(:);
end
% cluster by divide and conquer
msum = sum(MU,1)./(p+f);
for i = 1:N-p-f+1
if isempty(pvec) || ~any(pvec == i)
k = k + 1;
pvec = [pvec i];
pind{k,1} = i;
mind = find((msum >= (msum(i) - tol1)) & (msum <= (msum(i) + tol1)));
for j = 1:length(mind)
if i ~= mind(j) && ~any(pvec == mind(j))
if norm(MU(:,i) - MU(:,mind(j)))/sqrt(p+f) <= tol2
pvec = [pvec mind(j)];
pind{k,1} = [pind{k,1} mind(j)];
end
end
end
end
end
MU = [];
end