1 | NameBlock ROC = |
---|
2 | [[ |
---|
3 | Set _.interp.Set = SetOfText("linear", "cspline", "akima"); |
---|
4 | Set _.slice.Set = Range(0, 1, 0.02); |
---|
5 | |
---|
6 | Set _Interp |
---|
7 | ( |
---|
8 | Set xSet, // Set xSet with we want to know y for all funSet |
---|
9 | Set setFunSet, // Set of tables with same structure SetOfReal(x, y) |
---|
10 | Set interpSet // Set with gsl valid interpolate method (see gsl_interp) |
---|
11 | ) |
---|
12 | { |
---|
13 | Set setxyFunSet = EvalSet(setFunSet, Set(Set funSet) |
---|
14 | { |
---|
15 | SetOfMatrix(SetCol(Traspose(funSet)[1]), SetCol(Traspose(funSet)[2])) |
---|
16 | }); |
---|
17 | |
---|
18 | EvalSet(xSet, Set(Real x) |
---|
19 | { |
---|
20 | Set ySet = EvalSet(setxyFunSet, Real(Set xyFunSet) |
---|
21 | { |
---|
22 | Matrix xFunSet = xyFunSet[1]; |
---|
23 | Matrix yFunSet = xyFunSet[2]; |
---|
24 | |
---|
25 | Set ySetAux = EvalSet(interpSet, Real(Text code) |
---|
26 | { |
---|
27 | Code gslInterp = gsl_interp(code, xFunSet, yFunSet); |
---|
28 | gslInterp(0, x) |
---|
29 | }); |
---|
30 | SetAvr(ySetAux) |
---|
31 | }); |
---|
32 | SetOfReal(x)<<ySet |
---|
33 | }) |
---|
34 | }; |
---|
35 | |
---|
36 | Set Curve(Matrix y, Matrix py_, Real numQ) |
---|
37 | { |
---|
38 | Matrix py = Min(Max(py_, 0), 1); |
---|
39 | Set index = Range(1, 0, -1/Min(Max(numQ, 2), Rows(py)-1)); |
---|
40 | Set graf = [[ [[ 0, 0, 0 ]] ]] << EvalSet(index, Set(Real q) |
---|
41 | { |
---|
42 | Real slice = MatQuantile(py, q); |
---|
43 | Matrix yEst = GE(py, Rand(Rows(py), 1 , slice, slice)); |
---|
44 | Real VP = MatSum(And(yEst, y)); |
---|
45 | Real FN = MatSum(And(Not(yEst), y)); |
---|
46 | Real VN = MatSum(And(Not(yEst), Not(y))); |
---|
47 | Real FP = MatSum(And(yEst, Not(y))); |
---|
48 | |
---|
49 | Real TVP = VP/(VP+FN); |
---|
50 | Real TFP = 1-VN/(VN+FP);//=FP/(VN+FP) |
---|
51 | SetOfReal(TFP, TVP, slice) |
---|
52 | }) |
---|
53 | }; |
---|
54 | |
---|
55 | Set Curve.Abs |
---|
56 | ( |
---|
57 | Set ROCSet, // Table with reg = SetOfReal(TFP, TVP, slice, ...) |
---|
58 | Real M, // Total |
---|
59 | Real m // Infected |
---|
60 | ) |
---|
61 | { |
---|
62 | Real p = m/(M-m); |
---|
63 | EvalSet(ROCSet, Set(Set reg) |
---|
64 | { |
---|
65 | Real TFP = reg[1]; |
---|
66 | Real TVP = reg[2]; |
---|
67 | Real slice = reg[3]; |
---|
68 | Real infected = TVP*m; |
---|
69 | Real population = (p*TVP+TFP)*M/(1+p); |
---|
70 | SetOfReal(TFP, TVP, population, infected, slice) |
---|
71 | }) |
---|
72 | }; |
---|
73 | |
---|
74 | Set Eval.TFPSet(Set tfpSet, Set ROCSet) |
---|
75 | { |
---|
76 | Set tROCSet = Traspose(ROCSet); |
---|
77 | Set txFP = tROCSet[1]; |
---|
78 | Set txVP = tROCSet[2]; |
---|
79 | Set txSL = tROCSet[3]; |
---|
80 | |
---|
81 | Set setFunSet = SetOfSet |
---|
82 | ( |
---|
83 | Traspose(SetOfSet(txFP, txVP)), |
---|
84 | Traspose(SetOfSet(txFP, txSL)) |
---|
85 | ); |
---|
86 | _Interp(tfpSet, setFunSet, _.interp.Set) |
---|
87 | }; |
---|
88 | |
---|
89 | Set EvalAbs.PopSet(Set popSet, Set ROCAbsSet) |
---|
90 | { |
---|
91 | Set tROCSet = Traspose(ROCAbsSet); |
---|
92 | Set txPop = tROCSet[3]; |
---|
93 | Set txInf = tROCSet[4]; |
---|
94 | Set txSL = tROCSet[5]; |
---|
95 | |
---|
96 | Set setFunSet = SetOfSet |
---|
97 | ( |
---|
98 | Traspose(SetOfSet(txPop, txInf)), |
---|
99 | Traspose(SetOfSet(txPop, txSL)) |
---|
100 | ); |
---|
101 | _Interp(popSet, setFunSet, _.interp.Set) |
---|
102 | }; |
---|
103 | |
---|
104 | Real Get.Area(Set ROCSet) |
---|
105 | { |
---|
106 | Set txFP = Traspose(ROCSet)[1]; |
---|
107 | Set txVP = Traspose(ROCSet)[2]; |
---|
108 | Set setFunSet = SetOfSet( Traspose(SetOfSet(txFP, txVP)) ); |
---|
109 | Real get.tvp(Real tfp) |
---|
110 | { |
---|
111 | Set tfpSet = SetOfReal(tfp); |
---|
112 | Real tvp = _Interp(tfpSet, setFunSet, _.interp.Set)[1][2]; |
---|
113 | tvp |
---|
114 | }; |
---|
115 | IntegrateQAG(get.tvp, 0, 1) |
---|
116 | }; |
---|
117 | |
---|
118 | Real Get.AreaTrap(Set xySet) |
---|
119 | { |
---|
120 | Real auc = 0; |
---|
121 | Real k = 2; |
---|
122 | Real While(LE(k,Card(xySet)), |
---|
123 | { |
---|
124 | Real xk = xySet[k][1]; |
---|
125 | Real xk_1 = xySet[k-1][1]; |
---|
126 | |
---|
127 | Real yk = xySet[k][2]; |
---|
128 | Real yk_1 = xySet[k-1][2]; |
---|
129 | |
---|
130 | Real auc:= (xk-xk_1)*(yk+yk_1)/2 + auc; |
---|
131 | Real k := k+1 |
---|
132 | }); |
---|
133 | auc |
---|
134 | }; |
---|
135 | |
---|
136 | Real Get.AreaFull(Set ROCSet) |
---|
137 | { |
---|
138 | Set txFP = Traspose(ROCSet)[1]; |
---|
139 | Set txVP = Traspose(ROCSet)[2]; |
---|
140 | Set setFunSet = SetOfSet( Traspose(SetOfSet(txFP, txVP)) ); |
---|
141 | Real get.tvp(Real tfp) |
---|
142 | { |
---|
143 | Set tfpSet = SetOfReal(tfp); |
---|
144 | Real tvp = _Interp(tfpSet, setFunSet, _.interp.Set)[1][2]; |
---|
145 | tvp |
---|
146 | }; |
---|
147 | IntegrateQAG(get.tvp, 0, 1) |
---|
148 | } |
---|
149 | ]]; |
---|