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