LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
mtrace_iat2counts.m
1function C=mtrace_iat2counts(T,A,scale,no_mex)
2% Computes the per-class counting processes of T, i.e., the counts after
3% "scale" units of time from an arrival.
4% INPUT:
5% - T: inter-arrival times
6% - A: class labels
7% - scale: time after an arrival
8% - no_mex: set to 1 to avoid using the mex file (optional, default = 0)
9% OUTPUT:
10% - C: column k is the counting process for class k
11
12if nargin < 4
13 no_mex = 0;
14end
15
16if ~no_mex && exist('mtrace_iat2counts_native') == 3
17 C = mtrace_iat2counts_native(T,A,scale);
18else
19 warning('Using slow Matlab function instead of MEX file.');
20 n = length(T);
21 CT = cumsum(T);
22 K = unique(A); % classes
23 C = zeros(n-1,length(K));
24 for i=1:n-1
25 if i >= 2
26 % speedup loop by looking at the previous value
27 cur = (i-1) + C(i-1);
28 else
29 cur = 1;
30 end
31 while CT(cur + 1) - CT(i) <= scale
32 cur = cur + 1;
33 % when the window first hits the end of the trace we return
34 if cur == n
35 for j = 1:length(K)
36 C(i,j) = sum(A((i+1):cur) == K(j));
37 end
38 C=C(1:i,:);
39 return;
40 end
41 end
42 for j = 1:length(K)
43 C(i,j) = sum(A((i+1):cur) == K(j));
44 end
45 end
46end
47
48end