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,
49 };
50 
61 {
62 public:
65 
74  CInferenceMethod(CKernel* kernel, CFeatures* features,
75  CMeanFunction* mean, CLabels* labels, CLikelihoodModel* model);
76 
77  virtual ~CInferenceMethod();
78 
83  virtual EInferenceType get_inference_type() const { return INF_NONE; }
84 
97 
134  float64_t get_marginal_likelihood_estimate(int32_t num_importance_samples=1,
135  float64_t ridge_size=1e-15);
136 
152  CSGObject*>* parameters);
153 
167  virtual SGVector<float64_t> get_alpha()=0;
168 
174  virtual SGMatrix<float64_t> get_cholesky()=0;
175 
181  virtual SGVector<float64_t> get_diagonal_vector()=0;
182 
199 
216 
225  CMap<TParameter*, CSGObject*>* parameters)
226  {
228  }
229 
235  {
236  SGVector<float64_t> result(1);
238  return result;
239  }
240 
246 
251  virtual void set_features(CFeatures* feat)
252  {
253  SG_REF(feat);
255  m_features=feat;
256  }
257 
262  virtual CKernel* get_kernel() { SG_REF(m_kernel); return m_kernel; }
263 
268  virtual void set_kernel(CKernel* kern)
269  {
270  SG_REF(kern);
272  m_kernel=kern;
273  }
274 
279  virtual CMeanFunction* get_mean() { SG_REF(m_mean); return m_mean; }
280 
285  virtual void set_mean(CMeanFunction* m)
286  {
287  SG_REF(m);
288  SG_UNREF(m_mean);
289  m_mean=m;
290  }
291 
296  virtual CLabels* get_labels() { SG_REF(m_labels); return m_labels; }
297 
302  virtual void set_labels(CLabels* lab)
303  {
304  SG_REF(lab);
306  m_labels=lab;
307  }
308 
314 
319  virtual void set_model(CLikelihoodModel* mod)
320  {
321  SG_REF(mod);
322  SG_UNREF(m_model);
323  m_model=mod;
324  }
325 
330  virtual float64_t get_scale() const { return m_scale; }
331 
336  virtual void set_scale(float64_t scale) { m_scale=scale; }
337 
343  virtual bool supports_regression() const { return false; }
344 
350  virtual bool supports_binary() const { return false; }
351 
357  virtual bool supports_multiclass() const { return false; }
358 
360  virtual void update();
361 
368 
369 protected:
371  virtual void check_members() const;
372 
374  virtual void update_alpha()=0;
375 
377  virtual void update_chol()=0;
378 
382  virtual void update_deriv()=0;
383 
385  virtual void update_train_kernel();
386 
395  const TParameter* param)=0;
396 
405  const TParameter* param)=0;
406 
415  const TParameter* param)=0;
416 
425  const TParameter* param)=0;
426 
430  static void* get_derivative_helper(void* p);
431 
433  virtual void compute_gradient();
434 private:
435  void init();
436 
437 protected:
440 
443 
446 
449 
452 
455 
458 
461 
464 
467 
470 };
471 }
472 #endif /* HAVE_EIGEN3 */
473 #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)
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
virtual void set_scale(float64_t scale)
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)
virtual float64_t get_scale() const
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
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