| 1 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | // FILE : estimation.tol |
|---|
| 3 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 4 | WriteLn("file : estimation.tol... "+ Time); |
|---|
| 5 | |
|---|
| 6 | Text PathOutCome.cmd = "outcome"; |
|---|
| 7 | Text PathOutCome = PathOutCome.cmd +"/"; |
|---|
| 8 | Real System("mkdir "+ PathOutCome.cmd); |
|---|
| 9 | Text PutDumpFile(PathOutCome +"estimation.log"); |
|---|
| 10 | |
|---|
| 11 | Real SecondsIni = Copy(Time); |
|---|
| 12 | |
|---|
| 13 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 14 | // ESTIMATION CONSTANTS |
|---|
| 15 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 16 | WriteLn("estimation constants... "+ Time); |
|---|
| 17 | |
|---|
| 18 | Real NumTolerance = 4; |
|---|
| 19 | Text NewFormatReal = "%6.10lf"; |
|---|
| 20 | Text OldFormatReal = PutRealFormat(NewFormatReal); |
|---|
| 21 | Real (Tolerance := 5*(10^(-NumTolerance))); |
|---|
| 22 | Real (RelativeTolerance := 10^(-(NumTolerance+1))); |
|---|
| 23 | Real (DiffDist := 0.00001); |
|---|
| 24 | Real (MarqFactor := 2); |
|---|
| 25 | //Real (MinOutlierLikelyhood := 4); |
|---|
| 26 | Real (MarqLinMet := Copy(Choleski)); |
|---|
| 27 | Real (MaxIter := 85); |
|---|
| 28 | Real (DoStatistics := 0); |
|---|
| 29 | Real (DoDiagnostics := 0); |
|---|
| 30 | Real (NullInitResiduals := 0); |
|---|
| 31 | |
|---|
| 32 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 33 | // PATH |
|---|
| 34 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 35 | WriteLn("path... "+ Time); |
|---|
| 36 | |
|---|
| 37 | Text PathOutputSr = "output.bdt"; |
|---|
| 38 | Text PathParEst = "parest.bst"; |
|---|
| 39 | Text PathInputSr = "input.bdt"; |
|---|
| 40 | Text PathInputBst = "input.bst"; |
|---|
| 41 | |
|---|
| 42 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 43 | // STRUCT |
|---|
| 44 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 45 | WriteLn("struct... "+ Time); |
|---|
| 46 | |
|---|
| 47 | Struct ParEstSt |
|---|
| 48 | ( |
|---|
| 49 | Real FstTransfor, |
|---|
| 50 | Real SndTransfor, |
|---|
| 51 | Real Period, |
|---|
| 52 | Real Constant, |
|---|
| 53 | Polyn Dif, |
|---|
| 54 | Set AR, |
|---|
| 55 | Set MA |
|---|
| 56 | ); |
|---|
| 57 | |
|---|
| 58 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 59 | // INCLUDES |
|---|
| 60 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 61 | WriteLn(" |
|---|
| 62 | includes... "+ Time); |
|---|
| 63 | |
|---|
| 64 | Set OutputSr = Include(PathOutputSr); |
|---|
| 65 | Text ParEstBstTxt = ReadFile(PathParEst); |
|---|
| 66 | Text ParEstBstTxt.SP = WriteFile(PathParEst, |
|---|
| 67 | ReplaceTable(ParEstBstTxt, [[ [[ "[[", "SetOfPolyn(" ]], |
|---|
| 68 | [[ "]]", ")" ]] ]])); |
|---|
| 69 | Set ParEstBst = Include(PathParEst)[1]; |
|---|
| 70 | Set InputSr = Include(PathInputSr); |
|---|
| 71 | Set InputBst = Include(PathInputBst); |
|---|
| 72 | |
|---|
| 73 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 74 | // ESTIMATION PARAM |
|---|
| 75 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 76 | WriteLn(" |
|---|
| 77 | estimation param... "+ Time); |
|---|
| 78 | |
|---|
| 79 | Real FstTransfor.M = ParEstBst->FstTransfor; |
|---|
| 80 | Real SndTransfor.M = ParEstBst->SndTransfor; |
|---|
| 81 | Real Period.M = ParEstBst->Period; |
|---|
| 82 | Real Constant.M = ParEstBst->Constant; |
|---|
| 83 | Polyn Dif.M = ParEstBst->Dif; |
|---|
| 84 | Set AR.M = ParEstBst->AR; |
|---|
| 85 | Set MA.M = ParEstBst->MA; |
|---|
| 86 | Polyn ARI.M = Dif.M * BinGroup("*", AR.M); |
|---|
| 87 | |
|---|
| 88 | Set Input2Est = EvalSet(InputBst, Set(Set inp) |
|---|
| 89 | { |
|---|
| 90 | InputDef(inp->Omega, Eval( (inp->X) +";")) |
|---|
| 91 | }); |
|---|
| 92 | |
|---|
| 93 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 94 | // MODEL DEF |
|---|
| 95 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 96 | WriteLn(" |
|---|
| 97 | model def... "+ Time); |
|---|
| 98 | |
|---|
| 99 | Set ModeloInicial = ModelDef( |
|---|
| 100 | Output, |
|---|
| 101 | FstTransfor.M, |
|---|
| 102 | SndTransfor.M, |
|---|
| 103 | Period.M, |
|---|
| 104 | Constant.M, |
|---|
| 105 | Dif.M, |
|---|
| 106 | AR.M, |
|---|
| 107 | MA.M, |
|---|
| 108 | Input2Est, |
|---|
| 109 | AllLinear |
|---|
| 110 | ); |
|---|
| 111 | |
|---|
| 112 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 113 | // MODEL ESTIMATION |
|---|
| 114 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 115 | WriteLn(" |
|---|
| 116 | model estimation... "+ Time); |
|---|
| 117 | |
|---|
| 118 | Date IniOutput = First(Output); |
|---|
| 119 | Date IniEstim = If(TheBegin != IniOutput, |
|---|
| 120 | Max(IniOutput, TheBegin), |
|---|
| 121 | Succ(IniOutput, Dating(Output), Degree(ARI.M))); |
|---|
| 122 | Date EndOutput = Last(Output); |
|---|
| 123 | Date EndEstim = If(y2004m08d23 != EndOutput, |
|---|
| 124 | Min(EndOutput, y2004m08d23), |
|---|
| 125 | EndOutput); |
|---|
| 126 | Set ModeloEstimado = Estimate(ModeloInicial, IniEstim, EndEstim); |
|---|
| 127 | |
|---|
| 128 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 129 | // SAVE RESULTS |
|---|
| 130 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 131 | WriteLn(" |
|---|
| 132 | save results... "+ Time); |
|---|
| 133 | |
|---|
| 134 | Set SeriesEst = ExtractByIndex(ModeloEstimado[3], Range(1,8,1)); |
|---|
| 135 | Set BSIFile(SeriesEst, PathOutCome +"series.bsi"); |
|---|
| 136 | Set ParametersEst = ModeloEstimado[4]; |
|---|
| 137 | Set BSTFile(ParametersEst, PathOutCome +"paramest.bst"); |
|---|
| 138 | |
|---|
| 139 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 140 | // END INPUTS ESTIMATION |
|---|
| 141 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 142 | WriteLn(" |
|---|
| 143 | end inputs estimation... "+ Time); |
|---|
| 144 | |
|---|
| 145 | Real SecondsEnd = Copy(Time); |
|---|
| 146 | WriteLn("FIN DE LA ESTIMACION CON INPUTS"); |
|---|
| 147 | WriteLn(SecondsToText(SecondsEnd - SecondsIni)); |
|---|
| 148 | |
|---|
| 149 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 150 | // NOISE ESTIMATION |
|---|
| 151 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 152 | WriteLn(" |
|---|
| 153 | noise estimation... "+ Time); |
|---|
| 154 | |
|---|
| 155 | Serie NoiseEst = ModeloEstimado[3][3]; |
|---|
| 156 | Set ModeloInicial.Noi = ModelDef( |
|---|
| 157 | NoiseEst, |
|---|
| 158 | 1, |
|---|
| 159 | 0, |
|---|
| 160 | Period.M, |
|---|
| 161 | Constant.M, |
|---|
| 162 | Dif.M, |
|---|
| 163 | AR.M, |
|---|
| 164 | MA.M, |
|---|
| 165 | Empty, |
|---|
| 166 | AllLinear |
|---|
| 167 | ); |
|---|
| 168 | Set ModeloEstimado.Noi = Estimate(ModeloInicial.Noi, IniEstim, |
|---|
| 169 | EndOutput); |
|---|
| 170 | |
|---|
| 171 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 172 | // SAVE RESULTS NOISE |
|---|
| 173 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 174 | WriteLn(" |
|---|
| 175 | save results noise... "+ Time); |
|---|
| 176 | |
|---|
| 177 | Set SeriesEst.Noi = ExtractByIndex(ModeloEstimado.Noi[3], |
|---|
| 178 | Range(1,8,1)); |
|---|
| 179 | Set BSIFile(SeriesEst.Noi, PathOutCome +"series_noi.bsi"); |
|---|
| 180 | Set ParametersEst.Noi = ModeloEstimado.Noi[4]; |
|---|
| 181 | Set BSTFile(ParametersEst.Noi, PathOutCome +"paramest_noi.bst"); |
|---|
| 182 | |
|---|
| 183 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 184 | // END NOISE ESTIMATION |
|---|
| 185 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 186 | WriteLn(" |
|---|
| 187 | end noise estimation... "+ Time); |
|---|
| 188 | |
|---|
| 189 | Real SecondsEnd.Noi = Copy(Time); |
|---|
| 190 | WriteLn("FIN DE LA ESTIMACION DEL NOISE"); |
|---|
| 191 | WriteLn(SecondsToText(SecondsEnd.Noi - SecondsIni)); |
|---|
| 192 | |
|---|