File: bblLS.h

package info (click to toggle)
fastml 3.11-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,772 kB
  • sloc: cpp: 48,522; perl: 3,588; ansic: 819; makefile: 386; python: 83; sh: 55
file content (180 lines) | stat: -rw-r--r-- 5,687 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
Copyright (C) 2011 Tal Pupko  TalP@tauex.tau.ac.il.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef ___BBL_LS__
#define ___BBL_LS__

#include "definitions.h"
#include "tree.h"
#include "sequenceContainer.h"
#include "stochasticProcess.h"
#include "unObservableData.h"
#include "gainLossUtils.h"

using namespace std;

//#define MAX_BRANCH_LENGTH 50.0	//20.0

/*
This class optimize the branches using "naive" line search methodology.
go over each branch and optimize it using brent.
In one iteration it optimze seperatly all branches.
This procedure continues until convergence is reached or until the maximum number of iteration is reached.
*/
class bblLS {
public:
	
	explicit bblLS();
	~bblLS() {};
	MDOUBLE getTreeLikelihood() const {return _treeLikelihood;}


	MDOUBLE optimizeBranches(tree& tr, stochasticProcess* sp, const sequenceContainer &sc, Vdouble* weights, unObservableData* unObservableData_p,
		const int outerIter,
		const MDOUBLE epsilonOptimization =0.1, const int numIterations =10,
		MDOUBLE curL =NULL);

	MDOUBLE optimizeBranches(tree& tr, vector<vector<stochasticProcess*> >& spVVec,
		const distribution * gainDist, const distribution * lossDist,
		const sequenceContainer &sc, 
		Vdouble* weights, unObservableData* unObservableData_p,
		const int outerIter,
		const MDOUBLE epsilonOptimization =0.1, const int numIterations =10,
		MDOUBLE curL =NULL); 	


private:
	Vdouble* _weights; 
	MDOUBLE _treeLikelihood;
};

//////////////////////////////////////////////////////////////////////////
class evalBranch{
public:
	explicit evalBranch(tree::nodeP pNode, tree* tr, const sequenceContainer &sc, stochasticProcess* sp, Vdouble* weights, unObservableData* unObservableData_p )
		:_pNode(pNode),_tr(tr), _sc(sc), _sp(sp),_weights(weights)
	{
		if(unObservableData_p)
			_unObservableData_p = unObservableData_p->clone();
		else
			_unObservableData_p = NULL;

	};	
	virtual ~evalBranch(){
		if(_unObservableData_p)	delete _unObservableData_p;
	}	
	
	MDOUBLE operator() (MDOUBLE x);

private:
	tree::nodeP _pNode;
	tree* _tr;
	const sequenceContainer& _sc;
	const stochasticProcess* _sp;
	Vdouble* _weights;
	unObservableData* _unObservableData_p;
};

//////////////////////////////////////////////////////////////////////////
class evalBranchSPvv{
public:
	explicit evalBranchSPvv(tree::nodeP pNode, tree* tr, const sequenceContainer &sc, vector<vector<stochasticProcess*> >& spVVec,
		const distribution * gainDist, const distribution * lossDist,
		Vdouble* weights, unObservableData* unObservableData_p)
		:_pNode(pNode),_tr(tr),_sc(sc),_spVVec(spVVec), _gainDist(gainDist), _lossDist(lossDist),_unObservableData_p(unObservableData_p),_weights(weights)
	{
		if(unObservableData_p)
			_unObservableData_p = unObservableData_p->clone();
		else
			_unObservableData_p = NULL;
	};
	virtual ~evalBranchSPvv(){
		if(_unObservableData_p)	delete _unObservableData_p;
	}
	MDOUBLE operator() (MDOUBLE x);

private:
	tree::nodeP _pNode;
	tree* _tr;
	const sequenceContainer& _sc;
	const vector<vector<stochasticProcess*> >& _spVVec;
	const distribution * _gainDist;
	const distribution * _lossDist;
	Vdouble* _weights;
	unObservableData* _unObservableData_p;
};


//////////////////////////////////////////////////////////////////////////
class evalBranchProportionExponent{
public:
	explicit evalBranchProportionExponent(tree* tr, const sequenceContainer &sc, stochasticProcess* sp, Vdouble* weights, unObservableData* unObservableData_p )
		:_tr(tr), _sc(sc), _sp(sp),_weights(weights)
	{
		if(unObservableData_p)
			_unObservableData_p = unObservableData_p->clone();
		else
			_unObservableData_p = NULL;

	};	
	virtual ~evalBranchProportionExponent(){
		if(_unObservableData_p)	delete _unObservableData_p;
	}	

	MDOUBLE operator() (MDOUBLE x);

private:	
	tree* _tr;
	const sequenceContainer& _sc;
	const stochasticProcess* _sp;
	Vdouble* _weights;
	unObservableData* _unObservableData_p;
};

//////////////////////////////////////////////////////////////////////////
class evalBranchProportionExponentSPvv{
public:
	explicit evalBranchProportionExponentSPvv(tree* tr, const sequenceContainer &sc, vector<vector<stochasticProcess*> >& spVVec,
		const distribution * gainDist, const distribution * lossDist,
		Vdouble* weights, unObservableData* unObservableData_p)
		:_tr(tr),_sc(sc),_spVVec(spVVec), _gainDist(gainDist), _lossDist(lossDist),_unObservableData_p(unObservableData_p),_weights(weights)
	{
		if(unObservableData_p)
			_unObservableData_p = unObservableData_p->clone();
		else
			_unObservableData_p = NULL;
	};
	virtual ~evalBranchProportionExponentSPvv(){
		if(_unObservableData_p)	delete _unObservableData_p;
	}
	MDOUBLE operator() (MDOUBLE x);

private:
	tree* _tr;
	const sequenceContainer& _sc;
	const vector<vector<stochasticProcess*> >& _spVVec;
	const distribution * _gainDist;
	const distribution * _lossDist;
	Vdouble* _weights;
	unObservableData* _unObservableData_p;
};




#endif