Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Commit

Permalink
Merge branch 'development' of https://github.com/revbayes/revbayes in…
Browse files Browse the repository at this point in the history
…to development
  • Loading branch information
wf8 committed Feb 22, 2018
2 parents 6bf5af8 + 4c12caa commit 4f579ea
Show file tree
Hide file tree
Showing 94 changed files with 3,776 additions and 644 deletions.
4 changes: 2 additions & 2 deletions src/core/analysis/HillClimber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ bool HillClimber::hasConverged(double min_acceptance_ratio)

for (size_t i=0; i<moves.size() && converged == true; ++i)
{
size_t num_tried = moves[i].getNumberTried();
size_t num_accepted = moves[i].getNumberAccepted();
size_t num_tried = moves[i].getNumberTriedCurrentPeriod();
size_t num_accepted = moves[i].getNumberAcceptedCurrentPeriod();

if ( num_tried > 0)
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/analysis/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Model::Model(const DagNode *source) : Parallelizable()
* The entire model graph is copied and a map between the pointers to the original DAG nodes and
* the copied DAG nodes is created for convenient access.
*
* \param[in] sources The set of DAG nodes from which the model graph is extracted.
* \param[in] s The set of DAG nodes from which the model graph is extracted.
*/
Model::Model(const std::set<const DagNode*> &s) : Parallelizable(),
sources()
Expand Down Expand Up @@ -107,7 +107,7 @@ Model::~Model( void )
* \todo Check that this copy constructor is good or if we should use a different mechanism for the map between the
* original DAG nodes and the copied DAG nodes.
*
* \param[in] m The model object to copy.
* \param[in] x The model object to copy.
*/
Model& Model::operator=(const Model &x)
{
Expand Down
19 changes: 12 additions & 7 deletions src/core/analysis/MonteCarloAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "AbstractFileMonitor.h"
#include "DagNode.h"
#include "MonteCarloAnalysis.h"
#include "MonteCarloSampler.h"
#include "RlUserInterface.h"

#include <algorithm>
Expand All @@ -18,19 +19,22 @@ using namespace RevBayesCore;
*
* \param[in] m The monte carlo sampler.
*/
MonteCarloAnalysis::MonteCarloAnalysis(MonteCarloSampler *m, size_t r) : Cloneable(), Parallelizable(),
replicates( r ),
runs(r,NULL)
MonteCarloAnalysis::MonteCarloAnalysis(MonteCarloSampler *m, size_t r, MonteCarloAnalysisOptions::TraceCombinationTypes tc) : Cloneable(), Parallelizable(),
replicates( r ),
runs(r,NULL),
trace_combination( tc )
{

runs[0] = m;
resetReplicates();

}


MonteCarloAnalysis::MonteCarloAnalysis(const MonteCarloAnalysis &a) : Cloneable(), Parallelizable(a),
replicates( a.replicates ),
runs(a.replicates,NULL)
replicates( a.replicates ),
runs(a.replicates,NULL),
trace_combination( a.trace_combination )
{

// create replicate Monte Carlo samplers
Expand Down Expand Up @@ -84,7 +88,8 @@ MonteCarloAnalysis& MonteCarloAnalysis::operator=(const MonteCarloAnalysis &a)
}
runs = std::vector<MonteCarloSampler*>(a.replicates,NULL);

replicates = a.replicates;
replicates = a.replicates;
trace_combination = a.trace_combination;

// create replicate Monte Carlo samplers
for (size_t i=0; i < replicates; ++i)
Expand Down Expand Up @@ -636,7 +641,7 @@ void MonteCarloAnalysis::run( size_t kIterations, RbVector<StoppingRule> rules,

if ( runs[i] != NULL )
{
runs[i]->finishMonitors( replicates );
runs[i]->finishMonitors( replicates, trace_combination );
}

}
Expand Down
10 changes: 7 additions & 3 deletions src/core/analysis/MonteCarloAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MonteCarloAnalysis_H

#include "Cloneable.h"
#include "MonteCarloSampler.h"
#include "MonteCarloAnalysisOptions.h"
#include "Parallelizable.h"
#include "RbVector.h"
#include "StoppingRule.h"
Expand All @@ -17,6 +17,9 @@

namespace RevBayesCore {

class Model;
class MonteCarloSampler;

/**
* @brief Monte Carlo analysis running and managing the MonteCarloSampler objects.
*
Expand All @@ -32,7 +35,8 @@ namespace RevBayesCore {
class MonteCarloAnalysis : public Cloneable, public Parallelizable {

public:
MonteCarloAnalysis(MonteCarloSampler *m, size_t r);

MonteCarloAnalysis(MonteCarloSampler *m, size_t r, MonteCarloAnalysisOptions::TraceCombinationTypes ct);
MonteCarloAnalysis(const MonteCarloAnalysis &m);
virtual ~MonteCarloAnalysis(void); //!< Virtual destructor

Expand Down Expand Up @@ -63,7 +67,7 @@ namespace RevBayesCore {

size_t replicates;
std::vector<MonteCarloSampler*> runs;

MonteCarloAnalysisOptions::TraceCombinationTypes trace_combination;
};

// Global functions using the class
Expand Down
18 changes: 18 additions & 0 deletions src/core/analysis/MonteCarloAnalysisOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef MonteCarloAnalysisOptions_H
#define MonteCarloAnalysisOptions_H


namespace RevBayesCore {


struct MonteCarloAnalysisOptions {

enum TraceCombinationTypes { NONE, SEQUENTIAL, MIXED };

};


}

#endif

2 changes: 1 addition & 1 deletion src/core/analysis/PowerPosteriorAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void PowerPosteriorAnalysis::runStone(size_t idx, size_t gen)
outStream.close();

// Monitor
sampler->finishMonitors( 1 );
sampler->finishMonitors( 1, MonteCarloAnalysisOptions::NONE );

}

Expand Down
4 changes: 2 additions & 2 deletions src/core/analysis/mcmc/Mcmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Mcmc* Mcmc::clone( void ) const
/**
* Finish the monitors which will close the output streams.
*/
void Mcmc::finishMonitors( size_t n_reps )
void Mcmc::finishMonitors( size_t n_reps, MonteCarloAnalysisOptions::TraceCombinationTypes tc )
{

// iterate over all monitors
Expand All @@ -211,7 +211,7 @@ void Mcmc::finishMonitors( size_t n_reps )
// combine results if we used more than one replicate
if ( n_reps > 1 )
{
monitors[i].combineReplicates( n_reps );
monitors[i].combineReplicates( n_reps, tc );
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/core/analysis/mcmc/Mcmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace RevBayesCore {
void addMonitor(const Monitor &m);
void disableScreenMonitor(bool all, size_t rep); //!< Disable/remove all screen monitors
Mcmc* clone(void) const;
void finishMonitors(size_t n); //!< Finish the monitors
void finishMonitors(size_t n, MonteCarloAnalysisOptions::TraceCombinationTypes ct); //!< Finish the monitors
double getChainLikelihoodHeat(void) const; //!< Get the heat for this chain
double getChainPosteriorHeat(void) const; //!< Get the heat for this chain
size_t getChainIndex(void) const; //!< Get the index of this chain
Expand Down
40 changes: 20 additions & 20 deletions src/core/analysis/mcmc/Mcmcmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
using namespace RevBayesCore;

Mcmcmc::Mcmcmc(const Model& m, const RbVector<Move> &mv, const RbVector<Monitor> &mn, std::string sT, size_t nc, size_t si, double dt, size_t ntries) : MonteCarloSampler(),
num_chains(nc),
schedule_type(sT),
current_generation(0),
swap_interval(si),
active_chain_index( 0 ),
delta( dt ),
generation( 0 ),
numAttemptedSwaps( 0 ),
numAcceptedSwaps( 0 )
num_chains(nc),
schedule_type(sT),
current_generation(0),
swap_interval(si),
active_chain_index( 0 ),
delta( dt ),
generation( 0 ),
num_attempted_swaps( 0 ),
num_accepted_swaps( 0 )
{

// initialize container sizes
Expand Down Expand Up @@ -53,8 +53,8 @@ Mcmcmc::Mcmcmc(const Mcmcmc &m) : MonteCarloSampler(m)
schedule_type = m.schedule_type;
pid_per_chain = m.pid_per_chain;

numAttemptedSwaps = m.numAttemptedSwaps;
numAcceptedSwaps = m.numAcceptedSwaps;
num_attempted_swaps = m.num_attempted_swaps;
num_accepted_swaps = m.num_accepted_swaps;
generation = m.generation;


Expand Down Expand Up @@ -151,7 +151,7 @@ void Mcmcmc::disableScreenMonitor( bool all, size_t rep )
/**
* Start the monitors at the beginning of a run which will simply delegate this call to each chain.
*/
void Mcmcmc::finishMonitors( size_t n_reps )
void Mcmcmc::finishMonitors( size_t n_reps, MonteCarloAnalysisOptions::TraceCombinationTypes tc )
{

// Monitor
Expand All @@ -160,7 +160,7 @@ void Mcmcmc::finishMonitors( size_t n_reps )

if ( chains[i] != NULL )
{
chains[i]->finishMonitors( n_reps );
chains[i]->finishMonitors( n_reps, tc );
}
}

Expand Down Expand Up @@ -407,8 +407,8 @@ void Mcmcmc::reset( void )
{

// reset counters
numAcceptedSwaps = 0;
numAttemptedSwaps = 0;
num_accepted_swaps = 0;
num_attempted_swaps = 0;

// /* Reset the monitors */
// for (size_t i = 0; i < chainsPerProcess[pid].size(); ++i)
Expand Down Expand Up @@ -732,7 +732,7 @@ void Mcmcmc::swapNeighborChains(void)
j = int(GLOBAL_RNG->uniform01() * (num_chains-1));
k = j + 1;

++numAttemptedSwaps;
++num_attempted_swaps;

// compute exchange ratio
double bj = chain_heats[j];
Expand Down Expand Up @@ -813,7 +813,7 @@ void Mcmcmc::swapNeighborChains(void)
}
}

++numAcceptedSwaps;
++num_accepted_swaps;
}


Expand Down Expand Up @@ -850,7 +850,7 @@ void Mcmcmc::swapRandomChains(void)
while(j == k);
}

++numAttemptedSwaps;
++num_attempted_swaps;

// compute exchange ratio
double bj = chain_heats[j];
Expand Down Expand Up @@ -899,7 +899,7 @@ void Mcmcmc::swapRandomChains(void)
heat_ranks[j] = heat_ranks[k];
heat_ranks[k] = tmp;

++numAcceptedSwaps;
++num_accepted_swaps;
}


Expand Down Expand Up @@ -935,7 +935,7 @@ void Mcmcmc::swapRandomChains(void)
void Mcmcmc::tune( void )
{

double rate = numAcceptedSwaps / double(numAttemptedSwaps);
double rate = num_accepted_swaps / double(num_attempted_swaps);

if ( rate > 0.44 )
{
Expand Down
32 changes: 16 additions & 16 deletions src/core/analysis/mcmc/Mcmcmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,35 @@ namespace RevBayesCore {
public:
Mcmcmc(const Model& m, const RbVector<Move> &mv, const RbVector<Monitor> &mn, std::string sT="random", size_t nc=4, size_t si=100, double dt=0.1, size_t ntries=1000);
Mcmcmc(const Mcmcmc &m);
virtual ~Mcmcmc(void); //!< Virtual destructor
virtual ~Mcmcmc(void); //!< Virtual destructor

// public methods
void addFileMonitorExtension(const std::string &s, bool dir);
void addMonitor(const Monitor &m);
void disableScreenMonitor(bool all, size_t rep); //!< Disable/remove all screen monitors
void disableScreenMonitor(bool all, size_t rep); //!< Disable/remove all screen monitors
Mcmcmc* clone(void) const;
void finishMonitors(size_t n); //!< Finish the monitors
void finishMonitors(size_t n, MonteCarloAnalysisOptions::TraceCombinationTypes ct); //!< Finish the monitors
const Model& getModel(void) const;
double getModelLnProbability(bool likelihood_only);
RbVector<Monitor>& getMonitors( void );
std::string getStrategyDescription(void) const; //!< Get the discription of the strategy used for this sampler.
void initializeSampler(bool priorOnly=false); //!< Initialize objects for mcmc sampling
std::string getStrategyDescription(void) const; //!< Get the discription of the strategy used for this sampler.
void initializeSampler(bool priorOnly=false); //!< Initialize objects for mcmc sampling
void monitor(unsigned long g);
void nextCycle(bool advanceCycle);
void printOperatorSummary(void) const;
void redrawStartingValues(void); //!< Redraw the starting values.
void redrawStartingValues(void); //!< Redraw the starting values.
void removeMonitors(void);
void reset(void); //!< Reset the sampler for a new run.
void setLikelihoodHeat(double h); //!< Set the heat of the likelihood function.
void reset(void); //!< Reset the sampler for a new run.
void setLikelihoodHeat(double h); //!< Set the heat of the likelihood function.
void setModel(Model *m, bool redraw);
void setNumberOfProcesses(size_t i); //!< Set the number of processes for this replication.
void startMonitors(size_t numCycles, bool reopen); //!< Start the monitors
void tune(void); //!< Tune the sampler and its moves.
void writeMonitorHeaders(void); //!< Write the headers of the monitors.
void setNumberOfProcesses(size_t i); //!< Set the number of processes for this replication.
void startMonitors(size_t numCycles, bool reopen); //!< Start the monitors
void tune(void); //!< Tune the sampler and its moves.
void writeMonitorHeaders(void); //!< Write the headers of the monitors.


protected:
void setActivePIDSpecialized(size_t i, size_t n); //!< Set the number of processes for this class.
void setActivePIDSpecialized(size_t i, size_t n); //!< Set the number of processes for this class.


private:
Expand All @@ -68,7 +68,7 @@ namespace RevBayesCore {
void synchronizeValues(bool likelihood_only);
void synchronizeHeats(void);
void updateChainState(size_t j);
double computeBeta(double d, size_t i); // incremental temperature schedule
double computeBeta(double d, size_t i); // incremental temperature schedule

size_t num_chains;
std::vector<size_t> heat_ranks;
Expand All @@ -87,8 +87,8 @@ namespace RevBayesCore {
Mcmc* base_chain;

unsigned long generation;
unsigned long numAttemptedSwaps;
unsigned long numAcceptedSwaps;
unsigned long num_attempted_swaps;
unsigned long num_accepted_swaps;
};

}
Expand Down
Loading

0 comments on commit 4f579ea

Please sign in to comment.