LocARNA-2.0.0
fitonoff.hh
1 #ifndef LOCARNA_FIT_ON_OFF_HH
2 #define LOCARNA_FIT_ON_OFF_HH
3 
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7 
8 #include <string>
9 #include <vector>
10 
11 #include <cmath>
12 
13 namespace LocARNA {
14 
15  typedef std::vector<double> numseq_t;
16  typedef std::vector<double>::size_type size_type;
17 
18  typedef long double pf_t;
19 
24  class FitOnOff {
25  numseq_t x;
26  double delta_val;
27  double beta;
28 
29  pf_t exp_delta_val;
30 
31  std::vector<std::vector<pf_t> > v;
32 
33  std::vector<std::vector<bool> > t;
34 
35  std::vector<bool> trace;
36 
37  /*
38  * helper-functions for switching between position
39  * and non-position dependent penalties
40  */
41 
42  protected:
43  virtual
44  double delta(int i) const {return delta_val;}
45  virtual
46  double exp_delta(int i) const {return exp_delta_val;}
47 
48  public:
55  FitOnOff(numseq_t &x_, double delta_, double beta_)
56  : x(x_), delta_val(delta_), beta(beta_) {
57  v.resize(2);
58  v[0].resize(x.size() + 1);
59  v[1].resize(x.size() + 1);
60 
61  t.resize(2);
62  t[0].resize(x.size() + 1);
63  t[1].resize(x.size() + 1);
64  trace.resize(x.size() + 1);
65 
66  exp_delta_val = exp(-beta * delta_val);
67  }
68 
76  double
77  viterbi(double c0, double c1, bool traceback);
78 
86  double
87  best_once_on(double c0, double c1);
88 
93  pf_t
94  forward(double c0, double c1);
95 
100  std::pair<double, double>
101  optimize(double c0, double c1);
102 
104  void
105  write_viterbi_path_compact(std::ostream &out, double c0, double c1);
106 
108  void
109  write_viterbi_path(std::ostream &out, double c0, double c1) const;
110 
111  // DEBUGGING
112 
119  void
120  print_table(const std::string &name, const std::vector<bool> &v) const;
121 
128  void
129  print_table(const std::string &name, const std::vector<pf_t> &v) const;
130 
135  void
136  print_tables() const;
137  };
138 
142  class FitOnOffVarPenalty : public FitOnOff {
143  public:
150  FitOnOffVarPenalty(numseq_t &x_, numseq_t &penalties_, double beta_)
151  : FitOnOff(x_, 0, beta_), penalties(penalties_) {
152 
153  // pre-calculation of exp_penalties parameter
154  int length_penalties = penalties.size();
155  for (int i = 0; i < length_penalties; i++) {
156  exp_penalties.push_back(exp(-beta_ * penalties.at(i)));
157  }
158  }
159 
160  protected:
161  virtual
162  double delta(int i) const {return penalties.at(i-1);}
163  virtual
164  double exp_delta(int i) const {return exp_penalties.at(i-1);}
165 
166  private:
167  numseq_t penalties;
168  numseq_t exp_penalties;
169  };
170 } // END namespace LocARNA
171 
172 #endif // LOCARNA_FIT_ON_OFF_HH
Fitting of a two-step function with position-specific step penalities.
Definition: fitonoff.hh:142
FitOnOffVarPenalty(numseq_t &x_, numseq_t &penalties_, double beta_)
Definition: fitonoff.hh:150
Implements fitting of a two-step function to a number sequence.
Definition: fitonoff.hh:24
double viterbi(double c0, double c1, bool traceback)
Definition: fitonoff.cc:15
FitOnOff(numseq_t &x_, double delta_, double beta_)
Definition: fitonoff.hh:55
std::pair< double, double > optimize(double c0, double c1)
Definition: fitonoff.cc:118
double best_once_on(double c0, double c1)
Definition: fitonoff.cc:46
void print_table(const std::string &name, const std::vector< bool > &v) const
Definition: fitonoff.cc:278
void write_viterbi_path_compact(std::ostream &out, double c0, double c1)
writes the ranges in the viterbi path
Definition: fitonoff.cc:247
void write_viterbi_path(std::ostream &out, double c0, double c1) const
writes the viterbi path
Definition: fitonoff.cc:236
pf_t forward(double c0, double c1)
Definition: fitonoff.cc:103
void print_tables() const
Definition: fitonoff.cc:298
Definition: aligner.cc:15
size_t size_type
general size type
Definition: aux.hh:120