SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PluginEstimate.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  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
11 #ifndef _PLUGINESTIMATE_H___
12 #define _PLUGINESTIMATE_H___
13 
14 #include <shogun/machine/Machine.h>
18 
19 namespace shogun
20 {
35 {
36  public:
37 
40 
45  CPluginEstimate(float64_t pos_pseudo=1e-10, float64_t neg_pseudo=1e-10);
46  virtual ~CPluginEstimate();
47 
53  virtual CBinaryLabels* apply_binary(CFeatures* data=NULL);
54 
60  {
61  SG_REF(feat);
63  features=feat;
64  }
65 
71 
73  float64_t apply_one(int32_t vec_idx);
74 
82  uint16_t* vector, int32_t len)
83  {
84  return pos_model->get_log_likelihood_example(vector, len) - neg_model->get_log_likelihood_example(vector, len);
85  }
86 
94  uint16_t obs, int32_t position)
95  {
96  return pos_model->get_positional_log_parameter(obs, position) - neg_model->get_positional_log_parameter(obs, position);
97  }
98 
105  inline float64_t log_derivative_pos_obsolete(uint16_t obs, int32_t pos)
106  {
107  return pos_model->get_log_derivative_obsolete(obs, pos);
108  }
109 
116  inline float64_t log_derivative_neg_obsolete(uint16_t obs, int32_t pos)
117  {
118  return neg_model->get_log_derivative_obsolete(obs, pos);
119  }
120 
129  inline bool get_model_params(
130  float64_t*& pos_params, float64_t*& neg_params,
131  int32_t &seq_length, int32_t &num_symbols)
132  {
133  if ((!pos_model) || (!neg_model))
134  {
135  SG_ERROR("no model available\n")
136  return false;
137  }
138 
140  pos_params = log_pos_trans.vector;
142  neg_params = log_neg_trans.vector;
143 
144  seq_length = pos_model->get_sequence_length();
145  num_symbols = pos_model->get_num_symbols();
148  return true;
149  }
150 
157  inline void set_model_params(
158  float64_t* pos_params, float64_t* neg_params,
159  int32_t seq_length, int32_t num_symbols)
160  {
161  int32_t num_params;
162 
164  pos_model=new CLinearHMM(seq_length, num_symbols);
165  SG_REF(pos_model);
166 
167 
169  neg_model=new CLinearHMM(seq_length, num_symbols);
170  SG_REF(neg_model);
171 
172  num_params=pos_model->get_num_model_parameters();
173  ASSERT(seq_length*num_symbols==num_params)
175 
176  pos_model->set_log_transition_probs(SGVector<float64_t>(pos_params, num_params));
177  neg_model->set_log_transition_probs(SGVector<float64_t>(neg_params, num_params));
178  }
179 
184  inline int32_t get_num_params()
185  {
187  }
188 
193  inline bool check_models()
194  {
195  return ( (pos_model!=NULL) && (neg_model!=NULL) );
196  }
197 
199  virtual const char* get_name() const { return "PluginEstimate"; }
200 
201  protected:
210  virtual bool train_machine(CFeatures* data=NULL);
211 
212  protected:
217 
222 
225 };
226 }
227 #endif

SHOGUN Machine Learning Toolbox - Documentation