bpp-phyl
2.1.0
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Friends
Pages
MarkovModulatedSubstitutionModel.h
Go to the documentation of this file.
1
//
2
// File: MarkovModulatedSubstitutionModel.h
3
// Created by: Julien Dutheil
4
// Created on: Sat Aug 05 08:21 2006
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
#ifndef _MARKOVMODULATEDSUBSTITUTIONMODEL_H_
41
#define _MARKOVMODULATEDSUBSTITUTIONMODEL_H_
42
43
#include "
SubstitutionModel.h
"
44
45
#include <
Bpp/Numeric/AbstractParameterAliasable.h
>
46
#include <
Bpp/Numeric/Matrix/MatrixTools.h
>
47
48
namespace
bpp
49
{
50
75
class
MarkovModulatedSubstitutionModel
:
76
public
virtual
ReversibleSubstitutionModel
,
77
public
AbstractParameterAliasable
78
{
79
80
protected
:
81
ReversibleSubstitutionModel
*
model_
;
82
size_t
nbStates_
;
//Number of states in model
83
size_t
nbRates_
;
//Number of rate classes
84
91
RowMatrix<double>
rates_
;
//All rates values
92
RowMatrix<double>
ratesExchangeability_
;
//All rates transitions
93
Vdouble
ratesFreq_
;
//All rates equilibrium frequencies
95
RowMatrix<double>
ratesGenerator_
;
//All rates transitions
96
100
std::vector<int>
chars_
;
101
105
RowMatrix<double>
generator_
;
106
110
RowMatrix<double>
exchangeability_
;
111
115
RowMatrix<double>
leftEigenVectors_
;
116
120
RowMatrix<double>
rightEigenVectors_
;
121
125
Vdouble
eigenValues_
;
126
131
Vdouble
iEigenValues_
;
132
136
bool
eigenDecompose_
;
137
141
mutable
RowMatrix<double>
pijt_
;
142
mutable
RowMatrix<double>
dpijt_
;
143
mutable
RowMatrix<double>
d2pijt_
;
144
148
Vdouble
freq_
;
149
150
bool
normalizeRateChanges_
;
151
152
std::string
nestedPrefix_
;
153
154
public
:
164
MarkovModulatedSubstitutionModel
(
ReversibleSubstitutionModel
* model,
bool
normalizeRateChanges,
const
std::string& prefix) :
165
AbstractParameterAliasable
(prefix),
166
model_
(model),
nbStates_
(model->
getNumberOfStates
()),
nbRates_
(0),
rates_
(),
ratesExchangeability_
(),
167
ratesFreq_
(),
ratesGenerator_
(),
chars_
(),
generator_
(),
exchangeability_
(),
168
leftEigenVectors_
(),
rightEigenVectors_
(),
eigenValues_
(),
iEigenValues_
(),
eigenDecompose_
(true),
169
pijt_
(),
dpijt_
(),
d2pijt_
(),
freq_
(),
170
normalizeRateChanges_
(normalizeRateChanges),
171
nestedPrefix_
(
"model_"
+ model->
getNamespace
())
172
{
173
model_
->setNamespace(prefix +
nestedPrefix_
);
174
addParameters_
(
model_
->
getIndependentParameters
());
175
}
176
177
MarkovModulatedSubstitutionModel
(
const
MarkovModulatedSubstitutionModel
& model);
178
MarkovModulatedSubstitutionModel
&
operator=
(
const
MarkovModulatedSubstitutionModel
& model);
179
180
virtual
~MarkovModulatedSubstitutionModel
() {
delete
model_
; }
181
182
#ifndef NO_VIRTUAL_COV
183
MarkovModulatedSubstitutionModel
*
184
#else
185
Clonable
*
186
#endif
187
clone
()
const
= 0;
188
189
public
:
190
191
const
Alphabet
*
getAlphabet
()
const
{
return
model_
->
getAlphabet
(); }
192
193
size_t
getNumberOfStates
()
const
{
return
nbStates_
*
nbRates_
; }
194
195
const
Vdouble
&
getFrequencies
()
const
{
return
freq_
; }
196
197
const
Matrix<double>
&
getExchangeabilityMatrix
()
const
{
return
exchangeability_
; }
198
199
const
Matrix<double>
&
getGenerator
()
const
{
return
generator_
; }
200
201
const
Matrix<double>
&
getPij_t
(
double
t)
const
;
202
const
Matrix<double>
&
getdPij_dt
(
double
t)
const
;
203
const
Matrix<double>
&
getd2Pij_dt2
(
double
t)
const
;
204
205
const
Vdouble
&
getEigenValues
()
const
{
return
eigenValues_
; }
206
const
Vdouble
&
getIEigenValues
()
const
{
return
iEigenValues_
; }
207
208
bool
isDiagonalizable
()
const
{
return
true
; }
209
bool
isNonSingular
()
const
{
return
true
; }
210
211
const
Matrix<double>
&
getRowLeftEigenVectors
()
const
{
return
leftEigenVectors_
; }
212
const
Matrix<double>
&
getColumnRightEigenVectors
()
const
{
return
rightEigenVectors_
; }
213
214
double
freq
(
size_t
i)
const
{
return
freq_
[i]; }
215
double
Sij
(
size_t
i,
size_t
j)
const
{
return
exchangeability_
(i, j); }
216
double
Qij
(
size_t
i,
size_t
j)
const
{
return
generator_
(i, j); }
217
218
double
Pij_t
(
size_t
i,
size_t
j,
double
t)
const
{
return
getPij_t
(t)(i, j); }
219
double
dPij_dt
(
size_t
i,
size_t
j,
double
t)
const
{
return
getdPij_dt
(t)(i, j); }
220
double
d2Pij_dt2
(
size_t
i,
size_t
j,
double
t)
const
{
return
getd2Pij_dt2
(t)(i, j); }
221
222
double
getInitValue
(
size_t
i,
int
state)
const
throw
(
IndexOutOfBoundsException
,
BadIntException
);
223
224
void
setFreqFromData
(
const
SequenceContainer
& data,
double
pseudoCount = 0)
225
{
226
model_
->
setFreqFromData
(data, pseudoCount);
227
updateMatrices
();
228
}
229
230
const
std::vector<int>&
getAlphabetChars
()
const
231
{
232
return
chars_
;
233
}
234
235
int
getAlphabetChar
(
size_t
i)
const
236
{
237
return
chars_
[i];
238
}
239
240
std::vector<size_t>
getModelStates
(
int
i)
const
241
{
242
std::vector<size_t> states(
nbRates_
*
nbStates_
);
243
std::vector<size_t> nestedStates =
model_
->
getModelStates
(i);
244
for
(
size_t
j = 0; j <
nbRates_
; j++)
245
for
(
size_t
k = 0; k < nestedStates.size(); k++)
246
states.push_back(j * nbRates_ + states[k]);
247
return
states;
248
}
249
250
const
ReversibleSubstitutionModel
*
getNestedModel
()
const
{
return
model_
; }
251
259
size_t
getRate
(
size_t
i)
const
260
{
261
return
i /
nbStates_
;
262
}
263
264
double
getRate
()
const
{
return
model_
->
getRate
(); }
265
266
void
setRate
(
double
rate) {
model_
->
setRate
(rate); }
267
268
double
getScale
()
const
269
{
270
std::vector<double> v;
271
MatrixTools::diag
(
generator_
, v);
272
return
-VectorTools::scalar<double, double>(v,
freq_
);
273
}
274
275
void
setScale
(
double
scale) {
276
model_
->
setScale
(scale);
277
updateMatrices
();
278
}
279
280
void
enableEigenDecomposition
(
bool
yn) {
eigenDecompose_
= yn; }
281
282
bool
enableEigenDecomposition
() {
return
eigenDecompose_
; }
283
289
virtual
void
fireParameterChanged
(
const
ParameterList
& parameters)
290
{
291
AbstractParameterAliasable::fireParameterChanged
(parameters);
292
model_
->matchParametersValues(parameters);
293
updateRatesModel
();
294
updateMatrices
();
295
}
296
297
void
setNamespace
(
const
std::string& prefix);
298
299
protected
:
300
301
virtual
void
updateMatrices
();
302
309
virtual
void
updateRatesModel
() = 0;
310
311
};
312
313
}
//end of namespace bpp.
314
315
#endif //_MARKOVMODULATEDSUBSTITUTIONMODEL_H_
316
Bpp
Phyl
Model
MarkovModulatedSubstitutionModel.h
Generated on Thu Mar 14 2013 16:39:09 for bpp-phyl by
1.8.3.1-20130209