1 | |
---|
2 | /*! |
---|
3 | \file |
---|
4 | \brief Robust |
---|
5 | \author Vasek Smidl |
---|
6 | |
---|
7 | */ |
---|
8 | |
---|
9 | #include "robustlib.h" |
---|
10 | #include <vector> |
---|
11 | #include <iostream> |
---|
12 | #include <fstream> |
---|
13 | |
---|
14 | using namespace itpp; |
---|
15 | //using namespace bdm; |
---|
16 | |
---|
17 | const int emlig_size = 2; |
---|
18 | |
---|
19 | |
---|
20 | int main ( int argc, char* argv[] ) { |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | vector<vector<vector<string>>> string_lists; |
---|
26 | string_lists.push_back(vector<vector<string>>()); |
---|
27 | string_lists.push_back(vector<vector<string>>()); |
---|
28 | string_lists.push_back(vector<vector<string>>()); |
---|
29 | |
---|
30 | char* file_strings[3] = {"c:\\ar_normal.txt", "c:\\ar_student.txt", "c:\\ar_cauchy.txt"}; |
---|
31 | |
---|
32 | |
---|
33 | for(int i = 0;i<3;i++) |
---|
34 | { |
---|
35 | ifstream myfile(file_strings[i]); |
---|
36 | if (myfile.is_open()) |
---|
37 | { |
---|
38 | while ( myfile.good() ) |
---|
39 | { |
---|
40 | string line; |
---|
41 | getline(myfile,line); |
---|
42 | |
---|
43 | vector<string> parsed_line; |
---|
44 | while(line.find(',') != string::npos) |
---|
45 | { |
---|
46 | int loc = line.find(','); |
---|
47 | parsed_line.push_back(line.substr(0,loc)); |
---|
48 | line.erase(0,loc+1); |
---|
49 | } |
---|
50 | |
---|
51 | string_lists[i].push_back(parsed_line); |
---|
52 | } |
---|
53 | myfile.close(); |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | for(int j = 0;j<string_lists.size();j++) |
---|
58 | { |
---|
59 | |
---|
60 | for(int i = 0;i<string_lists[j].size()-1;i++) |
---|
61 | { |
---|
62 | vector<vec> conditions; |
---|
63 | emlig* emliga = new emlig(2); |
---|
64 | for(int k = 1;k<string_lists[j][i].size();k++) |
---|
65 | { |
---|
66 | vec condition; |
---|
67 | //condition.ins(0,1); |
---|
68 | condition.ins(0,string_lists[j][i][k]); |
---|
69 | conditions.push_back(condition); |
---|
70 | |
---|
71 | //cout << "orig:" << condition << endl; |
---|
72 | |
---|
73 | if(conditions.size()>1) |
---|
74 | { |
---|
75 | conditions[k-2].ins(0,string_lists[j][i][k]); |
---|
76 | |
---|
77 | } |
---|
78 | |
---|
79 | if(conditions.size()>2) |
---|
80 | { |
---|
81 | conditions[k-3].ins(0,string_lists[j][i][k]); |
---|
82 | |
---|
83 | //cout << "modi:" << conditions[k-3] << endl; |
---|
84 | |
---|
85 | emliga->add_condition(conditions[k-3]); |
---|
86 | |
---|
87 | /* |
---|
88 | if(k>5) |
---|
89 | { |
---|
90 | cout << "MaxLik coords:" << emliga->minimal_vertex->get_coordinates() << endl; |
---|
91 | } |
---|
92 | */ |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | //emliga->step_me(0); |
---|
97 | ofstream myfile; |
---|
98 | myfile.open("c:\\robust_ar1.txt",ios::app); |
---|
99 | myfile << emliga->minimal_vertex->get_coordinates()[0] << ";"; |
---|
100 | myfile.close(); |
---|
101 | |
---|
102 | myfile.open("c:\\robust_ar2.txt",ios::app); |
---|
103 | myfile << emliga->minimal_vertex->get_coordinates()[1] << ";"; |
---|
104 | myfile.close(); |
---|
105 | |
---|
106 | cout << "MaxLik coords:" << emliga->minimal_vertex->get_coordinates() << endl; |
---|
107 | cout << "Step: " << i << endl; |
---|
108 | } |
---|
109 | |
---|
110 | cout << "One experiment finished." << endl; |
---|
111 | |
---|
112 | ofstream myfile; |
---|
113 | myfile.open("c:\\robust_ar1.txt",ios::app); |
---|
114 | myfile << endl; |
---|
115 | myfile.close(); |
---|
116 | |
---|
117 | myfile.open("c:\\robust_ar2.txt",ios::app); |
---|
118 | myfile << endl; |
---|
119 | myfile.close(); |
---|
120 | } |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | //emlig* emlig1 = new emlig(emlig_size); |
---|
125 | |
---|
126 | /* |
---|
127 | emlig1->set_correction_factors(4); |
---|
128 | |
---|
129 | for(int j = 0;j<emlig1->correction_factors.size();j++) |
---|
130 | { |
---|
131 | for(set<my_ivec>::iterator vec_ref = emlig1->correction_factors[j].begin();vec_ref!=emlig1->correction_factors[j].end();vec_ref++) |
---|
132 | { |
---|
133 | cout << j << " "; |
---|
134 | |
---|
135 | for(int i=0;i<(*vec_ref).size();i++) |
---|
136 | { |
---|
137 | cout << (*vec_ref)[i]; |
---|
138 | } |
---|
139 | |
---|
140 | cout << endl; |
---|
141 | } |
---|
142 | }*/ |
---|
143 | |
---|
144 | /* |
---|
145 | vec condition1 = "1.0 1.0 1.01"; |
---|
146 | emlig1->add_condition(condition1); |
---|
147 | |
---|
148 | vec condition2 = "-1.0 1.0 1.0"; |
---|
149 | emlig1->add_condition(condition2); |
---|
150 | |
---|
151 | vec condition3 = "0.5 -1.01 1.0"; |
---|
152 | emlig1->add_condition(condition3); |
---|
153 | |
---|
154 | vec condition4 = "-0.5 -1.0 1.0"; |
---|
155 | emlig1->add_condition(condition4); |
---|
156 | |
---|
157 | cout << emlig1->minimal_vertex->get_coordinates(); |
---|
158 | |
---|
159 | //vec condition5 = "-0.3 1.7 1.5"; |
---|
160 | //emlig1->add_condition(condition5); |
---|
161 | |
---|
162 | // DA SE POUZIT PRO VYPIS DO SOUBORU |
---|
163 | // emlig1->step_me(0); |
---|
164 | |
---|
165 | //emlig1->remove_condition(condition1); |
---|
166 | |
---|
167 | |
---|
168 | |
---|
169 | |
---|
170 | /* |
---|
171 | |
---|
172 | for(int i = 0;i<100;i++) |
---|
173 | { |
---|
174 | cout << endl << "Step:" << i << endl; |
---|
175 | |
---|
176 | double condition[emlig_size+1]; |
---|
177 | |
---|
178 | for(int k = 0;k<=emlig_size;k++) |
---|
179 | { |
---|
180 | condition[k] = (rand()-RAND_MAX/2)/1000.0; |
---|
181 | } |
---|
182 | |
---|
183 | |
---|
184 | vec* condition_vec = new vec(condition,emlig_size+1); |
---|
185 | emlig1->add_condition(*condition_vec); |
---|
186 | |
---|
187 | /* |
---|
188 | for(polyhedron* toprow_ref = emlig1->statistic.rows[emlig_size]; toprow_ref != emlig1->statistic.end_poly; toprow_ref = toprow_ref->next_poly) |
---|
189 | { |
---|
190 | cout << ((toprow*)toprow_ref)->probability << endl; |
---|
191 | } |
---|
192 | */ |
---|
193 | /* |
---|
194 | cout << emlig1->statistic_rowsize(emlig_size) << endl << endl; |
---|
195 | |
---|
196 | /* |
---|
197 | if(i-emlig1->number_of_parameters >= 0) |
---|
198 | { |
---|
199 | pause(30); |
---|
200 | } |
---|
201 | */ |
---|
202 | |
---|
203 | // emlig1->step_me(i); |
---|
204 | |
---|
205 | /* |
---|
206 | vector<int> sizevector; |
---|
207 | for(int s = 0;s<=emlig1->number_of_parameters;s++) |
---|
208 | { |
---|
209 | sizevector.push_back(emlig1->statistic_rowsize(s)); |
---|
210 | } |
---|
211 | */ |
---|
212 | //} |
---|
213 | |
---|
214 | |
---|
215 | |
---|
216 | |
---|
217 | /* |
---|
218 | emlig1->step_me(1); |
---|
219 | |
---|
220 | vec condition = "2.0 0.0 1.0"; |
---|
221 | |
---|
222 | emlig1->add_condition(condition); |
---|
223 | |
---|
224 | vector<int> sizevector; |
---|
225 | for(int s = 0;s<=emlig1->number_of_parameters;s++) |
---|
226 | { |
---|
227 | sizevector.push_back(emlig1->statistic_rowsize(s)); |
---|
228 | } |
---|
229 | |
---|
230 | emlig1->step_me(2); |
---|
231 | |
---|
232 | condition = "2.0 1.0 0.0"; |
---|
233 | |
---|
234 | emlig1->add_condition(condition); |
---|
235 | |
---|
236 | sizevector.clear(); |
---|
237 | for(int s = 0;s<=emlig1->number_of_parameters;s++) |
---|
238 | { |
---|
239 | sizevector.push_back(emlig1->statistic_rowsize(s)); |
---|
240 | } |
---|
241 | */ |
---|
242 | |
---|
243 | return 0; |
---|
244 | } |
---|
245 | |
---|
246 | |
---|