Changeset 1242 for applications/robust

Show
Ignore:
Timestamp:
10/31/10 08:59:04 (14 years ago)
Author:
sindj
Message:

Rozdelani vypoctu. JS

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/robustlib.h

    r1234 r1242  
    170170        } 
    171171 
    172         void triangulate() 
     172        void triangulate(bool should_integrate) 
    173173        {                
    174174                for(list<polyhedron*>::iterator child_ref = children.begin();child_ref!=children.end();child_ref++) 
    175175                { 
     176                        set<double> simplex_integrals; 
     177                         
    176178                        for(list<set<vertex*>>::iterator t_ref = (*child_ref)->triangulation.begin();t_ref!=(*child_ref)->triangulation.end();t_ref++) 
    177179                        { 
     
    184186                                { 
    185187                                        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                                        } 
    186212                                }  
     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                                } 
    187223                        } 
    188224                }                
     
    245281         
    246282public: 
     283        double probability; 
     284 
    247285        /// A condition used for determining the function of a Laplace-Inverse-Gamma density resulting from Bayesian estimation 
    248286        vec condition; 
    249287 
     288        int condition_order; 
     289 
    250290        /// Default constructor 
    251291        toprow(){}; 
    252292 
    253293        /// Constructor creating a toprow from the condition 
    254         toprow(vec condition) 
    255         { 
    256                 this->condition = condition; 
    257         } 
     294        toprow(vec condition, int condition_order) 
     295        { 
     296                this->condition       = condition; 
     297                this->condition_order = condition_order; 
     298        }        
    258299 
    259300}; 
     
    587628                                                        else 
    588629                                                        { 
     630                                                                ((toprow*)current_parent)->condition_order++; 
     631 
    589632                                                                if(current_parent->negativechildren.size()>0) 
    590633                                                                { 
    591634                                                                        current_parent->set_state(-1, SPLIT); 
    592635 
    593                                                                         ((toprow*)current_parent)->condition-=toadd; 
     636                                                                        ((toprow*)current_parent)->condition-=toadd;                                                             
     637 
    594638                                                                } 
    595639                                                                else if(current_parent->positivechildren.size()>0) 
     
    597641                                                                        current_parent->set_state(1, SPLIT); 
    598642 
    599                                                                         ((toprow*)current_parent)->condition+=toadd; 
     643                                                                        ((toprow*)current_parent)->condition+=toadd;                                                                     
    600644                                                                } 
    601645                                                                else 
     
    673717 
    674718        void remove_condition(vec toremove) 
    675         { 
     719        {                
    676720                vec null_vector = ""; 
    677721 
     
    841885                                        } 
    842886 
    843                                         toprow* positive_poly = new toprow(((toprow*)current_polyhedron)->condition+toadd); 
    844                                         toprow* negative_poly = new toprow(((toprow*)current_polyhedron)->condition-toadd); 
     887                                        toprow* positive_poly = new toprow(((toprow*)current_polyhedron)->condition+toadd, ((toprow*)current_polyhedron)->condition_order+1); 
     888                                        toprow* negative_poly = new toprow(((toprow*)current_polyhedron)->condition-toadd, ((toprow*)current_polyhedron)->condition_order+1); 
    845889 
    846890                                        for(list<polyhedron*>::iterator parent_ref = current_polyhedron->parents.begin();parent_ref!=current_polyhedron->parents.end();parent_ref++) 
     
    897941                                        negative_poly->vertices.insert(new_totally_neutral_child->vertices.begin(),new_totally_neutral_child->vertices.end()); 
    898942 
    899                                         new_totally_neutral_child->triangulate(); 
    900  
    901                                         positive_poly->triangulate(); 
    902                                         negative_poly->triangulate(); 
     943                                        new_totally_neutral_child->triangulate(false); 
     944 
     945                                        positive_poly->triangulate(k==for_splitting.size()-1); 
     946                                        negative_poly->triangulate(k==for_splitting.size()-1); 
    903947 
    904948                                        statistic.append_polyhedron(k-1, new_totally_neutral_child); 
     
    10581102 
    10591103                                        // We create a new toprow with the previously specified condition. 
    1060                                         toprow* current_copy1 = new toprow(vec1); 
    1061                                         toprow* current_copy2 = new toprow(vec2);                                        
     1104                                        toprow* current_copy1 = new toprow(vec1, 0); 
     1105                                        toprow* current_copy2 = new toprow(vec2, 0);                                     
    10621106 
    10631107                                        // The vertices of the copies will be inherited, because there will be a parent/child relation