SHOGUN  3.2.1
 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 
15 #include <shogun/lib/config.h>
16 
18 #include <shogun/labels/Labels.h>
20 
21 namespace shogun
22 {
41 class CLinearHMM : public CDistribution
42 {
43  public:
45  CLinearHMM();
46 
52 
58  CLinearHMM(int32_t p_num_features, int32_t p_num_symbols);
59 
60  virtual ~CLinearHMM();
61 
70  virtual bool train(CFeatures* data=NULL);
71 
79  bool train(
80  const int32_t* indizes, int32_t num_indizes,
82 
89  float64_t get_log_likelihood_example(uint16_t* vector, int32_t len);
90 
97  float64_t get_likelihood_example(uint16_t* vector, int32_t len);
98 
104  float64_t get_likelihood_example(int32_t num_example);
105 
111  virtual float64_t get_log_likelihood_example(int32_t num_example);
112 
120  int32_t num_param, int32_t num_example);
121 
129  uint16_t obs, int32_t pos)
130  {
131  return 1.0/transition_probs[pos*num_symbols+obs];
132  }
133 
141  uint16_t* vector, int32_t len, int32_t pos)
142  {
143  ASSERT(pos<len)
144  return get_likelihood_example(vector, len)/transition_probs[pos*num_symbols+vector[pos]];
145  }
146 
151  virtual int32_t get_sequence_length() { return sequence_length; }
152 
157  virtual int32_t get_num_symbols() { return num_symbols; }
158 
163  virtual int32_t get_num_model_parameters() { return num_params; }
164 
172  uint16_t obs, int32_t position)
173  {
174  return log_transition_probs[position*num_symbols+obs];
175  }
176 
182  virtual float64_t get_log_model_parameter(int32_t num_param)
183  {
185  ASSERT(num_param<num_params)
186 
187  return log_transition_probs[num_param];
188  }
189 
195 
201  virtual bool set_log_transition_probs(const SGVector<float64_t> probs);
202 
208 
214  virtual bool set_transition_probs(const SGVector<float64_t> probs);
215 
217  virtual const char* get_name() const { return "LinearHMM"; }
218 
219  protected:
220  virtual void load_serializable_post() throw (ShogunException);
221 
222  private:
223  void init();
224 
225  protected:
229  int32_t num_symbols;
231  int32_t num_params;
236 };
237 }
238 #endif

SHOGUN Machine Learning Toolbox - Documentation