SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
InferenceMethod.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) 2013 Roman Votyakov
8  * Written (W) 2013-2014 Heiko Strathmann
9  * Written (W) 2015 Wu Lin
10  * Copyright (C) 2012 Jacob Walker
11  * Copyright (C) 2013 Roman Votyakov
12  */
13 
14 #ifndef CINFERENCEMETHOD_H_
15 #define CINFERENCEMETHOD_H_
16 
17 #include <shogun/lib/config.h>
18 
19 #ifdef HAVE_EIGEN3
20 
21 #include <shogun/base/SGObject.h>
22 #include <shogun/kernel/Kernel.h>
24 #include <shogun/labels/Labels.h>
28 
29 namespace shogun
30 {
31 
34 {
43  INF_EP=40,
44  INF_KL=50,
50 };
51 
62 {
63 public:
66 
75  CInferenceMethod(CKernel* kernel, CFeatures* features,
76  CMeanFunction* mean, CLabels* labels, CLikelihoodModel* model);
77 
78  virtual ~CInferenceMethod();
79 
84  virtual EInferenceType get_inference_type() const { return INF_NONE; }
85 
98 
135  float64_t get_marginal_likelihood_estimate(int32_t num_importance_samples=1,
136  float64_t ridge_size=1e-15);
137 
153  CSGObject*>* parameters);
154 
168  virtual SGVector<float64_t> get_alpha()=0;
169 
175  virtual SGMatrix<float64_t> get_cholesky()=0;
176 
182  virtual SGVector<float64_t> get_diagonal_vector()=0;
183 
200 
217 
226  CMap<TParameter*, CSGObject*>* parameters)
227  {
229  }
230 
236  {
237  SGVector<float64_t> result(1);
239  return result;
240  }
241 
247 
252  virtual void set_features(CFeatures* feat)
253  {
254  SG_REF(feat);
256  m_features=feat;
257  }
258 
263  virtual CKernel* get_kernel() { SG_REF(m_kernel); return m_kernel; }
264 
269  virtual void set_kernel(CKernel* kern)
270  {
271  SG_REF(kern);
273  m_kernel=kern;
274  }
275 
280  virtual CMeanFunction* get_mean() { SG_REF(m_mean); return m_mean; }
281 
286  virtual void set_mean(CMeanFunction* m)
287  {
288  SG_REF(m);
289  SG_UNREF(m_mean);
290  m_mean=m;
291  }
292 
297  virtual CLabels* get_labels() { SG_REF(m_labels); return m_labels; }
298 
303  virtual void set_labels(CLabels* lab)
304  {
305  SG_REF(lab);
307  m_labels=lab;
308  }
309 
315 
320  virtual void set_model(CLikelihoodModel* mod)
321  {
322  SG_REF(mod);
323  SG_UNREF(m_model);
324  m_model=mod;
325  }
326 
331  virtual float64_t get_scale() const;
332 
337  virtual void set_scale(float64_t scale);
338 
344  virtual bool supports_regression() const { return false; }
345 
351  virtual bool supports_binary() const { return false; }
352 
358  virtual bool supports_multiclass() const { return false; }
359 
361  virtual void update();
362 
369 
370 protected:
372  virtual void check_members() const;
373 
375  virtual void update_alpha()=0;
376 
378  virtual void update_chol()=0;
379 
383  virtual void update_deriv()=0;
384 
386  virtual void update_train_kernel();
387 
396  const TParameter* param)=0;
397 
406  const TParameter* param)=0;
407 
416  const TParameter* param)=0;
417 
426  const TParameter* param)=0;
427 
431  static void* get_derivative_helper(void* p);
432 
434  virtual void compute_gradient();
435 private:
436  void init();
437 
438 protected:
441 
444 
447 
450 
453 
456 
459 
462 
465 
468 
471 };
472 }
473 #endif /* HAVE_EIGEN3 */
474 #endif /* CINFERENCEMETHOD_H_ */
virtual void set_labels(CLabels *lab)
virtual void set_model(CLikelihoodModel *mod)
virtual float64_t get_negative_log_marginal_likelihood()=0
virtual CFeatures * get_features()
virtual void update_alpha()=0
SGVector< float64_t > m_alpha
The Inference Method base class.
virtual void set_features(CFeatures *feat)
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
parameter struct
virtual CMap< TParameter *, SGVector< float64_t > > * get_gradient(CMap< TParameter *, CSGObject * > *parameters)
virtual void set_scale(float64_t scale)
An abstract class of the mean function.
Definition: MeanFunction.h:28
virtual SGVector< float64_t > get_derivative_wrt_likelihood_model(const TParameter *param)=0
#define SG_REF(x)
Definition: SGObject.h:51
SGMatrix< float64_t > m_L
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
virtual SGMatrix< float64_t > get_multiclass_E()
virtual bool supports_regression() const
double float64_t
Definition: common.h:50
SGMatrix< float64_t > m_E
An abstract class that describes a differentiable function used for GradientEvaluation.
virtual CLabels * get_labels()
virtual SGVector< float64_t > get_derivative_wrt_inference_method(const TParameter *param)=0
virtual void update_train_kernel()
virtual SGVector< float64_t > get_derivative_wrt_kernel(const TParameter *param)=0
virtual CMeanFunction * get_mean()
virtual void set_kernel(CKernel *kern)
float64_t get_marginal_likelihood_estimate(int32_t num_importance_samples=1, float64_t ridge_size=1e-15)
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual SGVector< float64_t > get_derivative_wrt_mean(const TParameter *param)=0
virtual void set_mean(CMeanFunction *m)
virtual SGMatrix< float64_t > get_posterior_covariance()=0
virtual CKernel * get_kernel()
The class Features is the base class of all feature objects.
Definition: Features.h:68
void scale(Matrix A, Matrix B, typename Matrix::Scalar alpha)
Definition: Core.h:93
virtual void update_chol()=0
virtual bool supports_multiclass() const
virtual void check_members() const
virtual SGVector< float64_t > get_posterior_mean()=0
virtual EInferenceType get_inference_type() const
The Kernel base class.
Definition: Kernel.h:158
virtual bool supports_binary() const
virtual SGVector< float64_t > get_value()
virtual void update_deriv()=0
The Likelihood model base class.
SGMatrix< float64_t > m_ktrtr
virtual CMap< TParameter *, SGVector< float64_t > > * get_negative_log_marginal_likelihood_derivatives(CMap< TParameter *, CSGObject * > *parameters)
CLikelihoodModel * get_model()
CLikelihoodModel * m_model
virtual float64_t get_scale() const
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...
Definition: SGObject.h:36
static void * get_derivative_helper(void *p)

SHOGUN Machine Learning Toolbox - Documentation