Beispiel #1
0
void HillClimber::constructInternalObject( void )
{
    // we free the memory first
    delete value;
    
    const RevBayesCore::Model&                              mdl     = static_cast<const Model &>( model->getRevObject() ).getValue();
    const WorkspaceVector<Monitor> &                        ws_vec_mntr = static_cast<const WorkspaceVector<Monitor> &>( monitors->getRevObject() );
    RevBayesCore::RbVector<RevBayesCore::Monitor>           mntr;
    for ( size_t i = 0; i < ws_vec_mntr.size(); ++i )
    {
        mntr.push_back( ws_vec_mntr[i].getValue() );
    }
    const WorkspaceVector<Move>&                            ws_vec_mvs = static_cast<const WorkspaceVector<Move> &>( moves->getRevObject() );
    RevBayesCore::RbVector<RevBayesCore::Move>              mvs;
    for ( size_t i = 0; i < ws_vec_mvs.size(); ++i )
    {
        mvs.push_back( ws_vec_mvs[i].getValue() );
    }
    const std::string &                                     sched   = static_cast<const RlString &>( moveschedule->getRevObject() ).getValue();
    
    RevBayesCore::HillClimber *m = new RevBayesCore::HillClimber(mdl, mvs, mntr);
    m->setScheduleType( sched );
    
    value = new RevBayesCore::MaximumLikelihoodAnalysis(m);
    
}
Beispiel #2
0
RevPtr<RevVariable> Func_Mcmcmc::execute( void )
{
    
    const RevBayesCore::Model&                              mdl     = static_cast<const Model &>( args[0].getVariable()->getRevObject() ).getValue();
    const WorkspaceVector<Monitor> &                        ws_vec_mntr = static_cast<const WorkspaceVector<Monitor> &>( args[1].getVariable()->getRevObject() );
    RevBayesCore::RbVector<RevBayesCore::Monitor>           mntr;
    for ( size_t i = 0; i < ws_vec_mntr.size(); ++i )
    {
        mntr.push_back( ws_vec_mntr[i].getValue() );
    }
    const WorkspaceVector<Move>&                            ws_vec_mvs = static_cast<const WorkspaceVector<Move> &>( args[2].getVariable()->getRevObject() );
    RevBayesCore::RbVector<RevBayesCore::Move>              mvs;
    for ( size_t i = 0; i < ws_vec_mvs.size(); ++i )
    {
        mvs.push_back( ws_vec_mvs[i].getValue() );
    }
    const std::string &                                     sched   = static_cast<const RlString &>( args[3].getVariable()->getRevObject() ).getValue();
    int                                                     nchains = static_cast<const Natural &>( args[4].getVariable()->getRevObject() ).getValue();
    int                                                     si      = static_cast<const Natural &>( args[5].getVariable()->getRevObject() ).getValue();
    double                                                  delta   = static_cast<const RealPos &>( args[6].getVariable()->getRevObject() ).getValue();
    int                                                     nreps   = static_cast<const Natural &>( args[7].getVariable()->getRevObject() ).getValue();
    RevBayesCore::Mcmcmc *m = new RevBayesCore::Mcmcmc(mdl, mvs, mntr, sched, nchains, si, delta);
//    m->setScheduleType( sched );

    RevBayesCore::MonteCarloAnalysis *a = new RevBayesCore::MonteCarloAnalysis(m,nreps);
    
    return new RevVariable( new MonteCarloAnalysis( a ) );
}
void PowerPosteriorAnalysis::constructInternalObject( void )
{
    // we free the memory first
    delete value;

    // now allocate a new sliding move
    const RevBayesCore::Model&                      mdl     = static_cast<const Model &>( model->getRevObject() ).getValue();
    const WorkspaceVector<Move>&                    rlmvs   = static_cast<const WorkspaceVector<Move> &>( moves->getRevObject() );
    const WorkspaceVector<Monitor>&                 rlmntr  = static_cast<const WorkspaceVector<Monitor> &>( monitors->getRevObject() );
    RevBayesCore::RbVector<RevBayesCore::Monitor>   mntr;
    for ( size_t i = 0; i < rlmntr.size(); ++i )
    {
        mntr.push_back( rlmntr[i].getValue() );
    }
    RevBayesCore::RbVector<RevBayesCore::Move>      mvs;
    for ( size_t i = 0; i < rlmvs.size(); ++i )
    {
        mvs.push_back( rlmvs[i].getValue() );
    }
    const std::string&                              fn      = static_cast<const RlString &>( filename->getRevObject() ).getValue();
    const double                                    alpha   = static_cast<const RealPos &>( alphaVal->getRevObject() ).getValue();
    const int                                       sf      = static_cast<const Natural &>( sampFreq->getRevObject() ).getValue();
    const int                                       k       = static_cast<const Natural &>( proc_per_lik->getRevObject() ).getValue();

    RevBayesCore::Mcmc *m = new RevBayesCore::Mcmc(mdl, mvs, mntr);
    m->setScheduleType( "random" );

    value = new RevBayesCore::PowerPosteriorAnalysis( m, fn, size_t(k) );

    std::vector<double> beta;
    if ( powers->getRevObject() != RevNullObject::getInstance() )
    {
        beta = static_cast<const ModelVector<RealPos> &>( powers->getRevObject() ).getValue();
    }
    else
    {
        int k = static_cast<const Natural &>( cats->getRevObject() ).getValue();
        for (int i = k; i >= 0; --i)
        {
            double b = RevBayesCore::RbStatistics::Beta::quantile(alpha,1.0,i / double(k));
            beta.push_back( b );
        }
    }

    value->setPowers( beta );
    value->setSampleFreq( sf );
}
Beispiel #4
0
/* Map calls to member methods */
RevPtr<RevVariable> RlAtlas::executeMethod(std::string const &name, const std::vector<Argument> &args, bool &found)
{
    
    if (name == "nAreas")
    {
        found = true;
        
        return new RevVariable(new Natural((int)this->dagNode->getValue().getNumAreas())) ;
    }
    else if (name == "nEpochs")
    {
        found = true;
        
        return new RevVariable(new Natural((int)this->dagNode->getValue().getNumEpochs())) ;
    }
    else if (name == "names")
    {
        found = true;
        
        ModelVector<RlString> *n = new ModelVector<RlString>();
        const std::vector<std::vector<RevBayesCore::GeographicArea*> >& areas = this->dagNode->getValue().getAreas();
        for (size_t i = 0; i < areas[0].size(); ++i)
        {
            std::string name = areas[0][i]->getName();
            n->push_back( name );
        }
        return new RevVariable( n );
    }
    else if (name == "epochTimes")
    {
        found = true;
        ModelVector<RealPos> *n = new ModelVector<RealPos>( this->dagNode->getValue().getEpochs() );
        return new RevVariable( n );
    }
    else if (name == "getValues")
    {
        found = true;
        
        // get the member with give index
        std::string value = static_cast<const RlString &>( args[0].getVariable()->getRevObject() ).getValue();
        std::vector<std::vector<RevBayesCore::GeographicArea*> > areas = this->dagNode->getValue().getAreas();        
        ModelVector<ModelVector<ModelVector<Real > > > *f = new ModelVector<ModelVector<ModelVector<Real > > >();
        for (size_t i = 0; i < areas.size(); i++)
        {
            RevBayesCore::RbVector<RevBayesCore::RbVector<double> > v;
            for (size_t j = 0; j < areas[i].size(); j++)
            {
                if (value == "dispersal")
                    v.push_back(areas[i][j]->getDispersalValues());
                else if (value == "dispersal-upper")
                    v.push_back(areas[i][j]->getDispersalValues());
                else if (value == "extinction")
                    v.push_back(areas[i][j]->getExtinctionValues());
                else if (value == "latlon")
                    v.push_back(areas[i][j]->getLatlon());
                else if (value == "altitude")
                    v.push_back( RevBayesCore::RbVector<double>(1, areas[i][j]->getAltitude()) );
                else if (value == "size")
                    v.push_back( RevBayesCore::RbVector<double>(1, areas[i][j]->getSize()) );
            }
            f->push_back( ModelVector<ModelVector<Real> >(v) );
        }
        return new RevVariable(f);
    }
    
    return ModelObject<RevBayesCore::TimeAtlas>::executeMethod( name, args, found );
}