bpp-phyl  2.1.0
Bpp/Phyl/Model/AbstractBiblioSubstitutionModel.h
Go to the documentation of this file.
00001 //
00002 // File: AbstractBiblioSubstitutionModel.h
00003 // Created by: Laurent Guéguen
00004 // Created on: vendredi 8 juillet 2011, à 20h 17
00005 //
00006 
00007 /*
00008    Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
00009 
00010    This software is a computer program whose purpose is to provide classes
00011    for phylogenetic data analysis.
00012 
00013    This software is governed by the CeCILL  license under French law and
00014    abiding by the rules of distribution of free software.  You can  use,
00015    modify and/ or redistribute the software under the terms of the CeCILL
00016    license as circulated by CEA, CNRS and INRIA at the following URL
00017    "http://www.cecill.info".
00018 
00019    As a counterpart to the access to the source code and  rights to copy,
00020    modify and redistribute granted by the license, users are provided only
00021    with a limited warranty  and the software's author,  the holder of the
00022    economic rights,  and the successive licensors  have only  limited
00023    liability.
00024 
00025    In this respect, the user's attention is drawn to the risks associated
00026    with loading,  using,  modifying and/or developing or reproducing the
00027    software by the user in light of its specific status of free software,
00028    that may mean  that it is complicated to manipulate,  and  that  also
00029    therefore means  that it is reserved for developers  and  experienced
00030    professionals having in-depth computer knowledge. Users are therefore
00031    encouraged to load and test the software's suitability as regards their
00032    requirements in conditions enabling the security of their systems and/or
00033    data to be ensured and,  more generally, to use and operate it in the
00034    same conditions as regards security.
00035 
00036    The fact that you are presently reading this means that you have had
00037    knowledge of the CeCILL license and that you accept its terms.
00038  */
00039 
00040 #ifndef _ABSTRACTBIBLIOSUBSTITUTIONMODEL_H_
00041 #define _ABSTRACTBIBLIOSUBSTITUTIONMODEL_H_
00042 
00043 #include "SubstitutionModel.h"
00044 #include "AbstractSubstitutionModel.h"
00045 
00046 #include <Bpp/Numeric/AbstractParameterAliasable.h>
00047 
00048 namespace bpp
00049 {
00057 class AbstractBiblioSubstitutionModel :
00058   public virtual SubstitutionModel,
00059   public AbstractParameterAliasable
00060 {
00061 protected:
00068   std::map<std::string, std::string> mapParNamesFromPmodel_;
00069 
00070   ParameterList lParPmodel_;
00071 
00072 public:
00073   AbstractBiblioSubstitutionModel(const std::string& prefix);
00074 
00075   AbstractBiblioSubstitutionModel(const AbstractBiblioSubstitutionModel& model);
00076 
00077   AbstractBiblioSubstitutionModel& operator=(const AbstractBiblioSubstitutionModel& model);
00078 
00079   virtual ~AbstractBiblioSubstitutionModel() {}
00080 
00081 #ifndef NO_VIRTUAL_COV
00082   virtual AbstractBiblioSubstitutionModel* clone() const = 0;
00083 #endif
00084 
00085 public:
00086   virtual const SubstitutionModel& getModel() const = 0;
00087 
00088   /*
00089      *@ brief Methods to supersede SubstitutionModel methods.
00090    *
00091    * @{
00092    */
00093 
00094   const std::vector<int>& getAlphabetChars() const { return getModel().getAlphabetChars(); }
00095 
00096   int getAlphabetChar(size_t i) const { return getModel().getAlphabetChar(i); }
00097 
00098   std::vector<size_t> getModelStates(int i) const { return getModel().getModelStates(i); }
00099 
00100   virtual double freq(size_t i) const { return getModel().freq(i); }
00101 
00102   virtual double Qij(size_t i, size_t j) const { return getModel().Qij(i, j); }
00103 
00104   virtual double Pij_t    (size_t i, size_t j, double t) const { return getModel().Pij_t(i, j, t); }
00105   virtual double dPij_dt  (size_t i, size_t j, double t) const { return getModel().dPij_dt (i, j, t); }
00106   virtual double d2Pij_dt2(size_t i, size_t j, double t) const { return getModel().d2Pij_dt2(i, j, t); }
00107 
00108   virtual const Vdouble& getFrequencies() const { return getModel().getFrequencies(); }
00109 
00110   const Matrix<double>& getGenerator() const { return getModel().getGenerator(); }
00111 
00112   const Matrix<double>& getExchangeabilityMatrix() const { return getModel().getExchangeabilityMatrix(); }
00113 
00114   double Sij(size_t i, size_t j) const { return getModel().Sij(i, j); }
00115 
00116   const Matrix<double>& getPij_t(double t) const { return getModel().getPij_t(t); }
00117 
00118   const Matrix<double>& getdPij_dt(double t) const { return getModel().getdPij_dt(t); }
00119 
00120   const Matrix<double>& getd2Pij_dt2(double t) const { return getModel().getd2Pij_dt2(t); }
00121 
00122   void enableEigenDecomposition(bool yn) { getModel().enableEigenDecomposition(yn); }
00123 
00124   bool enableEigenDecomposition() { return getModel().enableEigenDecomposition(); }
00125 
00126   bool isDiagonalizable() const { return getModel().isDiagonalizable(); }
00127 
00128   bool isNonSingular() const { return getModel().isNonSingular(); }
00129 
00130   const Vdouble& getEigenValues() const { return getModel().getEigenValues(); }
00131 
00132   const Vdouble& getIEigenValues() const { return getModel().getIEigenValues(); }
00133 
00134   const Matrix<double>& getRowLeftEigenVectors() const { return getModel().getRowLeftEigenVectors(); }
00135   const Matrix<double>& getColumnRightEigenVectors() const { return getModel().getColumnRightEigenVectors(); }
00136 
00137   double getRate() const { return getModel().getRate(); }
00138 
00139   void setRate(double rate) { return getModel().setRate(rate); }
00140 
00141   void addRateParameter();
00142 
00143   void setFreqFromData(const SequenceContainer& data, double pseudoCount = 0);
00144 
00145   void setFreq(std::map<int, double>& frequ);
00146 
00147   const Alphabet* getAlphabet() const { return getModel().getAlphabet(); }
00148 
00149   size_t getNumberOfStates() const { return getModel().getNumberOfStates(); }
00150 
00151   double getInitValue(size_t i, int state) const throw (BadIntException) { return getModel().getInitValue(i, state); }
00152 
00153   const FrequenciesSet* getFrequenciesSet() const {return getModel().getFrequenciesSet(); }
00154 
00155   /*
00156    * @}
00157    *
00158    */
00159 
00160   /*
00161      *@ brief Methods to supersede AbstractSubstitutionModel methods.
00162    *
00163    * @{
00164    */
00165 
00171   virtual void fireParameterChanged(const ParameterList& parameters)
00172   {
00173     AbstractParameterAliasable::fireParameterChanged(parameters);
00174     if (parameters.size() > 1 || (parameters.size() == 1 && parameters[0].getName() != getNamespace() + "rate")) {
00175       updateMatrices();
00176     }
00177   }
00178 
00179 protected:
00180   virtual void updateMatrices();
00181   virtual SubstitutionModel& getModel() = 0;
00182 
00183 public:
00184   double getScale() const { return getModel().getScale(); }
00185 
00186   void setScale(double scale) { getModel().setScale(scale); }
00187 
00188   /*
00189    * @}
00190    */
00191 };
00192 } // end of namespace bpp.
00193 
00194 
00195 #endif  // _ABSTRACTBIBLIOSUBSTITUTIONMODEL_H_
00196 
 All Classes Namespaces Files Functions Variables Typedefs Friends