-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTreeDistance.h
93 lines (75 loc) · 3.03 KB
/
TreeDistance.h
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
#ifndef _TreeDistance_h_
#define _TreeDistance_h_
#include "default.h"
#include "Tree.h"
#include "NewickTree.h"
#include <string>
#include <vector>
#include <cassert>
#include <iostream>
/**
* Base class for distance computation
*
* Use TreeDistance::build() to construct an instance.
*/
class TreeDistance
{
public:
enum tree_distance_t { distance_unset, distance_depth, distance_leaves };
enum distance_scaling_t { scaling_none, scaling_exp_minus, scaling_log };
// Constructor
//static TreeDistance* build(PointerTree &, PointerTree &, tree_distance_t, distance_scaling_t);
// Compute distances to be used for prediction at the given input column
virtual void recomputeDistances(InputColumn const &) = 0;
// Evaluate the distance for the given destination node on the target tree
double evaluateDistance(std::vector<PointerTree::PointerNode *> const &, PointerTree::PointerNode *, PointerTree::PointerNode *);
// Init for evaluation over zero skeleton
virtual void initZeroSkeleton(InputColumn const &) = 0;
double evalZeroSkeleton(PointerTree::PointerNode *, PointerTree::PointerNode *);
virtual ~TreeDistance()
{ }
protected:
TreeDistance(PointerTree &target_)
: target(target_), sourcedist()
{ }
void distanceByTraversal(PointerTree::PointerNode *, PointerTree::PointerNode *, unsigned, LeafDistance &, unsigned);
void distanceByTraversal(PointerTree::PointerNode *, PointerTree::PointerNode const *, PointerTree::PointerNode const *, std::set<PointerTree::PointerNode *> &, unsigned, LeafDistance &);
//unsigned rootDistanceByTraversal(PointerTree::PointerNode *, PointerTree::PointerNode const *, std::set<PointerTree::PointerNode *> &);
void distanceSkeletonTraversal(PointerTree::PointerNode *, PointerTree::PointerNode const *, PointerTree::PointerNode const *, PointerTree::PointerNode *, unsigned, LeafDistance &);
PointerTree ⌖
LeafDistance sourcedist;
};
/**
* Distance computation for PointerTrees
*/
class PointerTreeDistance : public TreeDistance
{
public:
PointerTreeDistance(PointerTree &, PointerTree &);
// Compute distances to be used for prediction at the given input column
virtual void recomputeDistances(InputColumn const &);
virtual void initZeroSkeleton(InputColumn const &);
virtual ~PointerTreeDistance()
{ }
private:
PointerTree &source;
};
/**
* Distance computation for Newick trees
*/
class NewickDistance : public TreeDistance
{
public:
// Constructor
//static TreeDistance* build(NewickTree &, PointerTree &, tree_distance_t, distance_scaling_t);
NewickDistance(NewickTree &, PointerTree &);
// Compute distances to be used for prediction at the given input column
virtual void recomputeDistances(InputColumn const &);
virtual void initZeroSkeleton(InputColumn const &);
virtual ~NewickDistance()
{ }
private:
void distanceByTraversal(NewickTree::Node *, NewickTree::Node *, unsigned, LeafDistance &, unsigned);
NewickTree &source;
};
#endif