| 1 | NameBlock ROC = |
|---|
| 2 | [[ |
|---|
| 3 | Set _.interp.Set = SetOfText("linear", "akima", "cspline"); |
|---|
| 4 | |
|---|
| 5 | Set _Interp |
|---|
| 6 | ( |
|---|
| 7 | Set xSet, // Set xSet with we want to know y for all funSet |
|---|
| 8 | Set setFunSet, // Set of tables with same structure SetOfReal(x, y) |
|---|
| 9 | Set interpSet // Set with gsl valid interpolate method (see gsl_interp) |
|---|
| 10 | ) |
|---|
| 11 | { |
|---|
| 12 | Set setxyFunSet = EvalSet(setFunSet, Set(Set funSet) |
|---|
| 13 | { |
|---|
| 14 | SetOfMatrix(SetCol(Traspose(funSet)[1]), SetCol(Traspose(funSet)[2])) |
|---|
| 15 | }); |
|---|
| 16 | |
|---|
| 17 | EvalSet(xSet, Set(Real x) |
|---|
| 18 | { |
|---|
| 19 | Set ySet = EvalSet(setxyFunSet, Real(Set xyFunSet) |
|---|
| 20 | { |
|---|
| 21 | Matrix xFunSet = xyFunSet[1]; |
|---|
| 22 | Matrix yFunSet = xyFunSet[2]; |
|---|
| 23 | |
|---|
| 24 | Set ySet = EvalSet(interpSet, Real(Text code) |
|---|
| 25 | { |
|---|
| 26 | Code gslInterp = gsl_interp(code, xFunSet, yFunSet); |
|---|
| 27 | gslInterp(0, x) |
|---|
| 28 | }); |
|---|
| 29 | SetAvr(ySet) |
|---|
| 30 | }); |
|---|
| 31 | SetOfReal(x)<<ySet |
|---|
| 32 | }) |
|---|
| 33 | }; |
|---|
| 34 | |
|---|
| 35 | Set Curve(Matrix y, Matrix py, Set sliceSet) |
|---|
| 36 | { |
|---|
| 37 | Set graf = EvalSet(sliceSet, Set(Real slice) |
|---|
| 38 | { |
|---|
| 39 | Matrix yEst = GE(py, Rand(Rows(py), 1 , slice, slice)); |
|---|
| 40 | Real VP = MatSum(And(yEst, y)); |
|---|
| 41 | Real FN = MatSum(And(Not(yEst), y)); |
|---|
| 42 | Real VN = MatSum(And(Not(yEst), Not(y))); |
|---|
| 43 | Real FP = MatSum(And(yEst, Not(y))); |
|---|
| 44 | |
|---|
| 45 | Real TVP = VP/(VP+FN); |
|---|
| 46 | Real TFP = 1-VN/(VN+FP);//=FP/(VN+FP) |
|---|
| 47 | SetOfReal(TFP, TVP, slice) |
|---|
| 48 | }); |
|---|
| 49 | Set claTFP = Classify(graf, Real(Set reg1, Set reg2) |
|---|
| 50 | { |
|---|
| 51 | Real tfp1 = reg1[1]; |
|---|
| 52 | Real tfp2 = reg2[1]; |
|---|
| 53 | Compare(tfp1, tfp2) |
|---|
| 54 | }); |
|---|
| 55 | EvalSet(claTFP, Set(Set class) |
|---|
| 56 | { |
|---|
| 57 | Real maxTvp = SetMax(Traspose(class)[2]); |
|---|
| 58 | Select(class, Real(Set reg){EQ(reg[2], maxTvp)})[1] |
|---|
| 59 | }) |
|---|
| 60 | }; |
|---|
| 61 | |
|---|
| 62 | Set Curve.Abs |
|---|
| 63 | ( |
|---|
| 64 | Set ROCSet, // Table with reg = SetOfReal(TFP, TVP, slice, ...) |
|---|
| 65 | Real M, // Total |
|---|
| 66 | Real m // Infected |
|---|
| 67 | ) |
|---|
| 68 | { |
|---|
| 69 | Real p = m/(M-m); |
|---|
| 70 | EvalSet(ROCSet, Set(Set reg) |
|---|
| 71 | { |
|---|
| 72 | Real TFP = reg[1]; |
|---|
| 73 | Real TVP = reg[2]; |
|---|
| 74 | Real slice = reg[3]; |
|---|
| 75 | Real infected = TVP*m; |
|---|
| 76 | Real population = (p*TVP+TFP)*M/(1+p); |
|---|
| 77 | SetOfReal(TFP, TVP, population, infected, slice) |
|---|
| 78 | }) |
|---|
| 79 | }; |
|---|
| 80 | |
|---|
| 81 | Set Eval.TFPSet(Set tfpSet, Set ROCSet) |
|---|
| 82 | { |
|---|
| 83 | Set tROCSet = Traspose(ROCSet); |
|---|
| 84 | Set txFP = tROCSet[1]; |
|---|
| 85 | Set txVP = tROCSet[2]; |
|---|
| 86 | Set txSL = tROCSet[3]; |
|---|
| 87 | |
|---|
| 88 | Set setFunSet = SetOfSet |
|---|
| 89 | ( |
|---|
| 90 | Traspose(SetOfSet(txFP, txVP)), |
|---|
| 91 | Traspose(SetOfSet(txFP, txSL)) |
|---|
| 92 | ); |
|---|
| 93 | _Interp(tfpSet, setFunSet, _.interp.Set) |
|---|
| 94 | }; |
|---|
| 95 | |
|---|
| 96 | Set EvalAbs.PopSet(Set popSet, Set ROCAbsSet) |
|---|
| 97 | { |
|---|
| 98 | Set tROCSet = Traspose(ROCAbsSet); |
|---|
| 99 | Set txPop = tROCSet[3]; |
|---|
| 100 | Set txInf = tROCSet[4]; |
|---|
| 101 | Set txSL = tROCSet[5]; |
|---|
| 102 | |
|---|
| 103 | Set setFunSet = SetOfSet |
|---|
| 104 | ( |
|---|
| 105 | Traspose(SetOfSet(txPop, txInf)), |
|---|
| 106 | Traspose(SetOfSet(txPop, txSL)) |
|---|
| 107 | ); |
|---|
| 108 | _Interp(popSet, setFunSet, _.interp.Set) |
|---|
| 109 | }; |
|---|
| 110 | |
|---|
| 111 | Real Get.Area(Set ROCSet) |
|---|
| 112 | { |
|---|
| 113 | Set txFP = Traspose(ROCSet)[1]; |
|---|
| 114 | Set txVP = Traspose(ROCSet)[2]; |
|---|
| 115 | Set setFunSet = SetOfSet( Traspose(SetOfSet(txFP, txVP)) ); |
|---|
| 116 | Real get.tvp(Real tfp) |
|---|
| 117 | { |
|---|
| 118 | Set tfpSet = SetOfReal(tfp); |
|---|
| 119 | Real tvp = _Interp(tfpSet, setFunSet, _.interp.Set)[1][2]; |
|---|
| 120 | tvp |
|---|
| 121 | }; |
|---|
| 122 | IntegrateQAG(get.tvp, 0, 1) |
|---|
| 123 | } |
|---|
| 124 | ]]; |
|---|