Changeset 1254 for applications/robust

Show
Ignore:
Timestamp:
11/19/10 11:15:48 (14 years ago)
Author:
sindj
Message:

Rozdelane pocitani integralu. JS

Location:
applications/robust
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/main.cpp

    r1234 r1254  
    2323                cout << "Step:" << i << endl; 
    2424 
    25                 double condition[9];             
     25                double condition[4];             
    2626 
    2727                condition[0] = rand()/1000.0; 
  • applications/robust/robustlib.cpp

    r1172 r1254  
    11#include "robustlib.h" 
    22 
     3void polyhedron::triangulate(bool should_integrate) 
     4        {                
     5                for(list<polyhedron*>::iterator child_ref = children.begin();child_ref!=children.end();child_ref++) 
     6                { 
     7                        set<double> simplex_integrals; 
     8                         
     9                        for(list<set<vertex*>>::iterator t_ref = (*child_ref)->triangulation.begin();t_ref!=(*child_ref)->triangulation.end();t_ref++) 
     10                        { 
     11                                set<vertex*> new_simplex; 
     12                                new_simplex.insert((*t_ref).begin(),(*t_ref).end());                             
     13 
     14                                pair<set<vertex*>::iterator,bool> ret_val = new_simplex.insert(*vertices.begin()); 
     15 
     16                                if(ret_val.second == true) 
     17                                { 
     18                                        triangulation.push_back(new_simplex); 
     19 
     20                                        if(should_integrate) 
     21                                        { 
     22                                                toprow* as_toprow = (toprow*)this; 
     23 
     24                                                vec cur_condition = as_toprow->condition.get(1,as_toprow->condition.size()-1); 
     25 
     26                                                vertex* base_vertex = (*new_simplex.begin()); 
     27 
     28                                                int dimension = new_simplex.size()-1; 
     29 
     30                                                mat jacobian(dimension,dimension); 
     31 
     32                                                double a_0 = base_vertex->get_coordinates()*cur_condition+as_toprow->condition[0]; 
     33                                                vec as; 
     34 
     35                                                int row_count = 0; 
     36 
     37                                                for(set<vertex*>::iterator vert_ref = (++new_simplex.begin()); vert_ref!=new_simplex.end();vert_ref++) 
     38                                                { 
     39                                                        vec relative_coords = (*vert_ref)->get_coordinates()-base_vertex->get_coordinates(); 
     40                                                        jacobian.set_row(row_count,relative_coords); 
     41 
     42                                                        double new_a = relative_coords*cur_condition;                                                    
     43                                                                                                                 
     44                                                        as.ins(as.size(),new_a);                                                         
     45                                                         
     46                                                        row_count++; 
     47                                                } 
     48 
     49                                                double int_value = 0; 
     50                                                for(int a_count = 0;a_count<as.size();a_count++) 
     51                                                { 
     52                                                        vec reduced_as = (as.get(a_count)-as); 
     53 
     54                                                        reduced_as.del(a_count); 
     55 
     56                                                        int fac_order = ((toprow*)this)->condition_order-reduced_as.size()-1; 
     57 
     58                                                        double fac_value = ((double)tgamma(fac_order)*det(jacobian))/as[a_count]/pow(as[a_count]-a_0,fac_order);  
     59 
     60                                                        for(int b_count = 0;b_count<reduced_as.size();b_count++) 
     61                                                        { 
     62                                                                fac_value /= reduced_as[b_count];                                                                
     63                                                        } 
     64 
     65                                                        int_value += fac_value;                                                  
     66                                                } 
     67 
     68                                                simplex_integrals.insert(int_value); 
     69                                        } 
     70                                }  
     71                        } 
     72 
     73                        if(should_integrate) 
     74                        { 
     75                                ((toprow*)this)->probability = 0.0; 
     76 
     77                                for(set<double>::iterator integ_ref = simplex_integrals.begin();integ_ref!=simplex_integrals.end();integ_ref++) 
     78                                { 
     79                                        ((toprow*)this)->probability += (*integ_ref); 
     80                                } 
     81                        } 
     82                }                
     83        } 
     84 
  • applications/robust/robustlib.h

    r1242 r1254  
    1919using namespace itpp; 
    2020 
    21 const double max_range = 99999999999999999999999.0;//numeric_limits<double>::max()/10e-10; 
     21const double max_range = 1000.0;//numeric_limits<double>::max()/10e-10; 
    2222 
    2323enum actions {MERGE, SPLIT}; 
     
    2525class polyhedron; 
    2626class vertex; 
     27class toprow; 
    2728 
    2829/* 
     
    170171        } 
    171172 
    172         void triangulate(bool should_integrate) 
    173         {                
    174                 for(list<polyhedron*>::iterator child_ref = children.begin();child_ref!=children.end();child_ref++) 
    175                 { 
    176                         set<double> simplex_integrals; 
    177                          
    178                         for(list<set<vertex*>>::iterator t_ref = (*child_ref)->triangulation.begin();t_ref!=(*child_ref)->triangulation.end();t_ref++) 
    179                         { 
    180                                 set<vertex*> new_simplex; 
    181                                 new_simplex.insert((*t_ref).begin(),(*t_ref).end());                             
    182  
    183                                 pair<set<vertex*>::iterator,bool> ret_val = new_simplex.insert(*vertices.begin()); 
    184  
    185                                 if(ret_val.second == true) 
    186                                 { 
    187                                         triangulation.push_back(new_simplex); 
    188  
    189                                         if(should_integrate) 
    190                                         { 
    191                                                 toprow* as_toprow = (toprow*)this;                                               
    192  
    193                                                 vertex* base_vertex = (*new_simplex.begin()); 
    194  
    195                                                 double a_0 = base_vertex->get_coordinates()*as_toprow->condition(1,as_toprow->condition.size()-1)+as_toprow->condition[0]; 
    196                                                 list<double> as; 
    197  
    198                                                 for(set<vertex*>::iterator vert_ref = (++new_simplex.begin()); vert_ref!=new_simplex.end();vert_ref++) 
    199                                                 { 
    200                                                         vec relative_coords = (*vert_ref)->get_coordinates()-base_vertex->get_coordinates(); 
    201  
    202                                                         double new_a = relative_coords*as_toprow->condition(1,as_toprow->condition.size()-1); 
    203  
    204                                                         as.push_back(new_a); 
    205                                                 } 
    206  
    207                                                 for(list<double>::iterator as_ref = as.begin();as_ref!=as.end();as_ref++) 
    208                                                 { 
    209                                                         //TODO DODELAT VYPOCET! 
    210                                                 } 
    211                                         } 
    212                                 }  
    213                         } 
    214  
    215                         if(should_integrate) 
    216                         { 
    217                                 ((toprow*)this)->probability = 0.0; 
    218  
    219                                 for(set<double>::iterator integ_ref = simplex_integrals.begin();integ_ref!=simplex_integrals.end();integ_ref++) 
    220                                 { 
    221                                         ((toprow*)this)->probability += (*integ_ref); 
    222                                 } 
    223                         } 
    224                 }                
    225         } 
     173        void triangulate(bool should_integrate); 
     174         
    226175 
    227176