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 __all__ = ['find_classification_threshold','find_filtering_threshold',
26 'find_filtering_threshold2']
27
28 from numpy import zeros
29
30 from pycv.cs.stats import Stats2e, stdnorm
31 from pycv.ext import gaussian_find_classification_threshold
32
33
34
35
36
37
38
39
40
41
42
43
44
45
47 """Compute the estimated error. Here we penalize false negative by sqrt(thelambda)
48 and false positive by 1/sqrt(thelambda).
49
50 Input:
51 stats2e: per-element statistics of 2*N classes
52 thelambda: the value of 'lambda'
53 Output:
54 b: a numpy.array of shape (N,2) to hold the results where
55 b[i][0]: a threshold minimizing w.r.t. b
56 f(b) = (1/sqrt(thelambda) * w[i*2] * sf((b-mu[i*2])/sigma[i*2]) +
57 sqrt(thelambda) * w[i*2+1] * cdf((b-mu[i*2+1])/sigma[i*2+1]))
58 / (w[i*2]+w[i*2+1])
59 where sf(.) and cdf(.) are w.r.t. the normalized gaussian distribution
60 b[i][1] = f(b[i][0]), the estimated error
61 Requirement:
62 mu[i*2] <= mu[i*2+1] for all i = 0..N-1
63 """
64 tprint("Warning, this function is now obsolete. Please use sdGTSolve() instead")
65 N = stats2e.J / 2
66 A = stats2e.A
67 b = zeros([N,2])
68 ld = float(thelambda)
69 gaussian_find_classification_threshold(N,A,b,ld)
70 return b
71
73 """Use the thresholded classifier as above. If we wish detection rate >= minDR, what is the largest threshold?
74
75 Input:
76 stats2e: per-element statistics of 2*N classes
77 minDR: the value of 'minDR'
78 Output:
79 b: a numpy.array of shape (N,2) to hold the results where
80 b[i][0]: a threshold that
81 minimize FAR(b) = sf((b-mu[i*2])/sigma[i*2])
82 w.r.t. b
83 subject to DR(b) = sf((b-mu[i*2+1])/sigma[i*2+1]) >= minDR
84 where sf(.) is w.r.t. the normalized gaussian distribution
85 b[i][1] = FAR(b[i][0]), the estimated false acceptance rate
86 Requirement:
87 mu[i*2] <= mu[i*2+1] for all i = 0..N-1
88 """
89 tprint("Warning, this function is now obsolete. Please use sdGTSolve() instead")
90 b0 = stdnorm.isf(minDR)
91 N = stats2e.J / 2
92 A = stats2e.A.reshape(N,6)
93 b = zeros([N,2])
94 b[:,0] = A[:,5]*b0 + A[:,4]
95 b[:,1] = stdnorm.sf((b[:,0]-A[:,1])/A[:,2])
96 return b
97
99 """Use the thresholded classifier as above. If we wish false acceptance rate <= maxFAR, what is the smallest threshold?
100
101 Input:
102 stats2e: per-element statistics of 2*N classes
103 maxFAR: the value of 'maxFAR'
104 Output:
105 b: a numpy.array of shape (N,2) to hold the results where
106 b[i][0]: a threshold that
107 maximize DR(b) = sf((b-mu[i*2+1])/sigma[i*2+1])
108 w.r.t. b
109 subject to FAR(b) = sf((b-mu[i*2])/sigma[i*2]) <= maxFAR
110 where sf(.) is w.r.t. the normalized gaussian distribution
111 b[i][1] = 1-DR(b[i][0]), the estimated false rejection rate
112 Requirement:
113 mu[i*2] <= mu[i*2+1] for all i = 0..N-1
114 """
115 tprint("Warning, this function is now obsolete. Please use sdGTSolve() instead")
116 b0 = stdnorm.isf(maxFAR)
117 N = stats2e.J / 2
118 A = stats2e.A.reshape(N,6)
119 b = zeros([N,2])
120 b[:,0] = A[:,2]*b0 + A[:,1]
121 b[:,1] = stdnorm.cdf((b[:,0]-A[:,4])/A[:,5])
122 return b
123
125 class Test:
126 pass
127
128 a = zeros([4,3])
129 a[0,0] = 1
130 a[0,1] = 1
131 a[0,2] = 1
132 a[1,0] = 1
133 a[1,1] = 2
134 a[1,2] = 1
135 a[2,0] = 10
136 a[2,1] = 10
137 a[2,2] = 10
138 a[3,0] = 10
139 a[3,1] = 20
140 a[3,2] = 10
141 b = Test()
142 b.J = 4
143 b.A = a
144 return a, b, find_filtering_threshold2(b,0.01)
145
146 if __name__ == '__main__':
147 main()
148