-
Notifications
You must be signed in to change notification settings - Fork 5
/
outlier_detection.m
34 lines (30 loc) · 972 Bytes
/
outlier_detection.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
function q_outlier = outlier_detection(q, time, mq, k)
% OUTLIER_DETECTION Outlier Detection
% -------------------------------------------------------------------------
% This function calculates outlier's using geodesic distances of the SRVFs from
% the median
%
% Usage: [mu,gam_mu,psi,vec] = outlier_detection(q, time, mq)
% [mu,gam_mu,psi,vec] = outlier_detection(q, time, mq, k)
%
% Input:
% q: matrix (\eqn{N} x \eqn{M}) of \eqn{M} SRVF functions with \eqn{N} samples
% time: vector of size \eqn{N} describing the sample points
% mq: median calculated using time_warping
% k: cutoff threshold (default = 1.5)
%
% Output
% q_outlier: outlier functions
if nargin < 4
k = 1.5;
end
N = size(q,2);
ds = zeros(1,N);
for kk = 1:N
ds(kk) = sqrt(sum(trapz(time, (mq-q(:,kk)).^2)));
end
quartile_range = quantile(ds, [0 .25 .50 .75 1]);
IQR = quartile_range(4) - quartile_range(2);
thresh = quartile_range(4) + k * IQR;
ind = ds > thresh;
q_outlier = q(:,ind);