Changeset 1301 for applications/robust/main.cpp
- Timestamp:
- 03/21/11 09:01:57 (13 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/robust/main.cpp
r1300 r1301 21 21 22 22 /* 23 // EXPERIMENT: 100 AR model generated time series of length of 30 from y_t=0.95*y_(t-1)+0.05*y_(t-2)+0.2*e_t, 24 // where e_t is normally, student(4) and cauchy distributed are tested using robust AR model, to obtain the 25 // variance of location parameter estimators and compare it to the classical setup. 23 26 vector<vector<vector<string>>> string_lists; 24 27 string_lists.push_back(vector<vector<string>>()); … … 55 58 for(int j = 0;j<string_lists.size();j++) 56 59 { 57 /*60 58 61 for(int i = 0;i<string_lists[j].size()-1;i++) 59 62 { 60 63 vector<vec> conditions; 61 emlig* emliga = new emlig(2); 64 //emlig* emliga = new emlig(2); 65 RARX* my_rarx = new RARX(2,30); 66 62 67 for(int k = 1;k<string_lists[j][i].size();k++) 63 68 { … … 81 86 //cout << "modi:" << conditions[k-3] << endl; 82 87 83 emliga->add_condition(conditions[k-3]);88 my_rarx->bayes(conditions[k-3]); 84 89 85 90 … … 94 99 95 100 //emliga->step_me(0); 101 /* 96 102 ofstream myfile; 97 103 myfile.open("c:\\robust_ar1.txt",ios::app); 98 myfile << emliga->minimal_vertex->get_coordinates()[0] << ";";104 myfile << my_rarx->minimal_vertex->get_coordinates()[0] << ";"; 99 105 myfile.close(); 100 106 … … 102 108 myfile << emliga->minimal_vertex->get_coordinates()[1] << ";"; 103 109 myfile.close(); 110 104 111 105 112 cout << "MaxLik coords:" << emliga->minimal_vertex->get_coordinates() << endl; … … 117 124 myfile << endl; 118 125 myfile.close(); 119 } 120 */ 121 122 123 emlig* emlig1 = new emlig(emlig_size); 124 emlig* emlig2 = new emlig(emlig_size); 126 }*/ 127 128 129 // EXPERIMENT: A moving window estimation and prediction of RARX is tested on data generated from 130 // y_t=0.95*y_(t-1)+0.05*y_(t-2)+0.2*e_t, where e_t is normally, student(4) and cauchy distributed. It 131 // can be compared to the classical setup. 132 133 134 vector<vector<string>> strings; 135 136 char* file_strings[3] = {"c:\\ar_student_single.txt", "c:\\ar_cauchy_single.txt","c:\\ar_normal_single.txt"}; 137 138 for(int i = 0;i<3;i++) 139 { 140 ifstream myfile(file_strings[i]); 141 if (myfile.is_open()) 142 { 143 string line; 144 getline(myfile,line); 145 146 vector<string> parsed_line; 147 while(line.find(',') != string::npos) 148 { 149 int loc = line.find(','); 150 parsed_line.push_back(line.substr(0,loc)); 151 line.erase(0,loc+1); 152 } 153 154 strings.push_back(parsed_line); 155 156 myfile.close(); 157 } 158 } 159 160 for(int j = 0;j<strings.size();j++) 161 { 162 vector<vec> conditions; 163 //emlig* emliga = new emlig(2); 164 RARX* my_rarx = new RARX(2,0); 165 166 for(int k = 1;k<170;k++) 167 { 168 vec condition; 169 //condition.ins(0,1); 170 condition.ins(0,strings[j][k]); 171 conditions.push_back(condition); 172 173 //cout << "orig:" << condition << endl; 174 175 if(conditions.size()>1) 176 { 177 conditions[k-2].ins(0,strings[j][k]); 178 179 } 180 181 if(conditions.size()>2) 182 { 183 conditions[k-3].ins(0,strings[j][k]); 184 185 // cout << "modi:" << conditions[k-3] << endl; 186 187 my_rarx->bayes(conditions[k-3]); 188 189 190 191 if(k>5) 192 { 193 cout << "MaxLik coords:" << my_rarx->posterior->minimal_vertex->get_coordinates() << endl; 194 195 ofstream myfile; 196 char fstring[80]; 197 strcpy(fstring,file_strings[j]); 198 strcat(fstring,"_res.txt"); 199 200 myfile.open(fstring,ios::app); 201 myfile << my_rarx->posterior->minimal_vertex->get_coordinates()[0]; 202 if(k!=strings[j].size()-1) 203 { 204 myfile << ","; 205 } 206 else 207 { 208 myfile << endl; 209 } 210 myfile.close(); 211 } 212 213 } 214 215 //emliga->step_me(0); 216 /* 217 ofstream myfile; 218 myfile.open("c:\\robust_ar1.txt",ios::app); 219 myfile << my_rarx->minimal_vertex->get_coordinates()[0] << ";"; 220 myfile.close(); 221 222 myfile.open("c:\\robust_ar2.txt",ios::app); 223 myfile << emliga->minimal_vertex->get_coordinates()[1] << ";"; 224 myfile.close(); 225 226 227 cout << "MaxLik coords:" << emliga->minimal_vertex->get_coordinates() << endl; 228 cout << "Step: " << i << endl;*/ 229 } 230 } 231 232 /* 233 cout << "One experiment finished." << endl; 234 235 ofstream myfile; 236 myfile.open("c:\\robust_ar1.txt",ios::app); 237 myfile << endl; 238 myfile.close(); 239 240 myfile.open("c:\\robust_ar2.txt",ios::app); 241 myfile << endl; 242 myfile.close();*/ 243 244 245 //emlig* emlig1 = new emlig(emlig_size); 246 247 //emlig1->step_me(0); 248 //emlig* emlig2 = new emlig(emlig_size); 125 249 126 250 /* … … 142 266 }*/ 143 267 144 268 /* 145 269 vec condition5 = "1.0 1.0 1.01";//"-0.3 1.7 1.5"; 146 270 147 271 emlig1->add_condition(condition5); 148 149 //vec condition1a = "1.0 1.0 1.01"; 272 //emlig1->step_me(0); 273 274 275 vec condition1a = "-1.0 1.02 0.5"; 150 276 //vec condition1b = "1.0 1.0 1.01"; 151 //emlig1->add_condition(condition1a);277 emlig1->add_condition(condition1a); 152 278 //emlig2->add_condition(condition1b); 153 279 154 //vec condition2a = "-1.0 1.0 1.0";280 vec condition2a = "-0.3 1.7 1.5"; 155 281 //vec condition2b = "-1.0 1.0 1.0"; 156 //emlig1->add_condition(condition2a);282 emlig1->add_condition(condition2a); 157 283 //emlig2->add_condition(condition2b); 158 284 159 //vec condition3a = "0.5 -1.01 1.0";285 vec condition3a = "0.5 -1.01 1.0"; 160 286 //vec condition3b = "0.5 -1.01 1.0"; 161 287 162 //emlig1->add_condition(condition3a);288 emlig1->add_condition(condition3a); 163 289 //emlig2->add_condition(condition3b); 164 290 165 //vec condition4a = "-0.5 -1.0 1.0";291 vec condition4a = "-0.5 -1.0 1.0"; 166 292 //vec condition4b = "-0.5 -1.0 1.0"; 167 293 168 //emlig1->add_condition(condition4a);294 emlig1->add_condition(condition4a); 169 295 //cout << "************************************************" << endl; 170 296 //emlig2->add_condition(condition4b); … … 173 299 //cout << emlig1->minimal_vertex->get_coordinates(); 174 300 175 emlig1->remove_condition(condition5); 301 //emlig1->remove_condition(condition3a); 302 //emlig1->step_me(0); 303 //emlig1->remove_condition(condition2a); 304 //emlig1->remove_condition(condition1a); 305 //emlig1->remove_condition(condition5); 306 176 307 177 308 //emlig1->step_me(0); … … 183 314 184 315 //emlig1->remove_condition(condition1); 185 186 187 188 189 /*190 316 317 318 319 320 321 /* 191 322 for(int i = 0;i<100;i++) 192 323 {