Exemplo n.º 1
0
void TraceNumeric::computeStatistics( void )
{
    
    // check if we need to set the burnin
    if ( burnin == RbConstants::Size_t::nan )
    {
        burnin = size();
        burnin *= stepSize;
        burnin = (size_t)(burnin * 0.1);
    }
    
    TraceAnalysisContinuous* analysis = new TraceAnalysisContinuous();
    analysis->analyseCorrelation(values, burnin);
    ess = analysis->getEss();
    mean = analysis->getMean();
    sem = analysis->getStdErrorOfMean();
    
    
    
    // test stationarity within chain
    size_t nBlocks = 10;
    StationarityTest testS = StationarityTest(nBlocks, 0.01);
    passedStationarityTest = testS.assessConvergenceSingleChain(values, burnin);
    
    // Geweke's test for convergence within a chain
    GewekeTest testG = GewekeTest(0.01);
    passedGewekeTest = testG.assessConvergenceSingleChain(values, burnin);
        
}
Exemplo n.º 2
0
/**
 * Should we stop now?
 * Yes, if the minimum ESS is larger than the provided threshold.
 */
bool GewekeStoppingRule::stop( size_t g )
{
    
    bool passed = true;
    
    for ( size_t i = 1; i <= numReplicates; ++i)
    {
        std::string fn = filename;
        if ( numReplicates > 1 )
        {
            RbFileManager fm = RbFileManager(filename);
            fn = fm.getFilePath() + fm.getPathSeparator() + fm.getFileNameWithoutExtension() + "_run_" + StringUtilities::to_string(i) + "." + fm.getFileExtension();
        }
        
        TraceContinuousReader reader = TraceContinuousReader( fn );
        
        // get the vector of traces from the reader
        std::vector<Trace> &data = reader.getTraces();
        
        size_t maxBurnin = 0;
        
        for ( size_t j = 0; j < data.size(); ++j)
        {
            Trace &t = data[j];
            const std::vector<double> &v = t.getValues();
            size_t b = burninEst->estimateBurnin( v );
            if ( maxBurnin < b )
            {
                maxBurnin = b;
            }
        }
        
        GewekeTest gTest = GewekeTest( alpha, frac1, frac2 );
        
        for ( size_t j = 0; j < data.size(); ++j)
        {
            RevBayesCore::Trace &t = data[j];
            const std::vector<double> &v = t.getValues();
            t.setBurnin( maxBurnin );
            t.computeStatistics();
            
            passed &= gTest.assessConvergenceSingleChain( v, maxBurnin );
        }
        
    }
    
    
    return passed;
}