Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
HiddenMarkovModel.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2017.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: Andreas Bertsch $
33 // --------------------------------------------------------------------------
34 
35 
36 #ifndef OPENMS_ANALYSIS_ID_HIDDENMARKOVMODEL_H
37 #define OPENMS_ANALYSIS_ID_HIDDENMARKOVMODEL_H
38 
39 #include <vector>
40 #include <set>
41 
43 #include <OpenMS/CONCEPT/Types.h>
46 
47 #include <utility>
48 
49 namespace OpenMS
50 {
54  class OPENMS_DLLAPI HMMState
55  {
56 public:
57 
61  HMMState();
63 
65  HMMState(const HMMState & state);
66 
68  HMMState(const String & name, bool hidden = true);
69 
71  virtual ~HMMState();
73 
75  HMMState & operator=(const HMMState &);
76 
80  void setName(const String & name);
82 
84  const String & getName() const;
85 
87  void setHidden(bool hidden);
88 
90  bool isHidden() const;
91 
93  void addPredecessorState(HMMState * state);
94 
96  void deletePredecessorState(HMMState * state);
97 
99  void addSuccessorState(HMMState * state);
100 
102  void deleteSuccessorState(HMMState * state);
103 
105  const std::set<HMMState *> & getPredecessorStates() const;
106 
108  const std::set<HMMState *> & getSuccessorStates() const;
110 
111 protected:
112 
114  bool hidden_;
115 
118 
120  std::set<HMMState *> pre_states_;
121 
123  std::set<HMMState *> succ_states_;
124  };
125 
126 
134  class OPENMS_DLLAPI HiddenMarkovModel
135  {
136 public:
137 
143 
145  HiddenMarkovModel(const HiddenMarkovModel & hmm_new);
146 
148  virtual ~HiddenMarkovModel();
150 
152  HiddenMarkovModel & operator=(const HiddenMarkovModel &);
153 
162  void writeGraphMLFile(const String & filename);
163 
165  void write(std::ostream & out) const;
166 
168  double getTransitionProbability(const String & s1, const String & s2) const;
169 
171  void setTransitionProbability(const String & s1, const String & s2, double prob);
172 
174  Size getNumberOfStates() const;
175 
177  void addNewState(HMMState * state);
178 
180  void addNewState(const String & name);
181 
183  void addSynonymTransition(const String & name1, const String & name2, const String & synonym1, const String & synonym2);
184 
186  void evaluate();
187 
189  void train();
190 
192  void setInitialTransitionProbability(const String & state, double prob);
193 
195  void clearInitialTransitionProbabilities();
196 
198  void setTrainingEmissionProbability(const String & state, double prob);
199 
201  void clearTrainingEmissionProbabilities();
202 
204  void enableTransition(const String & s1, const String & s2);
205 
207  void disableTransition(const String & s1, const String & s2);
208 
210  void disableTransitions();
211 
213  void calculateEmissionProbabilities(Map<HMMState *, double> & emission_probs);
214 
216  void dump();
217 
219  void forwardDump();
220 
222  //void buildSynonyms();
223 
225  void estimateUntrainedTransitions();
226 
228  HMMState * getState(const String & name);
229 
231  const HMMState * getState(const String & name) const;
232 
234  void clear();
235 
237  void setPseudoCounts(double pseudo_counts);
238 
240  double getPseudoCounts() const;
241 
242  void setVariableModifications(const StringList & modifications);
244 
245 protected:
246 
248  void disableTransition_(HMMState * s1, HMMState * s2);
249 
251  void enableTransition_(HMMState * s1, HMMState * s2);
252 
254  void setTrainingEmissionProbability_(HMMState * state, double prob);
255 
257  void setTransitionProbability_(HMMState * s1, HMMState * s2, double prob);
258 
260  double getTransitionProbability_(HMMState * s1, HMMState * s2) const;
261 
262 
264  void calculateForwardPart_();
265 
267  void calculateBackwardPart_();
268 
270  double getForwardVariable_(HMMState *);
271 
273  double getBackwardVariable_(HMMState *);
274 
275 private:
276 
277  // transition probs
279 
280  // transition prob counts
282 
284 
285  // all transition probs of all training steps (for model checking)
287 
288  // number of training steps of the transitions
290 
291  // forward variables
293 
294  // backward variables
296 
297  // name to state Mapping
299 
300  // emission probabilities
302 
303  // initial transition probabilities
305 
306  // all states of the HMM
307  std::set<HMMState *> states_;
308 
309  // trained transitions
310  std::set<std::pair<HMMState *, HMMState *> > trained_trans_;
311 
312  // synonym transitions Mapping
314 
315  // synonym transitions
317 
318  // transitions which are enabled
320 
321  // pseudocounts used in this instance
323 
324  // copy all the stuff from one HMM to this
325  void copy_(const HiddenMarkovModel & source);
326 
328  };
329 }
330 #endif
Map< HMMState *, double > train_emission_prob_
Definition: HiddenMarkovModel.h:301
double pseudo_counts_
Definition: HiddenMarkovModel.h:322
Map< HMMState *, double > backward_
Definition: HiddenMarkovModel.h:295
StringList var_modifications_
Definition: HiddenMarkovModel.h:327
A more convenient string class.
Definition: String.h:57
Map< HMMState *, Map< HMMState *, double > > trans_
Definition: HiddenMarkovModel.h:278
bool hidden_
Definition: HiddenMarkovModel.h:114
std::set< HMMState * > succ_states_
Definition: HiddenMarkovModel.h:123
std::set< HMMState * > pre_states_
Definition: HiddenMarkovModel.h:120
Map< HMMState *, Map< HMMState *, std::pair< HMMState *, HMMState * > > > synonym_trans_
Definition: HiddenMarkovModel.h:316
std::set< HMMState * > states_
Definition: HiddenMarkovModel.h:307
Map< String, Map< String, std::pair< String, String > > > synonym_trans_names_
Definition: HiddenMarkovModel.h:313
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
String name_
Definition: HiddenMarkovModel.h:117
std::set< std::pair< HMMState *, HMMState * > > trained_trans_
Definition: HiddenMarkovModel.h:310
Hidden Markov Model State class for the Hidden Markov Model.
Definition: HiddenMarkovModel.h:54
Map< String, HMMState * > name_to_state_
Definition: HiddenMarkovModel.h:298
Map< HMMState *, Map< HMMState *, double > > count_trans_
Definition: HiddenMarkovModel.h:281
Map< HMMState *, double > forward_
Definition: HiddenMarkovModel.h:292
Map< HMMState *, Map< HMMState *, std::vector< double > > > train_count_trans_all_
Definition: HiddenMarkovModel.h:286
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:74
Map< HMMState *, std::set< HMMState * > > enabled_trans_
Definition: HiddenMarkovModel.h:319
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
Hidden Markov Model implementation of PILIS.
Definition: HiddenMarkovModel.h:134
Map class based on the STL map (containing several convenience functions)
Definition: Map.h:51
Map< HMMState *, double > init_prob_
Definition: HiddenMarkovModel.h:304
Map< HMMState *, Map< HMMState *, std::vector< double > > > count_trans_all_
Definition: HiddenMarkovModel.h:283
Map< HMMState *, Map< HMMState *, Size > > training_steps_count_
Definition: HiddenMarkovModel.h:289

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:00 using doxygen 1.8.13