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 );
}
Exemplo n.º 2
0
RevPtr<RevVariable> Func_Mcmc::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                                                     nreps   = static_cast<const Natural &>( args[4].getVariable()->getRevObject() ).getValue();
    RevBayesCore::Mcmc *m = new RevBayesCore::Mcmc(mdl, mvs, mntr);
    m->setScheduleType( sched );
    RevBayesCore::MonteCarloAnalysis *a = new RevBayesCore::MonteCarloAnalysis(m,nreps);
    
    return new RevVariable( new MonteCarloAnalysis( a ) );
}