16.3 The ExchangeabilityUpdater Class

(Linux version)

< 16.2 | 16.3 | 16.4 >

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&lt; ExchangeabilityUpdater &gt; SharedPtr;

                                            ExchangeabilityUpdater(QMatrix::SharedPtr qmatrix);
                                            ~ExchangeabilityUpdater();
        
        private:
        
            void                            pullFromModel();
            void                            pushToModel();

            QMatrix::SharedPtr              _qmatrix;
        };

    // member function bodies go here
    
}   

Constructor and destructor

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 &lt;&lt; "Creating an ExchangeabilityUpdater" &lt;&lt; std::endl;
        DirichletUpdater::clear();
        _name = "Exchangeabilities";
        assert(qmatrix);
        _qmatrix = qmatrix;
    }

    inline ExchangeabilityUpdater::~ExchangeabilityUpdater() {
        // std::cout &lt;&lt; "Destroying an ExchangeabilityUpdater" &lt;&lt; std::endl;
    }   

The pullFromModel and pushToModel member functions

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-&gt;getExchangeabilitiesSharedPtr();
        _curr_point.assign(xchg-&gt;begin(), xchg-&gt;end());
    }
    
    inline void ExchangeabilityUpdater::pushToModel() {
        _qmatrix-&gt;setExchangeabilities(_curr_point);
    }   

< 16.2 | 16.3 | 16.4 >