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

Ticket #1134: To_Interpolacion.tol

File To_Interpolacion.tol, 3.7 KB (added by Chakib Faghloumi, 11 years ago)

Funcion de interpolación

Line 
1
2Set Dates.(NameBlock arg)
3{
4  @Serie _.serie_ = [[ arg::_.serie ]],
5  @Date _.ini_  = [[ getOptArg(arg, "_.ini", First($_.serie_)) ]];
6  @Date _.end_  = [[ getOptArg(arg, "_.end", Last($_.serie_))  ]];
7  Real zeroIsData    = getOptArg(arg, "_.zeroIsData", 1);
8 
9  Set dates1 = Dates(Dating($_.serie_), $_.ini_, $_.end_);
10  Set dates = SetConcat(EvalSet(dates1, Set(Date d)
11  {
12    Case(
13      IsUnknown(SerDat($_.serie_, d)), Copy(Empty),
14      SerDat($_.serie_, d)==0 & !zeroIsData, Copy(Empty),
15      1, [[ d ]]
16    )
17  }))
18};
19Anything PutDescription("
20  Saca el set de fechas de una serie _.serie donde esta definida"+NL+
21  "NameBlock  arg = [["+NL+
22  " Serie _.serie = serie,//Obligatorio"+NL+
23  " Date _.ini = desde,  //Opcional"+NL+
24  " Date _.ini = hasta   //Opcional"+NL+
25  " Real _.zeroIsData = zeroIsData//Opcional"+NL+
26  "]]"+NL+
27  "Por defecto:"+NL+
28  " Date _.ini = First(_.serie),"+NL+
29  " Date _.ini = Last(_.serie) ,"+NL+
30  " Real _.zeroIsData = 1."+NL+NL+
31  "Real _.zeroIsData = 1 -> considerar los 0 de la serie como dato. "+NL+
32  "Real _.zeroIsData = 0 -> no considerar los 0 de la serie como dato. ",
33  Dates.
34);
35
36
37Set InterpolaSer.(NameBlock arg)
38{
39  @Serie _.serie_ = [[ arg::_.serie ]];
40  Text _.tms_ =  getOptArg(arg, "_.tms", DatingName($_.serie_));
41  Text method_    = getOptArg(arg, "_.method", "linear" );
42  Real zeroIsData    = getOptArg(arg, "_.zeroIsData", 1);
43  Text name_ = Name($_.serie_);
44  Text name = ToTolName(If(name_=="", "Ser", name_)+Name(Dating($_.serie_)));
45//  @TimeSet tmsOri = [[ Dating(ser) ]];
46  @Date ini = [[ First($_.serie_) ]];
47  @Date fin = [[ Last($_.serie_)  ]];
48  Set dates_ =  Dates.(arg);
49  @Matrix x = SetOfMatrix( SetRow(EvalSet(dates_, DateToIndex)) );
50  @Matrix y = SetOfMatrix(SetRow(EvalSet(dates_, Real(Date d){SerDat($_.serie_, d)})));
51  Set indexTms = EvalSet(Dates(Eval("TimeSet "+_.tms_), $ini, $fin), DateToIndex);
52  @Matrix xTms = SetOfMatrix( SetRow(indexTms) );
53  Code c = gsl_interp(method_, $x, $y);
54  @Matrix yTms = SetOfMatrix( SetRow(EvalSet(indexTms, Real(Real t) { c(0,t) })) );
55  Set setSerInterpolate = MatSerSet($yTms, Eval("TimeSet "+_.tms_), $ini)
56};
57Anything PutDescription("
58  Interpola la serie _.serie en las fechas donde no esta definida"+NL+
59  "NameBlock  arg = [["+NL+
60  " Serie _.serie = serie,         //Obligatorio"+NL+
61  " Text _.tms = tms,              //Opcional"+NL+
62  " Text _.method = met            //Opcional"+NL+
63  " Real _.zeroIsData = zeroIsData //Opcional"+NL+
64  "]]"+NL+
65  "Por defecto:"+NL+
66  " Text _.tms = DatingName(_.serie),"+NL+
67  " Text _.method = linear ,"+NL+
68  " Real _.zeroIsData = 1"+NL+NL+
69  "Real _.zeroIsData = 1 -> considerar los 0 de la serie como dato. "+NL+
70  "Real _.zeroIsData = 0 -> no considerar los 0 de la serie como dato. "+NL+
71  "Los metodos que se admite son  los mismos de la funcón gsl_interp: "+NL+
72  "  linear, polynomial, cspline, cspline_periodic, akima, akima_periodic",
73  InterpolaSer.
74);
75
76
77Serie InterpolaSer(NameBlock arg)
78{
79 Serie  InterpolaSer.(arg)[1]
80};
81
82/*
83Date ini1 = y2000;
84Date fin1 = y2010;
85
86Date ini2 = y2005;
87Date fin2 = y2020;
88
89Serie ori_ori = SubSer(Gaussian(10, 0.5, Mensual), ini1, fin1);
90
91Serie ori = Copy(ori_ori);
92
93Set datS = Dates(Mensual, ini1, fin1);
94
95Set Omit = Unique(For(1, 12, Real(Real n)
96{
97  Real rand = Rand(2, Card(datS));
98  Real randInteger = Floor(rand);
99  PutSerDat(ori, datS[ randInteger ],  ?)
100
101}));
102
103
104Serie prev = SubSer(Gaussian(20, 0.5, Trimestral), ini2, fin2);
105
106Serie foreMes = F:DatCh(B:prev, Mensual, FirstS);
107
108Serie concat = Concat(
109 ori,
110 foreMes,
111 Last(ori)
112);
113
114
115Serie concat_Interpola = InterpolaSer(NameBlock [[ Serie _.serie = concat, Real _.zeroIsData = 0   ]])
116*/
117
118
119
120
121