LinearHMM.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 1999-2008 Soeren Sonnenburg
00008  * Written (W) 1999-2008 Gunnar Raetsch
00009  * Copyright (C) 1999-2008 Fraunhofer Institute FIRST and Max-Planck-Society
00010  */
00011 
00012 #ifndef _LINEARHMM_H__
00013 #define _LINEARHMM_H__
00014 
00015 #include "features/StringFeatures.h"
00016 #include "features/Labels.h"
00017 #include "distributions/Distribution.h"
00018 
00020 class CLinearHMM : public CDistribution
00021 {
00022     public:
00027         CLinearHMM(CStringFeatures<WORD>* f);
00028 
00034         CLinearHMM(INT p_num_features, INT p_num_symbols);
00035         ~CLinearHMM();
00036 
00041         bool train();
00042 
00050         bool train(const INT* indizes, INT num_indizes, DREAL pseudo_count);
00051 
00058         DREAL get_log_likelihood_example(WORD* vector, INT len);
00059 
00066         DREAL get_likelihood_example(WORD* vector, INT len);
00067 
00073         virtual DREAL get_log_likelihood_example(INT num_example);
00074 
00081         virtual DREAL get_log_derivative(INT num_param, INT num_example);
00082 
00089         virtual inline DREAL get_log_derivative_obsolete(WORD obs, INT pos)
00090         {
00091             return 1.0/transition_probs[pos*num_symbols+obs];
00092         }
00093 
00100         virtual inline DREAL get_derivative_obsolete(WORD* vector, INT len, INT pos)
00101         {
00102             ASSERT(pos<len);
00103             return get_likelihood_example(vector, len)/transition_probs[pos*num_symbols+vector[pos]];
00104         }
00105 
00110         virtual inline INT get_sequence_length() { return sequence_length; }
00111 
00116         virtual inline INT get_num_symbols() { return num_symbols; }
00117 
00122         virtual inline INT get_num_model_parameters() { return num_params; }
00123 
00130         virtual inline DREAL get_positional_log_parameter(WORD obs, INT position)
00131         {
00132             return log_transition_probs[position*num_symbols+obs];
00133         }
00134 
00140         virtual inline DREAL get_log_model_parameter(INT num_param)
00141         {
00142             ASSERT(log_transition_probs);
00143             ASSERT(num_param<num_params);
00144 
00145             return log_transition_probs[num_param];
00146         }
00147 
00155         virtual void get_log_transition_probs(DREAL** dst, INT* num);
00156 
00163         virtual bool set_log_transition_probs(const DREAL* src, INT num);
00164 
00170         virtual void get_transition_probs(DREAL** dst, INT* num);
00171 
00178         virtual bool set_transition_probs(const DREAL* src, INT num);
00179 
00180     protected:
00182         INT sequence_length;
00184         INT num_symbols;
00186         INT num_params;
00188         DREAL* transition_probs;
00190         DREAL* log_transition_probs;
00191 };
00192 #endif

SHOGUN Machine Learning Toolbox - Documentation