-
Notifications
You must be signed in to change notification settings - Fork 0
/
TSSRP.py
68 lines (60 loc) · 2.24 KB
/
TSSRP.py
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
import numpy as np
from scipy.special import logsumexp
from model.srpabstract import SRPAbstract
import pdb
class TSSRP(SRPAbstract):
"""
Extended the SRPAbstract class
"""
def __init__(self, p, c, k, M, nsensors, Ks, L=-1, chart = 'srp',mode = 'T2',selectmode='indi',decisionchart = 1):
"""
srp is the main class of the library
Input:
- p: Number of dimensions
- c: scale vector, Target meanshift is c * M
- k: Number of failuer Mode
- M: Failure Mode Mean Matrix of k failure modes: p * k
- nsensors: number of selected sensors
- Ks: Number of selected failure mode
- L: control limit, set to -1 if not initialized yet.
"""
super().__init__(p, c, k, M, nsensors, Ks, L, chart, mode, selectmode, decisionchart)
def compute_log_LRT(self,a,x):
"""
Compute the log liklihood ratio of
Input:
- a: sensing vectors
- x: sensing data, must be in format of p * 1
"""
c = self.c
# M = np.eye(self.k)
M = self.M
E = 2*c*M*x - c**2*M**2
return a@E
def compute_index(self,failureModeTopIdx,r=1):
"""
Compute the index function to decide the best sensing allocation
Input:
- x_sample: sampled version of x, must be in format of p * 1 or p * k
- failureModeTopIdx: The most important failure index
- mode: Types of monitoring statistics
"""
c = self.c
p = self.p
M = self.M
nsensors = self.nsensors
x_sample = np.zeros(p)
return failureModeTopIdx
if self.mode == 'T2':
# sensingIdx = failureModeTopIdx
for ik in failureModeTopIdx:
x_sample += np.random.randn(p) + M[:,ik]*c
# print(x_sample.shape)
sensingIdx = np.argsort(-x_sample)[:nsensors]
elif self.mode == 'T1':
# individualS = np.sum(np.exp(r[failureModeTopIdx]))
individualS = np.sum((r[failureModeTopIdx]))
sensingIdx = np.argsort(-individualS)[:nsensors]
elif self.mode == 'full':
sensingIdx = np.arange(nsensors)
return sensingIdx