SHOGUN  5.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
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
virtual int32_t get_sequence_length()
Definition: LinearHMM.h:151
virtual float64_t get_positional_log_parameter(uint16_t obs, int32_t position)
Definition: LinearHMM.h:171
int32_t sequence_length
Definition: LinearHMM.h:227
virtual float64_t get_derivative_obsolete(uint16_t *vector, int32_t len, int32_t pos)
Definition: LinearHMM.h:140
virtual float64_t get_log_derivative_obsolete(uint16_t obs, int32_t pos)
Definition: LinearHMM.h:128
virtual int32_t get_num_symbols()
Definition: LinearHMM.h:157
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
float64_t * transition_probs
Definition: LinearHMM.h:233
virtual float64_t get_log_derivative(int32_t num_param, int32_t num_example)
Definition: LinearHMM.cpp:235
virtual int32_t get_num_model_parameters()
Definition: LinearHMM.h:163
virtual ~CLinearHMM()
Definition: LinearHMM.cpp:48
Base class Distribution from which all methods implementing a distribution are derived.
Definition: Distribution.h:44
float64_t get_log_likelihood_example(uint16_t *vector, int32_t len)
Definition: LinearHMM.cpp:186
virtual float64_t get_log_model_parameter(int32_t num_param)
Definition: LinearHMM.h:182
#define ASSERT(x)
Definition: SGIO.h:201
int32_t num_symbols
Definition: LinearHMM.h:229
virtual const char * get_name() const
Definition: LinearHMM.h:217
double float64_t
Definition: common.h:50
virtual SGVector< float64_t > get_transition_probs()
Definition: LinearHMM.cpp:254
virtual bool set_log_transition_probs(const SGVector< float64_t > probs)
Definition: LinearHMM.cpp:283
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual bool set_transition_probs(const SGVector< float64_t > probs)
Definition: LinearHMM.cpp:259
The class Features is the base class of all feature objects.
Definition: Features.h:68
virtual bool train(CFeatures *data=NULL)
Definition: LinearHMM.cpp:54
float64_t * log_transition_probs
Definition: LinearHMM.h:235
virtual SGVector< float64_t > get_log_transition_probs()
Definition: LinearHMM.cpp:278
The class LinearHMM is for learning Higher Order Markov chains.
Definition: LinearHMM.h:41
virtual void load_serializable_post()
Definition: LinearHMM.cpp:302
int32_t num_params
Definition: LinearHMM.h:231
float64_t get_likelihood_example(uint16_t *vector, int32_t len)
Definition: LinearHMM.cpp:210

SHOGUN Machine Learning Toolbox - Documentation