Search in sources :

Example 1 with StateLoader

use of dr.inference.state.StateLoader in project beast-mcmc by beast-dev.

the class MCMC method chain.

/**
 * This method actually initiates the MCMC analysis.
 */
public void chain() {
    stopping = false;
    currentState = 0;
    timer.start();
    if (loggers != null) {
        for (Logger logger : loggers) {
            logger.startLogging();
        }
    }
    if (!stopping) {
        long loadedState = 0;
        if (Factory.INSTANCE != null) {
            StateLoader initialStateLoader = Factory.INSTANCE.getInitialStateLoader();
            if (initialStateLoader != null) {
                double[] savedLnL = new double[1];
                loadedState = initialStateLoader.loadState(mc, savedLnL);
                mc.setCurrentLength(loadedState);
                double lnL = mc.evaluate();
                initialStateLoader.checkLoadState(savedLnL[0], lnL);
            }
        }
        mc.addMarkovChainListener(chainListener);
        long chainLength = getChainLength();
        // this also potentially gets the new adaptationDelay of a possibly increased chain length
        final long adaptationDelay = getAdaptationDelay();
        // System.out.println("adaptationDelay = " + adaptationDelay + " vs. loadedState = " +loadedState);
        if (adaptationDelay > loadedState) {
            mc.runChain(adaptationDelay - loadedState, true);
            chainLength -= adaptationDelay;
            for (int i = 0; i < schedule.getOperatorCount(); i++) {
                schedule.getOperator(i).reset();
            }
        }
        mc.runChain(chainLength, false);
        mc.terminateChain();
        mc.removeMarkovChainListener(chainListener);
    }
    timer.stop();
}
Also used : StateLoader(dr.inference.state.StateLoader) Logger(dr.inference.loggers.Logger)

Aggregations

Logger (dr.inference.loggers.Logger)1 StateLoader (dr.inference.state.StateLoader)1