-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentify_fault.m
More file actions
78 lines (69 loc) · 3.11 KB
/
Copy pathidentify_fault.m
File metadata and controls
78 lines (69 loc) · 3.11 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
66
67
68
69
70
71
72
73
74
75
76
77
78
function [faultyIdx, suspectSet, confidence] = identify_fault(subsets, clusterLabels, winnerIdx, N)
% IDENTIFY_FAULT Identify faulty measurement from the winning (healthy) cluster.
%
% [faultyIdx, suspectSet, confidence] = identify_fault(subsets, clusterLabels, winnerIdx, N)
%
% LOGIC:
% The healthy cluster contains subsets that all exclude the faulty measurement.
% Therefore the faulty index is the one ABSENT from the union of all
% measurement indices present in the winning cluster's subsets.
%
% present = union of all indices that appear in any winning-cluster subset
% faulty = {1,...,N} \ present
%
% INPUTS:
% subsets cell array all subsets (from enumerate_subsets), each a row
% vector of 1-indexed measurement indices
% clusterLabels [M x 1] cluster label for each subset (from cluster_estimates)
% winnerIdx integer label of the winning cluster
% N scalar total number of measurements
%
% OUTPUTS:
% faultyIdx integer (or []) 1-indexed measurement(s) identified as faulty.
% Empty if identification is ambiguous.
% suspectSet vector the absent index set (complement of union)
% confidence scalar fraction of winning-cluster subsets that exclude
% faultyIdx (1.0 = perfect identification)
M = numel(subsets);
assert(numel(clusterLabels) == M, 'identify_fault: subsets and clusterLabels must have the same length.');
% --- Gather subsets belonging to the winning cluster ---
winnerMask = (clusterLabels == winnerIdx);
winnerSubsets = subsets(winnerMask);
if isempty(winnerSubsets)
warning('identify_fault: winning cluster is empty. Cannot identify fault.');
faultyIdx = [];
suspectSet = [];
confidence = 0;
return;
end
% --- Union of all measurement indices present in winning cluster ---
presentSet = [];
for k = 1:numel(winnerSubsets)
presentSet = union(presentSet, winnerSubsets{k});
end
% --- Complement: indices absent from all winning-cluster subsets ---
fullSet = 1:N;
suspectSet = setdiff(fullSet, presentSet);
if isempty(suspectSet)
warning('identify_fault: all measurements appear in the winning cluster. Identification ambiguous.');
faultyIdx = [];
confidence = 0;
return;
end
if numel(suspectSet) > 1
warning('identify_fault: multiple absent indices %s. System may have multiple faults or insufficient redundancy.', ...
mat2str(suspectSet));
faultyIdx = suspectSet; % return all suspects
confidence = 0.5; % flag ambiguity
return;
end
faultyIdx = suspectSet; % single faulty measurement index
% --- Confidence: fraction of winning-cluster subsets that exclude faultyIdx ---
excludeCount = 0;
for k = 1:numel(winnerSubsets)
if ~ismember(faultyIdx, winnerSubsets{k})
excludeCount = excludeCount + 1;
end
end
confidence = excludeCount / numel(winnerSubsets);
end