1 %> @brief Univariate Outlier removal
3 %> This
block generates two datasets. The first one contains the inliers and the second one the outliers.
4 %> The inlier is derived at training stage. \c train() and \c use() don't need to be called with the same dataset, but
5 %> the datasets do need to have the same number of rows.
7 properties(SetAccess=protected)
14 %> =1. Index of feature to consider
16 %> Number of bins for histogram calculation.
18 %> [no_ranges][2] matrix. Univariate outlier removal is range-based. Descendants may have different ways to fill in this property.
24 o.classtitle = 'Univariate';
29 %. @brief Returns the index of the first bin that already starts above the 50%
30 function z = get_idx_50plus(o, x)
32 [val, idx] = find(I > I(end)/2);
36 function o = calculate_map(o, data)
37 o = o.calculate_ranges(data);
38 boolmap = ones(1, length(o.distances));
39 for i = 1:size(o.ranges, 1)
40 boolmap = boolmap & ~((o.distances >= o.ranges(i, 1)) & (o.distances < o.ranges(i, 2)));
42 o.map = find(boolmap);
45 function o = calculate_distances(o, data)
47 o.distances = data.X(:, o.idx_fea)';
54 function o = calculate_ranges(o, data)
57 %> @brief Calculates @c edges and @c hist properties. Dependant on calling @c calculate_distances() first.
58 function o = calculate_hits(o)
59 if isempty(o.distances)
63 maxdist = max(o.distances);
64 mindist = min(o.distances);
65 offset = (maxdist-mindist)*.00001;
66 o.edges = linspace(mindist-offset, maxdist+offset, o.no_bins+1);
67 o.hits = histc(o.distances, o.edges);
68 o.hits = o.hits(1:end-1); % For some reason histc always places a zero element at the end
72 %> Draws hachures do signal ranges, and histogram
73 function o = draw_histogram(o)
74 o = o.calculate_hits();
77 % Replaces infinities in ranges
79 di = o.edges(2)-o.edges(1);
80 ra(ra == -Inf) = o.edges(1)-di;
81 ra(ra == +Inf) = o.edges(end)+di;
83 x = sum([o.edges(1:end-1); o.edges(2:end)], 1)/2;
84 maxy = max(o.hits)*1.1;
87 if ra(i, 2) > ra(i, 1)
95 bar(x, o.hits, 'FaceColor', [.3, .3, 1]);
98 xlim([o.edges(1), o.edges(end)]);
Outlier Removal base class.
Univariate Outlier removal.
function draw_hachure(in position)