root/applications/robust/robustlib.h @ 1172

Revision 1172, 6.2 kB (checked in by sindj, 14 years ago)

Znova a lip, ted uz snad skoro dokoncena funkce create_statistic(). JS

Line 
1/*!
2  \file
3  \brief Robust Bayesian auto-regression model
4  \author Jan Sindelar.
5*/
6
7#ifndef ROBUST_H
8#define ROBUST_H
9
10#include <stat/exp_family.h>
11#include <limits>
12#include <vector>
13#include <algorithm>
14       
15using namespace bdm;
16using namespace std;
17
18const double max_range = numeric_limits<double>::max()/10e-5;
19
20class polyhedron;
21class vertex;
22
23/// A class describing a single polyhedron of the split complex. From a collection of such classes a Hasse diagram
24/// of the structure in the exponent of a Laplace-Inverse-Gamma density will be created.
25class polyhedron
26{
27        /// A property having a value of 1 usually, with higher value only if the polyhedron arises as a coincidence of
28        /// more than just the necessary number of conditions. For example if a newly created line passes through an already
29        /// existing point, the points multiplicity will rise by 1.
30        int multiplicity;       
31
32public:
33        /// A list of polyhedrons parents within the Hasse diagram.
34        vector<polyhedron*> parents;
35
36        /// A list of polyhedrons children withing the Hasse diagram.
37        vector<polyhedron*> children;
38
39        /// All the vertices of the given polyhedron
40        vector<vertex*> vertices;
41
42        /// A list used for storing children that lie in the positive region related to a certain condition
43        vector<polyhedron*> positivechildren;
44
45        /// A list used for storing children that lie in the negative region related to a certain condition
46        vector<polyhedron*> negativechildren;
47
48        /// Children intersecting the condition
49        vector<polyhedron*> neutralchildren;
50
51        /// List of triangulation polyhedrons of the polyhedron given by their relative vertices.
52        vector<vector<vertex*>> triangulations;
53
54        /// A list of relative addresses serving for Hasse diagram construction.
55        vector<int> kids_rel_addresses;
56
57        /// Default constructor
58        polyhedron()
59        {
60                multiplicity = 1;       
61        }
62       
63        /// Setter for raising multiplicity
64        void RaiseMultiplicity()
65        {
66                multiplicity++;
67        }
68
69        /// Setter for lowering multiplicity
70        void LowerMultiplicity()
71        {
72                multiplicity--;
73        }
74       
75        /// An obligatory operator, when the class is used within a C++ STL structure like a vector
76        int operator==(polyhedron polyhedron2)
77        {
78                return true;
79        }
80
81        /// An obligatory operator, when the class is used within a C++ STL structure like a vector
82        int operator<(polyhedron polyhedron2)
83        {
84                return false;
85        }
86};
87
88/// A
89class vertex : public polyhedron
90{
91        vector<double> coordinates;
92
93public:
94
95        vertex();
96
97        vertex(vector<double> coordinates)
98        {
99                this->coordinates = coordinates;
100        }
101
102        void push_coordinate(double coordinate)
103        {
104                coordinates.push_back(coordinate);
105        }
106
107        vector<double> get_coordinates()
108        {
109                vector<double> returned_vec;
110
111                copy(this->coordinates.begin(),this->coordinates.end(),returned_vec.begin());
112
113                return returned_vec;
114        }
115};
116
117class toprow : public polyhedron
118{
119        vector<double> condition;
120
121public:
122
123        toprow();
124
125        toprow(vector<double> condition)
126        {
127                this->condition = condition;
128        }
129
130};
131
132
133
134
135//! Conditional(e) Multicriteria-Laplace-Inverse-Gamma distribution density
136class emlig : public eEF
137{
138
139        vector<vector<polyhedron*>> statistic;
140       
141public: 
142
143        emlig(int number_of_parameters)
144        {
145                create_statistic(number_of_parameters);
146        }
147
148        emlig(vector<vector<polyhedron*>> statistic)
149        {
150                this->statistic = statistic;
151        }
152
153
154
155protected:
156
157    void create_statistic(int number_of_parameters)
158        {
159                vector<double> origin_coord;   
160
161                vertex *origin = new vertex(origin_coord);
162
163                origin->vertices.push_back(origin);
164
165                vector<polyhedron*> origin_vec;
166
167                origin_vec.push_back(origin);
168
169                statistic.push_back(origin_vec);
170
171                for(int i=0;i<number_of_parameters;i++)
172                {
173                        vector<double> origin_coord1 = origin->get_coordinates();
174                        vector<double> origin_coord2 = origin->get_coordinates();
175
176                        origin->push_coordinate(0);
177
178                        origin_coord1.push_back(max_range);
179                        origin_coord2.push_back(-max_range);
180
181                        vertex *new_point1 = new vertex(origin_coord1);
182                        vertex *new_point2 = new vertex(origin_coord2); 
183
184                        vector<vector<polyhedron*>> new_statistic1;
185                        vector<vector<polyhedron*>> new_statistic2;
186
187                       
188                        for(int j=0;j<statistic.size();j++)
189                        {
190                                int element_number = 0;
191
192                                for(vector<polyhedron*>::iterator horiz_ref = statistic[j].begin();horiz_ref<statistic[j].end();horiz_ref++)
193                                {       
194                                        if(!(*horiz_ref)->parents.empty())
195                                        {
196                                                for(vector<polyhedron*>::iterator parent_ref = (*horiz_ref)->parents.begin();parent_ref < (*horiz_ref)->parents.end();parent_ref++)
197                                                {
198                                                        (*parent_ref)->kids_rel_addresses.push_back(element_number);                                                   
199                                                }                                               
200                                        }
201
202                                        vector<double> vec1(i+2,0);
203                                        vector<double> vec2(i+2,0);
204
205                                        toprow *current_copy1 = new toprow(vec1);
206                                        toprow *current_copy2 = new toprow(vec2);                                       
207
208                                        for(vector<vertex*>::iterator vert_ref = (*horiz_ref)->vertices.begin();vert_ref<(*horiz_ref)->vertices.end();vert_ref++)
209                                        {
210                                                current_copy1->vertices.push_back(*vert_ref);
211                                                current_copy2->vertices.push_back(*vert_ref);                                           
212                                        }
213                                       
214
215                                        current_copy1->vertices.push_back(new_point1);
216                                        current_copy2->vertices.push_back(new_point2);
217
218                                        current_copy1->triangulations.push_back(current_copy1->vertices);
219                                        current_copy2->triangulations.push_back(current_copy2->vertices);
220
221                                       
222
223                                        if(!(*horiz_ref)->kids_rel_addresses.empty())
224                                        {
225                                                for(vector<int>::iterator kid_ref = (*horiz_ref)->kids_rel_addresses.begin();kid_ref<(*horiz_ref)->kids_rel_addresses.end();kid_ref++)
226                                                {                                               
227                                                        current_copy1->children.push_back(new_statistic1[i][(*kid_ref)]);
228                                                        current_copy2->children.push_back(new_statistic2[i][(*kid_ref)]);
229
230                                                        new_statistic1[i][(*kid_ref)]->parents.push_back(current_copy1);
231                                                        new_statistic2[i][(*kid_ref)]->parents.push_back(current_copy2);
232                                                }                                               
233
234                                                (*horiz_ref)->kids_rel_addresses.clear();
235                                        }
236                                        else
237                                        {
238                                                current_copy1->children.push_back(new_point1);
239                                                current_copy2->children.push_back(new_point2);
240
241                                                new_point1->parents.push_back(current_copy1);
242                                                new_point2->parents.push_back(current_copy2);
243                                        }
244
245                                        current_copy1->children.push_back(*horiz_ref);
246                                        current_copy2->children.push_back(*horiz_ref);
247
248                                        new_statistic1[i+1].push_back(current_copy1);
249                                        new_statistic2[i+1].push_back(current_copy2);
250                                       
251                                        element_number++;
252                                }                               
253                        }                               
254                       
255                }
256        }
257
258
259       
260       
261};
262
263//! Robust Bayesian AR model for Multicriteria-Laplace-Inverse-Gamma density
264class RARX : public BMEF{
265};
266
267
268#endif //TRAGE_H
Note: See TracBrowser for help on using the browser.