close Warning: Can't synchronize with repository "(default)" (/var/svn/tolp does not appear to be a Subversion repository.). Look in the Trac log for more information.

Ticket #152: estimation.tol

File estimation.tol, 5.8 KB (added by manuelb, 21 years ago)

TOL source file to test this issue

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