-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscorers.h
More file actions
83 lines (74 loc) · 2.28 KB
/
scorers.h
File metadata and controls
83 lines (74 loc) · 2.28 KB
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
// Copyright 2012 Florian Petran
#ifndef SCORERS_H_
#define SCORERS_H_
#include<vector>
#include"containers.h"
namespace Align {
class Scorer;
/// A container of scoring methods.
/** This class exists so that clients do not need
* to know what scoring methods there are, but can
* just iterate over this container.
*
* In order to add a client defined scoring method,
* you need to define a class that's derived from
* Scorer, construct it on the heap, and push it onto
* ScoringMethods.
**/
class ScoringMethods : public std::vector<Scorer*> {
public:
ScoringMethods();
~ScoringMethods();
ScoringMethods(const ScoringMethods&) = delete;
const ScoringMethods& operator=(const ScoringMethods&) = delete;
};
/// pure virtual base for all scoring methods
/** A scoring method is a functor that calculates the
* raw (unnormalized) score for a sequence. The base provides
* storage and a getter for the maximum of the respective
* score.
* Custom scorers need to implement the
* Scorer::name() and Scorer::operator(), obviously.
* where name() serves debugging purposes and may return
* and empty char ptr. operator() contains the scoring
* logic. Additionally, it needs to update the _max
* member after each run, which is used to calculate
* averages later.
**/
class Scorer {
public:
Scorer();
virtual ~Scorer() = default;
virtual float operator()(const Sequence&) = 0;
/// returns the maximum value for this score over all sequences
/// seen so far
inline virtual float get_max() final {
return _max;
}
virtual const char* name() = 0;
protected:
float _max;
};
/// simple scorer that favors long sequences
class LengthScorer : public Scorer {
float operator()(const Sequence&);
const char* name() {
return "length";
}
};
/// score average index difference between e and f tokens
class IndexdiffScorer : public Scorer {
float operator()(const Sequence&);
const char* name() {
return "i-diff";
}
};
/// score average bi_sim between e and f strings
class BisimScorer : public Scorer {
float operator()(const Sequence&);
const char* name() {
return "bi_sim";
}
};
} // namespace Align
#endif // SCORERS_H_