| 132 | | return children.size()+positivechildren.size()+negativechildren.size()+neutralchildren.size(); |
| 133 | | } |
| 134 | | |
| 135 | | void send_state_message(bool shouldsplit, bool shouldmerge) |
| | 132 | return children.size(); |
| | 133 | } |
| | 134 | |
| | 135 | |
| | 136 | }; |
| | 137 | |
| | 138 | /// A class for representing 0-dimensional polyhedron - a vertex. It will be located in the bottom row of the Hasse |
| | 139 | /// diagram representing a complex of polyhedrons. It has its coordinates in the parameter space. |
| | 140 | class vertex : public polyhedron |
| | 141 | { |
| | 142 | /// A dynamic array representing coordinates of the vertex |
| | 143 | vec coordinates; |
| | 144 | |
| | 145 | enum actions {MERGE, SPLIT}; |
| | 146 | |
| | 147 | public: |
| | 148 | |
| | 149 | |
| | 150 | |
| | 151 | /// Default constructor |
| | 152 | vertex(); |
| | 153 | |
| | 154 | /// Constructor of a vertex from a set of coordinates |
| | 155 | vertex(vec coordinates) |
| | 156 | { |
| | 157 | this->coordinates = coordinates; |
| | 158 | } |
| | 159 | |
| | 160 | /// A method that widens the set of coordinates of given vertex. It is used when a complex in a parameter |
| | 161 | /// space of certain dimension is established, but the dimension is not known when the vertex is created. |
| | 162 | void push_coordinate(double coordinate) |
| | 163 | { |
| | 164 | coordinates = concat(coordinates,coordinate); |
| | 165 | } |
| | 166 | |
| | 167 | /// A method obtaining the set of coordinates of a vertex. These coordinates are not obtained as a pointer |
| | 168 | /// (not given by reference), but a new copy is created (they are given by value). |
| | 169 | vec get_coordinates() |
| | 170 | { |
| | 171 | return coordinates; |
| | 172 | } |
| | 173 | |
| | 174 | |
| | 175 | }; |
| | 176 | |
| | 177 | /// A class representing a polyhedron in a top row of the complex. Such polyhedron has a condition that differitiates |
| | 178 | /// it from polyhedrons in other rows. |
| | 179 | class toprow : public polyhedron |
| | 180 | { |
| | 181 | |
| | 182 | public: |
| | 183 | /// A condition used for determining the function of a Laplace-Inverse-Gamma density resulting from Bayesian estimation |
| | 184 | vec condition; |
| | 185 | |
| | 186 | /// Default constructor |
| | 187 | toprow(); |
| | 188 | |
| | 189 | /// Constructor creating a toprow from the condition |
| | 190 | toprow(vec condition) |
| | 191 | { |
| | 192 | this->condition = condition; |
| | 193 | } |
| | 194 | |
| | 195 | }; |
| | 196 | |
| | 197 | class condition |
| | 198 | { |
| | 199 | public: |
| | 200 | vec value; |
| | 201 | |
| | 202 | int multiplicity; |
| | 203 | |
| | 204 | condition(vec value) |
| | 205 | { |
| | 206 | this->value = value; |
| | 207 | multiplicity = 1; |
| | 208 | } |
| | 209 | } |
| | 210 | |
| | 211 | |
| | 212 | //! Conditional(e) Multicriteria-Laplace-Inverse-Gamma distribution density |
| | 213 | class emlig // : eEF |
| | 214 | { |
| | 215 | |
| | 216 | /// A statistic in a form of a Hasse diagram representing a complex of convex polyhedrons obtained as a result |
| | 217 | /// of data update from Bayesian estimation or set by the user if this emlig is a prior density |
| | 218 | vector<vector<polyhedron*>> statistic; |
| | 219 | |
| | 220 | vector<vector<polyhedron*>> for_splitting; |
| | 221 | |
| | 222 | vector<vector<polyhedron*>> for_merging; |
| | 223 | |
| | 224 | vector<condition*> conditions; |
| | 225 | |
| | 226 | double normalization_factor; |
| | 227 | |
| | 228 | void alter_toprow_conditions(vec condition, bool should_be_added) |
| | 229 | { |
| | 230 | for(vector<polyhedron*>::iterator horiz_ref = statistic[statistic.size()-1].begin();horiz_ref<statistic[statistic.size()-1].end();horiz_ref++) |
| | 231 | { |
| | 232 | double product = 0; |
| | 233 | |
| | 234 | vector<vertex*>::iterator vertex_ref = (*horiz_ref)->vertices.begin(); |
| | 235 | |
| | 236 | do |
| | 237 | { |
| | 238 | product = (*vertex_ref)->coordinates*condition; |
| | 239 | } |
| | 240 | while(product == 0) |
| | 241 | |
| | 242 | if((product>0 && should_be_added)||(product<0 && !should_be_added)) |
| | 243 | { |
| | 244 | ((toprow*) (*horiz_ref))->condition += condition; |
| | 245 | } |
| | 246 | else |
| | 247 | { |
| | 248 | ((toprow*) (*horiz_ref))->condition -= condition; |
| | 249 | } |
| | 250 | } |
| | 251 | } |
| | 252 | |
| | 253 | |
| | 254 | void send_state_message(polyhedron* sender, bool shouldsplit, bool shouldmerge, int level) |
| 197 | | |
| 198 | | } |
| | 321 | if(shouldsplit) |
| | 322 | { |
| | 323 | switch(sender->get_state(SPLIT)) |
| | 324 | { |
| | 325 | case 1: |
| | 326 | current_parent->positivechildren.push_back(sender); |
| | 327 | break; |
| | 328 | case 0: |
| | 329 | current_parent->neutralchildren.push_back(sender); |
| | 330 | break; |
| | 331 | case -1: |
| | 332 | current_parent->negativechildren.push_back(sender); |
| | 333 | break; |
| | 334 | } |
| | 335 | |
| | 336 | if(is_last) |
| | 337 | { |
| | 338 | if(current_parent->negativechildren.size()>0) |
| | 339 | { |
| | 340 | if(current_parent->positivechildren.size()>0) |
| | 341 | { |
| | 342 | for_splitting[level+1].push_back(current_parent); |
| | 343 | |
| | 344 | current_parent->set_state(0, SPLIT); |
| | 345 | } |
| | 346 | else |
| | 347 | { |
| | 348 | current_parent->set_state(-1, SPLIT); |
| | 349 | |
| | 350 | current_parent->negativechildren.clear(); |
| | 351 | current_parent->neutralchildren.clear(); |
| | 352 | } |
| | 353 | } |
| | 354 | else if(current_parent->positivechildren.size()>0) |
| | 355 | { |
| | 356 | current_parent->set_state(1, SPLIT); |
| | 357 | |
| | 358 | current_parent->positivechildren.clear(); |
| | 359 | current_parent->neutralchildren.clear(); |
| | 360 | } |
| | 361 | else |
| | 362 | { |
| | 363 | current_parent->raise_multiplicity(); |
| | 364 | |
| | 365 | current_parent->neutralchildren.clear(); |
| | 366 | } |
| | 367 | } |
| | 368 | } |
| | 369 | |
| | 370 | if(is_last) |
| | 371 | { |
| | 372 | send_state_message(current_parent,shouldsplit,shouldmerge,level+1); |
| | 373 | } |
| | 374 | } |
| 201 | | } |
| 202 | | } |
| 203 | | }; |
| 204 | | |
| 205 | | /// A class for representing 0-dimensional polyhedron - a vertex. It will be located in the bottom row of the Hasse |
| 206 | | /// diagram representing a complex of polyhedrons. It has its coordinates in the parameter space. |
| 207 | | class vertex : public polyhedron |
| 208 | | { |
| 209 | | /// A dynamic array representing coordinates of the vertex |
| 210 | | vec coordinates; |
| 211 | | |
| 212 | | enum actions {MERGE, SPLIT}; |
| 213 | | |
| 214 | | public: |
| 215 | | |
| 216 | | |
| 217 | | |
| 218 | | /// Default constructor |
| 219 | | vertex(); |
| 220 | | |
| 221 | | /// Constructor of a vertex from a set of coordinates |
| 222 | | vertex(vec coordinates) |
| 223 | | { |
| 224 | | this->coordinates = coordinates; |
| 225 | | } |
| 226 | | |
| 227 | | /// A method that widens the set of coordinates of given vertex. It is used when a complex in a parameter |
| 228 | | /// space of certain dimension is established, but the dimension is not known when the vertex is created. |
| 229 | | void push_coordinate(double coordinate) |
| 230 | | { |
| 231 | | coordinates = concat(coordinates,coordinate); |
| 232 | | } |
| 233 | | |
| 234 | | /// A method obtaining the set of coordinates of a vertex. These coordinates are not obtained as a pointer |
| 235 | | /// (not given by reference), but a new copy is created (they are given by value). |
| 236 | | vec get_coordinates() |
| 237 | | { |
| 238 | | return coordinates; |
| 239 | | } |
| 240 | | |
| 241 | | |
| 242 | | }; |
| 243 | | |
| 244 | | /// A class representing a polyhedron in a top row of the complex. Such polyhedron has a condition that differitiates |
| 245 | | /// it from polyhedrons in other rows. |
| 246 | | class toprow : public polyhedron |
| 247 | | { |
| 248 | | |
| 249 | | public: |
| 250 | | /// A condition used for determining the function of a Laplace-Inverse-Gamma density resulting from Bayesian estimation |
| 251 | | vec condition; |
| 252 | | |
| 253 | | /// Default constructor |
| 254 | | toprow(); |
| 255 | | |
| 256 | | /// Constructor creating a toprow from the condition |
| 257 | | toprow(vec condition) |
| 258 | | { |
| 259 | | this->condition = condition; |
| 260 | | } |
| 261 | | |
| 262 | | }; |
| 263 | | |
| 264 | | class condition |
| 265 | | { |
| 266 | | public: |
| 267 | | vec value; |
| 268 | | |
| 269 | | int multiplicity; |
| 270 | | |
| 271 | | condition(vec value) |
| 272 | | { |
| 273 | | this->value = value; |
| 274 | | multiplicity = 1; |
| 275 | | } |
| 276 | | } |
| 277 | | |
| 278 | | |
| 279 | | //! Conditional(e) Multicriteria-Laplace-Inverse-Gamma distribution density |
| 280 | | class emlig // : eEF |
| 281 | | { |
| 282 | | |
| 283 | | /// A statistic in a form of a Hasse diagram representing a complex of convex polyhedrons obtained as a result |
| 284 | | /// of data update from Bayesian estimation or set by the user if this emlig is a prior density |
| 285 | | vector<vector<polyhedron*>> statistic; |
| 286 | | |
| 287 | | vector<condition*> conditions; |
| 288 | | |
| 289 | | double normalization_factor; |
| 290 | | |
| 291 | | void alter_toprow_conditions(vec condition, bool should_be_added) |
| 292 | | { |
| 293 | | for(vector<polyhedron*>::iterator horiz_ref = statistic[statistic.size()-1].begin();horiz_ref<statistic[statistic.size()-1].end();horiz_ref++) |
| 294 | | { |
| 295 | | double product = 0; |
| 296 | | |
| 297 | | vector<vertex*>::iterator vertex_ref = (*horiz_ref)->vertices.begin(); |
| 298 | | |
| 299 | | do |
| 300 | | { |
| 301 | | product = (*vertex_ref)->coordinates*condition; |
| 302 | | } |
| 303 | | while(product == 0) |
| 304 | | |
| 305 | | if((product>0 && should_be_added)||(product<0 && !should_be_added)) |
| 306 | | { |
| 307 | | ((toprow*) (*horiz_ref))->condition += condition; |
| 308 | | } |
| 309 | | else |
| 310 | | { |
| 311 | | ((toprow*) (*horiz_ref))->condition -= condition; |
| 312 | | } |
| 313 | | } |
| | 377 | |
| | 378 | } |