-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.m
78 lines (75 loc) · 1.75 KB
/
Test.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
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
function [falserate,Detectionrate,falsealarmrate,result] = Test( FPC,Mu,dmax,correct,false)
%检测阶段,采用220组正确的数据,100组可能错误的数据
Fcount=0;
Dcount=0;
Detectionrate=0;%检测率
falsealarmrate=0;%错检率
falserate=false/(correct+false);
test=zeros(correct+false,3);
result=zeros(1,correct+false);
X=[0.3 0.35 0.4];%均值集合
%检验正常数据
for i=1:correct
for j=1:3
mu=X(randperm(3,1));
Sigma=0.03;
test(i,j)=normrnd(mu,Sigma);
end
%计算到第一主成分的距离
s1=test(i,:)-Mu;
d1=norm(s1,2);
d2=s1*FPC;
di=sqrt(d1.^2-d2.^2);
%判断是否超过阈值,判断是否是故障
if(di<=dmax)
result(1,i)=1;
else
Fcount=Fcount+1;
end
end
falsealarmrate=Fcount/correct;
x=test(1:correct,1);
y=test(1:correct,2);
z=test(1:correct,3);
%xlswrite('data.xls',train);%数据写入excel表格保存
scatter3(x,y,z,'b','.');%数据集合的空间分布图形
hold on;
% %检验异常数据
% for i=correct+1:correct+false
% for j=1:3
% test(i,j)=unifrnd(0.4,0.6);
% end
% s1=test(i,:)-Mu;
% d1=norm(s1,2);
% d2=s1*FPC;
% di=sqrt(d1.^2-d2.^2);
% %判断是否超过阈值,判断是否是故障
% if(di<=dmax)
% result(1,i)=1;
% end
% end
%检测某个属性异常的数据
for i=correct+1:correct+false
for j=1:2
mu=X(randperm(3,1));
Sigma=0.03;
test(i,j)=normrnd(mu,Sigma);
end
test(i,3)=unifrnd(0.4,0.6);
s1=test(i,:)-Mu;
d1=norm(s1,2);
d2=s1*FPC;
di=sqrt(d1.^2-d2.^2);
%判断是否超过阈值,判断是否是故障
if(di<=dmax)
result(1,i)=1;
else
Dcount=Dcount+1;%检测数据是错误的个数
end
end
Detectionrate=Dcount/false
x=test(correct+1:correct+false,1);
y=test(correct+1:correct+false,2);
z=test(correct+1:correct+false,3);
scatter3(x,y,z,'r','*')
end