Creating an ExchangeabilityUpdater
is as easy as creating the StateFreqUpdater
(in fact, the two classes are almost identical).
Create a new header file named exchangeability_updater.hpp and fill it with the following.
#pragma once
#include "dirichlet_updater.hpp"
namespace strom {
class ExchangeabilityUpdater : public DirichletUpdater {
public:
typedef std::shared_ptr< ExchangeabilityUpdater > SharedPtr;
ExchangeabilityUpdater(QMatrix::SharedPtr qmatrix);
~ExchangeabilityUpdater();
private:
void pullFromModel();
void pushToModel();
QMatrix::SharedPtr _qmatrix;
};
// member function bodies go here
}
The constructor first calls the clear
function defined by the DirichletUpdater
base class. It then sets its _name
to “Exchangeabilities” and its _qmatrix
data member to the shared pointer qmatrix
supplied as an argument. This points to the QMatrix
object that manages the exchangeabilities that this class will update. The destructor is merely a placeholder, as usual.
inline ExchangeabilityUpdater::ExchangeabilityUpdater(QMatrix::SharedPtr qmatrix) {
// std::cout << "Creating an ExchangeabilityUpdater" << std::endl;
DirichletUpdater::clear();
_name = "Exchangeabilities";
assert(qmatrix);
_qmatrix = qmatrix;
}
inline ExchangeabilityUpdater::~ExchangeabilityUpdater() {
// std::cout << "Destroying an ExchangeabilityUpdater" << std::endl;
}
The pullFromModel
function first obtains a shared pointer to the exchangeabilities vector of the QMatrix
object pointed to by _qmatrix
. It then copies those exchangeabilities into the _curr_point
vector. The pushToModel
function copies the values from _curr_point
to the model via the setExchangeabilities
member function of QMatrix
, which handles recalculation of the instantaneous rate matrix and the corresponding eigen decomposition using the new exchangeabilities.
inline void ExchangeabilityUpdater::pullFromModel() {
QMatrix::freq_xchg_ptr_t xchg = _qmatrix->getExchangeabilitiesSharedPtr();
_curr_point.assign(xchg->begin(), xchg->end());
}
inline void ExchangeabilityUpdater::pushToModel() {
_qmatrix->setExchangeabilities(_curr_point);
}