void CPDNRigid<Scalar, Dim>::compute()
    {
        size_t iter_num = 0;
        Scalar e_tol = 10 + this->e_tol_;
        Scalar e = 0;
        
        this->normalize();
        initialization();

        /*if (this->_vision)
        {
        RenderThread<Scalar, Dim>::instance()->updateModel(this->model_);
        RenderThread<Scalar, Dim>::instance()->updateData(this->data_);
        RenderThread<Scalar, Dim>::instance()->startThread();
        }*/

        while (iter_num < this->iter_num_ && e_tol > this->e_tol_ && paras_.sigma2_ > 10 * this->v_tol_)
        {

            e_step();
            
            Scalar old_e = e;
            e = energy();
            e += paras_.lambda_/2 * (paras_.W_.transpose()*G_*paras_.W_).trace();
            e_tol = fabs((e - old_e) / e);

            m_step();

            /*if (this->_vision == true)
            RenderThread<Scalar, Dim>::instance()->updateModel(this->T_);*/

            iter_num ++;
        }
        
        correspondences();
        this->updateModel();
        this->denormalize();
        this->rewriteOriginalSource();
        /*RenderThread<Scalar, Dim>::instance()->cancel();*/
    }
    void CPDNRigid<T, D>::run()
    {
        size_t iter_num = 0;
        T e_tol = 10 + _e_tol;
        T e = 0;
        
        normalize();
        initialization();

        if (_vision)
        {
            RenderThread<T, D>::instance()->updateModel(_model);
            RenderThread<T, D>::instance()->updateData(_data);
            RenderThread<T, D>::instance()->startThread();
        }

        while (iter_num < _iter_num && e_tol > _e_tol && _paras._sigma2 > 10 * _v_tol)
        {

            e_step();
            
            T old_e = e;
            e = energy();
            e += _paras._lambda/2 * (_paras._W.transpose()*_G*_paras._W).trace();
            e_tol = abs((e - old_e) / e);

            m_step();

            if (_vision == true)
                RenderThread<T, D>::instance()->updateModel(_T);

            iter_num ++;	
        }
        
        correspondences();
        updateModel();
        denormalize();
        RenderThread<T, D>::instance()->cancel();	
    }
Exemple #3
0
void Kmeans::cluster(const MatrixXdRowMajor& data_points, int k)
{
    init_centroids(data_points,k);
    int i=1;
    tiempo_promedio_iteracion = 0.0;
    tiempo_promedio_e_step = 0.0;
    tiempo_promedio_m_step = 0.0;
    double tiempo_parcial;
    do
    {
        std::cout << "Iteration: " << i++;
        changed_centroids = 0;
        error = 0.0;
        utils.tic("Iteration");
        utils.tic("E");
        #ifdef MIC
            mic_e_step(data_points);
        #else
            e_step(data_points);
        #endif
        tiempo_parcial = utils.toc("E");
        tiempo_promedio_e_step += tiempo_parcial;
        std::cout << "\tE: " << tiempo_parcial << "(" << (tiempo_promedio_e_step/(i-1)) << ")";
        utils.tic("M");
        m_step(data_points);
        tiempo_parcial = utils.toc("M");
        tiempo_promedio_m_step += tiempo_parcial;
        std::cout << "\tM: " << tiempo_parcial << "(" << (tiempo_promedio_m_step/(i-1)) << ")";
        tiempo_parcial = utils.toc("Iteration");
        tiempo_promedio_iteracion += tiempo_parcial;
        std::cout << "\tI: " << tiempo_parcial << "(" << (tiempo_promedio_iteracion/(i-1)) << ")";
        std::cout<<"\tchanged: "<<changed_centroids<<"\terror: "<<error<<std::endl;
    } while (changed_centroids > 0);
    std::cout << "Total Execution time: " << tiempo_promedio_iteracion << std::endl;
    std::cout << "Total E_STEP time: " << tiempo_promedio_e_step << std::endl;
    std::cout << "Total M_STEP time: " << tiempo_promedio_m_step << std::endl;
}