Changeset e9e4854 in tol


Ignore:
Timestamp:
Apr 15, 2011, 10:02:11 AM (16 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
fcb7cd1
Parents:
84be16b
Message:

Fixes #1167

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@3451 be4846ae-f051-483a-831f-b64e7d08527f

Location:
tol
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/bmodel/estim.cpp

    r84be16b re9e4854  
    900900}
    901901
    902 
     902/*
    903903//--------------------------------------------------------------------
    904904DeclareContensClass(BPol, BPolTemporary, BPolAutoReg);
    … …  
    926926}
    927927
    928 
     928/*
    929929//--------------------------------------------------------------------
    930930DeclareContensClass(BSet, BSetTemporary, BSetAutoRegInt);
    … …  
    952952  );
    953953}
    954 
     954*/
    955955
    956956
  • tol/stdlib/gui/html/_htmlmethods.tol

    r84be16b re9e4854  
    376376
    377377//////////////////////////////////////////////////////////////////////////////
    378    Text HtmlLinReg(Set series)
    379 
    380 // PURPOSE: Creates an HTML text width a linear regression report of series
    381 //
    382 //////////////////////////////////////////////////////////////////////////////
    383 {
    384   Real n = Card(series);
    385   If
    386   (
    387     n<2,
    388     {
    389       WriteLn("Error: Son necesarias al menos dos series para calcular "+
    390               "la regresión lineal.");
    391       "Número de series = " + IntText(n)
    392     },
    393     {
    394       HtmlLinearRegression(series, Periodicity(series[1]))
    395     }
    396   )
    397 };
    398 
    399 
    400 //////////////////////////////////////////////////////////////////////////////
    401378  Text HtmlAutoReg(Set  series,
    402379                   Real periodicidad,
    … …  
    592569  @SeriesMethodStruct("Componentes" , Copy(HtmlSeriesComponents), Empty);
    593570
    594 Set LinRegMet =
    595   @SeriesMethodStruct("Regresión lineal" , Copy(HtmlLinReg), Empty);
    596 
    597571
    598572//////////////////////////////////////////////////////////////////////////////
  • tol/stdlib/gui/html/_htmlutil.tol

    r84be16b re9e4854  
    235235
    236236
    237 
    238 //////////////////////////////////////////////////////////////////////////////
    239    Text HtmlLinearRegression(Set ser, Real period)
    240 
    241 // PURPOSE: Creates an HTML text width a linear regression report of series
    242 //
    243 //////////////////////////////////////////////////////////////////////////////
    244 {
    245   Text old = PutEditor("");
    246  
    247   Text tmpDir = Replace(TmpDir,"\\","/");
    248 
    249   Text rand = FormatReal(Rand(0,99999999),"%0.lf");
    250 
    251   Text outputName = Identify(ser[1]);
    252 
    253   Serie output = ser[1];
    254 
    255   Text CreaInputExpresion(Real n, Real k)
    256   {
    257     Text name = Identify(ser[n]);
    258     Text expr = "(B^"+k+"):("+name+");";
    259     expr
    260   };   
    261   Set    ARIEst = AutoRegInt(output, period);
    262   Polyn  DIF    = ARIEst[1];
    263   Polyn  AR     = ARIEst[2];
    264   Polyn  ARI    = DIF*AR;
    265   Real degree   = Degree(ARI)-1;
    266 
    267   Set  inputBackNames = For
    268   (
    269     1,
    270     Card(ser),
    271     Set s(Real n)
    272     {
    273       If
    274       (
    275         n==1,
    276         For(1, degree, Text(Real k) { CreaInputExpresion(n,k) } ),
    277         For(0, 2,      Text(Real k) { CreaInputExpresion(n,k) } )
    278       )
    279     }
    280   );
    281   Set idSet = SetConcat(inputBackNames);
    282   Set input = EvalSet(idSet, Serie (Text expr) { Eval(expr) } );
    283 
    284   Real n = Card(input);
    285 
    286   Set lr = LinearRegression
    287   (
    288     output,
    289     input
    290   );
    291 
    292  
    293   Set param = lr[2];
    294   Set ParInf =
    295   {
    296     Set For
    297     (
    298       1,n,
    299       Set linePar(Real i)
    300       {
    301         Text id = idSet[i]; 
    302         Set p1 = param[i];
    303         Set p2 = SetOfReal(p1[2],p1[3],p1[4],p1[5]);
    304         [[id]] + p2
    305       }
    306     )
    307   };
    308  
    309   Set ExprInf =
    310   {
    311     Set For
    312     (
    313       1,n,
    314       Text lineExpr(Real i)
    315       {
    316         Real j = n-i+1;
    317         Text id = idSet[j]; 
    318         Set p1 = param[j];
    319         Real coef = p1[2];
    320         Real aCoef = Abs(coef);
    321         Text sig = If(coef>0, "+",  "-");
    322         NL + "    " + sig + aCoef + "*" + id
    323       }
    324     )
    325   };
    326 
    327   Real outStd = StDsS(output);
    328   Set  info   = lr[3];
    329   Real err    = info[5];
    330   Real sw     = info[6]*2;
    331   Text expression = "Est" + outputName + " = " +
    332                     Text (SetSum( ExprInf)) +
    333                     NL + "    + Gaussian(0," + err +")";
    334 
    335   Text InfoFile =
    336   {
    337     Text txt =
    338       "Concepto;"                         + "Valor"  + ";" + NL +
    339       "Fecha inicial;"                    + info[ 1] + ";" + NL +
    340       "Fecha final;"                      + info[ 2] + ";" + NL +
    341       "Número de datos;"                  + info[ 3] + ";" + NL +
    342       "Número de variables;"              + info[ 4] + ";" + NL +
    343       "Error estandar de "+outputName+";" + outStd   + ";" + NL +
    344       "Error estandar de los residuos;"   + err      + ";" + NL +
    345       "Inform. Swartz;"                   + sw       + ";" + NL +
    346       "F de Snedecor;"                    + info[10] + ";" + NL +
    347       "Alfa;"                             + info[11] + ";" + NL;
    348     WriteFile(tmpDir + "/Info"+rand+".txt", txt)
    349   };
    350  
    351   Text ParFile =
    352   {
    353     Text pFile = tmpDir + "/Par" + rand + ".txt";
    354     Set Table(SetOfSet(ParInf),pFile);
    355     Text t1 = ReadFile(pFile);
    356     Text t2 = Replace(t1, Quotes, "");
    357     Text head = "Nombre; Valor; Desv. Típ.; t de Student; 1-Alfa;"+NL;
    358     WriteFile(pFile,head+t2)
    359   };
    360 
    361   Serie residuals = lr[1];
    362   Serie prevHist  = output - residuals;
    363 
    364   Set seriesReport = [[output,prevHist]];
    365 
    366   Text aiaHtml = "";
    367   Set aia = AIA(residuals+0, 1/ARI);
    368   Real If(Card(aia),
    369   {
    370     Text AIAFile = tmpDir + "/AIA" + rand + ".txt";
    371     Set Table([[aia]],AIAFile);
    372     Text
    373     (
    374       aiaHtml :=
    375       "  <LI>" + HtmlTitle("Análisis de Intervención Automático",3,TitCol)+
    376         HtmlTable(AIAFile)+ BR
    377     );
    378     Real SystemDelete(AIAFile)
    379   });
    380 
    381   Text report =
    382     "<OL>" +
    383     "  <LI>" + HtmlTitle("Gráfico de previsión",3,TitCol)+
    384       HtmlBdtChart(seriesReport) +  BR +
    385     "  <LI>" + HtmlTitle("Información",3,TitCol)+
    386       HtmlTable(InfoFile)+ BR +
    387     "  <LI>" + HtmlTitle("Parámetros",3,TitCol)+
    388       HtmlTable(ParFile)+ BR +
    389     aiaHtml +
    390     "  <LI>" + HtmlTitle("Correlaciones de los parámetros",3,TitCol)+
    391       HtmlMatrixTable(lr[5],idSet,idSet,"Correlación") + BR +
    392     "  <LI>" + HtmlTitle("Gráfico de error de la previsión",3,TitCol)+
    393       HtmlBdtChart([[residuals]]) +  BR +
    394     "  <LI>" + HtmlTitle("Autocorrelaciones de los residuos", 3, Blue) +
    395                HtmlAutoCorReport([[residuals]]) + BR +
    396     "  <LI>" + HtmlTitle("Tabla de previsión histórica",3,TitCol)+
    397       HtmlBdtTable([[output,prevHist,residuals]]) +
    398     "</OL>";
    399  
    400  
    401   Real SystemDelete(InfoFile);
    402   Real SystemDelete(ParFile);
    403 
    404      
    405   Text PutEditor(old);
    406   report
    407 };
    408 
    409 
    410237//////////////////////////////////////////////////////////////////////////////
    411238  Text HtmlAutoRegression(Serie z,
Note: See TracChangeset for help on using the changeset viewer.