SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LinearHMM.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2009 Soeren Sonnenburg
8  * Written (W) 1999-2008 Gunnar Raetsch
9  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
10  */
11 
12 #ifndef _LINEARHMM_H__
13 #define _LINEARHMM_H__
14 
16 #include <shogun/labels/Labels.h>
18 
19 namespace shogun
20 {
39 class CLinearHMM : public CDistribution
40 {
41  public:
43  CLinearHMM();
44 
50 
56  CLinearHMM(int32_t p_num_features, int32_t p_num_symbols);
57 
58  virtual ~CLinearHMM();
59 
68  virtual bool train(CFeatures* data=NULL);
69 
77  bool train(
78  const int32_t* indizes, int32_t num_indizes,
80 
87  float64_t get_log_likelihood_example(uint16_t* vector, int32_t len);
88 
95  float64_t get_likelihood_example(uint16_t* vector, int32_t len);
96 
102  virtual float64_t get_log_likelihood_example(int32_t num_example);
103 
111  int32_t num_param, int32_t num_example);
112 
120  uint16_t obs, int32_t pos)
121  {
122  return 1.0/transition_probs[pos*num_symbols+obs];
123  }
124 
132  uint16_t* vector, int32_t len, int32_t pos)
133  {
134  ASSERT(pos<len)
135  return get_likelihood_example(vector, len)/transition_probs[pos*num_symbols+vector[pos]];
136  }
137 
142  virtual int32_t get_sequence_length() { return sequence_length; }
143 
148  virtual int32_t get_num_symbols() { return num_symbols; }
149 
154  virtual int32_t get_num_model_parameters() { return num_params; }
155 
163  uint16_t obs, int32_t position)
164  {
165  return log_transition_probs[position*num_symbols+obs];
166  }
167 
173  virtual float64_t get_log_model_parameter(int32_t num_param)
174  {
176  ASSERT(num_param<num_params)
177 
178  return log_transition_probs[num_param];
179  }
180 
186 
192  virtual bool set_log_transition_probs(const SGVector<float64_t> probs);
193 
199 
205  virtual bool set_transition_probs(const SGVector<float64_t> probs);
206 
208  virtual const char* get_name() const { return "LinearHMM"; }
209 
210  protected:
211  virtual void load_serializable_post() throw (ShogunException);
212 
213  private:
214  void init();
215 
216  protected:
220  int32_t num_symbols;
222  int32_t num_params;
227 };
228 }
229 #endif

SHOGUN Machine Learning Toolbox - Documentation