root/library/tests/tutorial/arx_simple.cpp @ 1383

Revision 1383, 2.2 kB (checked in by sindj, 13 years ago)

Program update, kontrola vypoctu provedena, integruje spravne v nedegenerovanem pripade. JS

  • Property svn:eol-style set to native
Line 
1#include "estim/arx.h"
2#include <vector>
3#include <iostream>
4#include <fstream>
5using namespace bdm;
6
7// estimation of AR(0) model
8int main(){
9        //data
10        vector<vector<vector<string>>> string_lists;
11        string_lists.push_back(vector<vector<string>>());
12        string_lists.push_back(vector<vector<string>>());
13        string_lists.push_back(vector<vector<string>>());
14
15        char* file_strings[3] = {"c:\\ar_normal.txt", "c:\\ar_student.txt", "c:\\ar_cauchy.txt"};
16       
17
18        for(int i = 0;i<3;i++)
19        {       
20                ifstream myfile(file_strings[i]);
21                if (myfile.is_open())
22                {
23                        while ( myfile.good() )
24                        {
25                                string line;
26                                getline(myfile,line);
27                               
28                                vector<string> parsed_line;
29                                while(line.find(',') != string::npos)
30                                {
31                                        int loc = line.find(',');
32                                        parsed_line.push_back(line.substr(0,loc));
33                                        line.erase(0,loc+1);                                   
34                                }                               
35
36                                string_lists[i].push_back(parsed_line);
37                        }
38                        myfile.close();
39                }
40        }
41
42    //prior
43    mat V0 = 0.0001 * eye ( 3 );
44    //V0 ( 0, 0 ) = 0.1; //
45
46        for(int j = 0;j<string_lists.size();j++)
47        { 
48               
49                for(int i = 0;i<string_lists[j].size();i++)
50                {
51                        ARX Ar;
52                        Ar.set_statistics ( 1, V0 ); //nu is default (set to have finite moments)
53                        Ar.set_constant ( false );
54                        Ar.validate();
55                        // forgetting is default: 1.0
56                       
57                        vector<vec> conditions;
58                        for(int k = 1;k<string_lists[j][i].size();k++)
59                        {
60                                vec condition;                                                         
61                                condition.ins(0,string_lists[j][i][k]);                         
62                                conditions.push_back(condition);                               
63
64                                if(conditions.size()>1)
65                                {               
66                                        conditions[k-2].ins(0,string_lists[j][i][k]);
67                                       
68                                }
69
70                                if(conditions.size()>2)
71                                {
72                                        conditions[k-3].ins(0,string_lists[j][i][k]);                                   
73
74                                        //cout << conditions[k-3] << endl;// << conditions[k-3].left(1) << conditions[k-3].right(2);
75
76                                        Ar.bayes(conditions[k-3].left(1),conditions[k-3].right(2));                             
77                                }
78                        }
79
80                        ofstream myfile;
81                        myfile.open("c:\\classic_ar1.txt",ios::app);
82                        myfile << Ar.posterior().mean()[0] << ";";
83                        myfile.close();
84
85                        myfile.open("c:\\classic_ar2.txt",ios::app);
86                        myfile << Ar.posterior().mean()[1] << ";";
87                        myfile.close();
88
89
90                       
91                }
92
93                ofstream myfile;
94                myfile.open("c:\\classic_ar1.txt",ios::app);
95                myfile << endl;
96                myfile.close();
97
98                myfile.open("c:\\classic_ar2.txt",ios::app);
99                myfile << endl;
100                myfile.close();
101        }
102}
Note: See TracBrowser for help on using the browser.