bpp-phyl
2.1.0
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Friends
Pages
AbstractSubstitutionModel.h
Go to the documentation of this file.
1
//
2
// File: AbstractSubstitutionModel.h
3
// Created by: Julien Dutheil
4
// Created on: Tue May 27 10:31:49 2003
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 _ABSTRACTSUBSTITUTIONMODEL_H_
41
#define _ABSTRACTSUBSTITUTIONMODEL_H_
42
43
#include "
SubstitutionModel.h
"
44
45
#include <
Bpp/Numeric/AbstractParameterAliasable.h
>
46
#include <
Bpp/Numeric/VectorTools.h
>
47
48
namespace
bpp
49
{
76
class
AbstractSubstitutionModel
:
77
public
virtual
SubstitutionModel
,
78
public
virtual
AbstractParameterAliasable
79
{
80
protected
:
84
const
Alphabet
*
alphabet_
;
85
89
size_t
size_
;
90
97
double
rate_
;
98
102
std::vector<int>
chars_
;
103
107
RowMatrix<double>
generator_
;
108
113
Vdouble
freq_
;
114
122
RowMatrix<double>
exchangeability_
;
123
127
mutable
RowMatrix<double>
pijt_
;
128
mutable
RowMatrix<double>
dpijt_
;
129
mutable
RowMatrix<double>
d2pijt_
;
130
134
bool
eigenDecompose_
;
135
139
Vdouble
eigenValues_
;
140
144
Vdouble
iEigenValues_
;
145
150
bool
isDiagonalizable_
;
151
155
RowMatrix<double>
rightEigenVectors_
;
156
161
bool
isNonSingular_
;
162
168
RowMatrix<double>
leftEigenVectors_
;
169
175
std::vector< RowMatrix<double> >
vPowGen_
;
176
182
mutable
RowMatrix<double>
tmpMat_
;
183
184
public
:
185
AbstractSubstitutionModel
(
const
Alphabet
* alpha,
const
std::string& prefix);
186
187
AbstractSubstitutionModel
(
const
AbstractSubstitutionModel
& model) :
188
AbstractParameterAliasable
(model),
189
alphabet_
(model.
alphabet_
),
190
size_
(model.
size_
),
191
rate_
(model.
rate_
),
192
chars_
(model.
chars_
),
193
generator_
(model.
generator_
),
194
freq_
(model.
freq_
),
195
exchangeability_
(model.
exchangeability_
),
196
pijt_
(model.
pijt_
),
197
dpijt_
(model.
dpijt_
),
198
d2pijt_
(model.
d2pijt_
),
199
eigenDecompose_
(model.
eigenDecompose_
),
200
eigenValues_
(model.
eigenValues_
),
201
iEigenValues_
(model.
iEigenValues_
),
202
isDiagonalizable_
(model.
isDiagonalizable_
),
203
rightEigenVectors_
(model.
rightEigenVectors_
),
204
isNonSingular_
(model.
isNonSingular_
),
205
leftEigenVectors_
(model.
leftEigenVectors_
),
206
vPowGen_
(model.
vPowGen_
),
207
tmpMat_
(model.
tmpMat_
)
208
{}
209
210
AbstractSubstitutionModel
&
operator=
(
const
AbstractSubstitutionModel
& model)
211
{
212
AbstractParameterAliasable::operator=
(model);
213
alphabet_
= model.
alphabet_
;
214
size_
= model.
size_
;
215
rate_
= model.
rate_
;
216
chars_
= model.
chars_
;
217
generator_
= model.
generator_
;
218
freq_
= model.
freq_
;
219
exchangeability_
= model.
exchangeability_
;
220
pijt_
= model.
pijt_
;
221
dpijt_
= model.
dpijt_
;
222
d2pijt_
= model.
d2pijt_
;
223
eigenDecompose_
= model.
eigenDecompose_
;
224
eigenValues_
= model.
eigenValues_
;
225
iEigenValues_
= model.
iEigenValues_
;
226
isDiagonalizable_
= model.
isDiagonalizable_
;
227
rightEigenVectors_
= model.
rightEigenVectors_
;
228
isNonSingular_
= model.
isNonSingular_
;
229
leftEigenVectors_
= model.
leftEigenVectors_
;
230
vPowGen_
= model.
vPowGen_
;
231
tmpMat_
= model.
tmpMat_
;
232
return
*
this
;
233
}
234
235
virtual
~AbstractSubstitutionModel
() {}
236
237
#ifndef NO_VIRTUAL_COV
238
virtual
AbstractSubstitutionModel
*
clone
()
const
= 0;
239
#endif
240
241
public
:
242
const
Alphabet
*
getAlphabet
()
const
{
return
alphabet_
; }
243
244
const
std::vector<int>&
getAlphabetChars
()
const
{
return
chars_
; }
245
246
int
getAlphabetChar
(
size_t
i)
const
{
return
chars_
[i]; }
247
248
std::vector<size_t>
getModelStates
(
int
i)
const
{
return
VectorTools::whichAll
(
chars_
, i); }
249
250
virtual
const
Vdouble
&
getFrequencies
()
const
{
return
freq_
; }
251
252
const
Matrix<double>
&
getGenerator
()
const
{
return
generator_
; }
253
254
const
Matrix<double>
&
getExchangeabilityMatrix
()
const
{
return
exchangeability_
; }
255
256
double
Sij
(
size_t
i,
size_t
j)
const
{
return
exchangeability_
(i, j); }
257
258
virtual
const
Matrix<double>
&
getPij_t
(
double
t)
const
;
259
virtual
const
Matrix<double>
&
getdPij_dt
(
double
t)
const
;
260
virtual
const
Matrix<double>
&
getd2Pij_dt2
(
double
t)
const
;
261
262
const
Vdouble
&
getEigenValues
()
const
{
return
eigenValues_
; }
263
264
const
Vdouble
&
getIEigenValues
()
const
{
return
iEigenValues_
; }
265
266
bool
isDiagonalizable
()
const
{
return
isDiagonalizable_
; }
267
268
bool
isNonSingular
()
const
{
return
isNonSingular_
; }
269
270
const
Matrix<double>
&
getRowLeftEigenVectors
()
const
{
return
leftEigenVectors_
; }
271
272
const
Matrix<double>
&
getColumnRightEigenVectors
()
const
{
return
rightEigenVectors_
; }
273
274
virtual
double
freq
(
size_t
i)
const
{
return
freq_
[i]; }
275
276
virtual
double
Qij
(
size_t
i,
size_t
j)
const
{
return
generator_
(i, j); }
277
278
virtual
double
Pij_t
(
size_t
i,
size_t
j,
double
t)
const
{
return
getPij_t
(t) (i, j); }
279
virtual
double
dPij_dt
(
size_t
i,
size_t
j,
double
t)
const
{
return
getdPij_dt
(t) (i, j); }
280
virtual
double
d2Pij_dt2
(
size_t
i,
size_t
j,
double
t)
const
{
return
getd2Pij_dt2
(t) (i, j); }
281
282
double
getInitValue
(
size_t
i,
int
state)
const
throw
(
IndexOutOfBoundsException
,
BadIntException
);
283
284
void
setFreqFromData
(
const
SequenceContainer
& data,
double
pseudoCount = 0);
285
286
virtual
void
setFreq
(std::map<int, double>&);
287
288
void
enableEigenDecomposition
(
bool
yn) {
eigenDecompose_
= yn; }
289
290
bool
enableEigenDecomposition
() {
return
eigenDecompose_
; }
291
297
virtual
void
fireParameterChanged
(
const
ParameterList
& parameters)
298
{
299
AbstractParameterAliasable::fireParameterChanged
(parameters);
300
if
((parameters.
size
()!=1) || (parameters[0].
getName
()!=
getNamespace
()+
"rate"
))
301
updateMatrices
();
302
}
303
304
void
addRateParameter
();
305
306
protected
:
323
virtual
void
updateMatrices
();
324
325
public
:
326
double
getScale
()
const
;
327
328
void
setScale
(
double
scale);
329
330
virtual
double
getRate
()
const
;
331
332
virtual
void
setRate
(
double
rate);
333
334
335
friend
class
AbstractBiblioSubstitutionModel
;
336
337
};
338
339
364
class
AbstractReversibleSubstitutionModel
:
365
public
virtual
AbstractSubstitutionModel
,
366
public
virtual
ReversibleSubstitutionModel
367
{
368
public
:
369
AbstractReversibleSubstitutionModel
(
const
Alphabet
* alpha,
const
std::string& prefix) :
370
AbstractParameterAliasable
(prefix),
371
AbstractSubstitutionModel
(alpha, prefix)
372
{
373
isDiagonalizable_
=
true
;
374
isNonSingular_
=
true
;
375
}
376
377
virtual
~AbstractReversibleSubstitutionModel
() {}
378
379
#ifndef NO_VIRTUAL_COV
380
virtual
AbstractReversibleSubstitutionModel
*
clone
()
const
= 0;
381
#endif
382
383
protected
:
384
406
virtual
void
updateMatrices
();
407
};
408
409
}
//end of namespace bpp.
410
411
#endif //_ABSTRACTSUBSTITUTIONMODEL_H_
412
Bpp
Phyl
Model
AbstractSubstitutionModel.h
Generated on Thu Mar 14 2013 16:39:09 for bpp-phyl by
1.8.3.1-20130209