bpp-phyl  2.2.0
SSR.cpp
Go to the documentation of this file.
1 //
2 // File: SSR.cpp
3 // Created by: Julien Dutheil
4 // Created on: Tue Nov 4 11:46 2008
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #include "SSR.h"
41 
42 #include <Bpp/Numeric/Matrix/MatrixTools.h>
43 
44 // From SeqLib:
45 #include <Bpp/Seq/Container/SequenceContainerTools.h>
46 
47 // From the STL:
48 #include <cmath>
49 
50 using namespace bpp;
51 using namespace std;
52 
53 /******************************************************************************/
54 
56  const NucleicAlphabet* alpha,
57  double beta,
58  double gamma,
59  double delta,
60  double theta):
61  AbstractParameterAliasable("SSR."),
62  AbstractReversibleSubstitutionModel(alpha, new CanonicalStateMap(alpha, false), "SSR."),
63  beta_(beta), gamma_(gamma), delta_(delta), theta_(theta),
64  piA_((1. - theta) / 2.), piC_(theta / 2.), piG_(theta / 2.), piT_((1. - theta) / 2.)
65 {
66  addParameter_(new Parameter("SSR.beta" , beta , &Parameter::R_PLUS_STAR));
67  addParameter_(new Parameter("SSR.gamma", gamma, &Parameter::R_PLUS_STAR));
68  addParameter_(new Parameter("SSR.delta", delta, &Parameter::R_PLUS_STAR));
69  addParameter_(new Parameter("SSR.theta" , theta , &Parameter::PROP_CONSTRAINT_EX));
71 }
72 
73 /******************************************************************************/
74 
76 {
77  beta_ = getParameterValue("beta");
78  gamma_ = getParameterValue("gamma");
79  delta_ = getParameterValue("delta");
80  theta_ = getParameterValue("theta");
81 
82  freq_[0] = piA_ = (1. - theta_)/2.;
83  freq_[1] = piC_ = theta_/2.;
84  freq_[2] = piG_ = theta_/2;
85  freq_[3] = piT_ = (1. - theta_)/2.;
86 
87  // Exchangeability matrix:
89  exchangeability_(1,0) = beta_;
90  exchangeability_(0,1) = beta_;
91  exchangeability_(2,0) = 1.;
92  exchangeability_(0,2) = 1.;
93  exchangeability_(3,0) = gamma_;
94  exchangeability_(0,3) = gamma_;
96  exchangeability_(1,2) = delta_;
97  exchangeability_(2,1) = delta_;
98  exchangeability_(1,3) = 1.;
99  exchangeability_(3,1) = 1.;
101  exchangeability_(2,3) = beta_;
102  exchangeability_(3,2) = beta_;
104 
106 }
107 
108 /******************************************************************************/
109 
110 void SSR::setFreq(map<int, double>& freqs)
111 {
112  piC_ = freqs[1];
113  piG_ = freqs[2];
114  setParameterValue("theta",piC_ + piG_);
115  updateMatrices();
116 }
117 
118 /******************************************************************************/
119 
double beta_
Definition: SSR.h:103
RowMatrix< double > exchangeability_
The exchangeability matrix of the model, defined as . When the model is reversible, this matrix is symetric.
double piA_
Definition: SSR.h:103
This class implements a state map where all resolved states are modeled.
Definition: StateMap.h:161
STL namespace.
Vdouble freq_
The vector of equilibrium frequencies.
double piG_
Definition: SSR.h:103
double gamma_
Definition: SSR.h:103
void setFreq(std::map< int, double > &)
This method is redefined to actualize the corresponding parameters theta too.
Definition: SSR.cpp:110
virtual void updateMatrices()
Compute and diagonalize the matrix, and fill the eigenValues_, leftEigenVectors_ and rightEigenVecto...
double theta_
Definition: SSR.h:103
Partial implementation of the ReversibleSubstitutionModel interface.
double piT_
Definition: SSR.h:103
double delta_
Definition: SSR.h:103
void updateMatrices()
Compute and diagonalize the matrix, and fill the eigenValues_, leftEigenVectors_ and rightEigenVecto...
Definition: SSR.cpp:75
SSR(const NucleicAlphabet *alpha, double beta=1., double gamma=1., double delta=1., double theta=0.5)
Definition: SSR.cpp:55
double piC_
Definition: SSR.h:103