SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Inference.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) The Shogun Machine Learning Toolbox
3  * Written (W) 2015 Wu Lin
4  * Written (W) 2013-2014 Heiko Strathmann
5  * Written (W) 2013 Roman Votyakov
6  * Written (W) 2012 Jacob Walker
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice, this
13  * list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * The views and conclusions contained in the software and documentation are those
30  * of the authors and should not be interpreted as representing official policies,
31  * either expressed or implied, of the Shogun Development Team.
32  *
33  */
34 #ifndef CINFERENCE_H_
35 #define CINFERENCE_H_
36 
37 #include <shogun/lib/config.h>
38 
39 
40 #include <shogun/base/SGObject.h>
41 #include <shogun/kernel/Kernel.h>
43 #include <shogun/labels/Labels.h>
48 
49 namespace shogun
50 {
51 
54 {
63  INF_EP=40,
64  INF_KL=50,
70 };
71 
82 {
83 public:
85  CInference();
86 
95  CInference(CKernel* kernel, CFeatures* features,
96  CMeanFunction* mean, CLabels* labels, CLikelihoodModel* model);
97 
98  virtual ~CInference();
99 
104  virtual EInferenceType get_inference_type() const { return INF_NONE; }
105 
118 
155  float64_t get_marginal_likelihood_estimate(int32_t num_importance_samples=1,
156  float64_t ridge_size=1e-15);
157 
173  CSGObject*>* parameters);
174 
188  virtual SGVector<float64_t> get_alpha()=0;
189 
195  virtual SGMatrix<float64_t> get_cholesky()=0;
196 
203 
220 
237 
246  CMap<TParameter*, CSGObject*>* parameters)
247  {
249  }
250 
256  {
257  SGVector<float64_t> result(1);
259  return result;
260  }
261 
267 
272  virtual void set_features(CFeatures* feat)
273  {
274  SG_REF(feat);
276  m_features=feat;
277  }
278 
283  virtual CKernel* get_kernel() { SG_REF(m_kernel); return m_kernel; }
284 
289  virtual void set_kernel(CKernel* kern)
290  {
291  SG_REF(kern);
293  m_kernel=kern;
294  }
295 
300  virtual CMeanFunction* get_mean() { SG_REF(m_mean); return m_mean; }
301 
306  virtual void set_mean(CMeanFunction* m)
307  {
308  SG_REF(m);
309  SG_UNREF(m_mean);
310  m_mean=m;
311  }
312 
317  virtual CLabels* get_labels() { SG_REF(m_labels); return m_labels; }
318 
323  virtual void set_labels(CLabels* lab)
324  {
325  SG_REF(lab);
327  m_labels=lab;
328  }
329 
335 
340  virtual void set_model(CLikelihoodModel* mod)
341  {
342  SG_REF(mod);
343  SG_UNREF(m_model);
344  m_model=mod;
345  }
346 
351  virtual float64_t get_scale() const;
352 
357  virtual void set_scale(float64_t scale);
358 
364  virtual bool supports_regression() const { return false; }
365 
371  virtual bool supports_binary() const { return false; }
372 
378  virtual bool supports_multiclass() const { return false; }
379 
381  virtual void update();
382 
389 
394  virtual void register_minimizer(Minimizer* minimizer);
395 protected:
397  virtual void check_members() const;
398 
400  virtual void update_alpha()=0;
401 
403  virtual void update_chol()=0;
404 
408  virtual void update_deriv()=0;
409 
411  virtual void update_train_kernel();
412 
421  const TParameter* param)=0;
422 
431  const TParameter* param)=0;
432 
441  const TParameter* param)=0;
442 
451  const TParameter* param)=0;
452 
456  static void* get_derivative_helper(void* p);
457 
459  virtual void compute_gradient();
460 
461 private:
462  void init();
463 
464 protected:
467 
470 
473 
476 
479 
482 
485 
488 
491 
494 
497 
500 };
501 }
502 #endif /* CINFERENCE_H_ */
float64_t m_log_scale
Definition: Inference.h:490
virtual void update_train_kernel()
Definition: Inference.cpp:337
virtual void update()
Definition: Inference.cpp:316
virtual SGMatrix< float64_t > get_cholesky()=0
virtual ~CInference()
Definition: Inference.cpp:91
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
virtual EInferenceType get_inference_type() const
Definition: Inference.h:104
virtual void update_alpha()=0
CKernel * m_kernel
Definition: Inference.h:469
virtual bool supports_binary() const
Definition: Inference.h:371
virtual void update_chol()=0
static void * get_derivative_helper(void *p)
Definition: Inference.cpp:268
virtual CKernel * get_kernel()
Definition: Inference.h:283
parameter struct
virtual void set_scale(float64_t scale)
Definition: Inference.cpp:65
virtual CLabels * get_labels()
Definition: Inference.h:317
virtual CFeatures * get_features()
Definition: Inference.h:266
SGMatrix< float64_t > m_E
Definition: Inference.h:496
An abstract class of the mean function.
Definition: MeanFunction.h:49
virtual void set_labels(CLabels *lab)
Definition: Inference.h:323
#define SG_REF(x)
Definition: SGObject.h:54
CFeatures * m_features
Definition: Inference.h:478
SGMatrix< float64_t > m_ktrtr
Definition: Inference.h:493
virtual SGVector< float64_t > get_derivative_wrt_mean(const TParameter *param)=0
virtual SGMatrix< float64_t > get_posterior_covariance()=0
CMeanFunction * m_mean
Definition: Inference.h:472
virtual void update_deriv()=0
virtual SGMatrix< float64_t > get_multiclass_E()
Definition: Inference.cpp:71
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
CLabels * m_labels
Definition: Inference.h:481
virtual float64_t get_scale() const
Definition: Inference.cpp:60
virtual bool supports_regression() const
Definition: Inference.h:364
virtual SGVector< float64_t > get_diagonal_vector()=0
double float64_t
Definition: common.h:50
virtual void compute_gradient()
Definition: Inference.cpp:343
virtual CMap< TParameter *, SGVector< float64_t > > * get_gradient(CMap< TParameter *, CSGObject * > *parameters)
Definition: Inference.h:245
EInferenceType
Definition: Inference.h:53
An abstract class that describes a differentiable function used for GradientEvaluation.
virtual SGVector< float64_t > get_alpha()=0
virtual void set_model(CLikelihoodModel *mod)
Definition: Inference.h:340
virtual void set_kernel(CKernel *kern)
Definition: Inference.h:289
virtual SGVector< float64_t > get_derivative_wrt_inference_method(const TParameter *param)=0
SGMatrix< float64_t > m_L
Definition: Inference.h:487
virtual SGVector< float64_t > get_posterior_mean()=0
virtual float64_t get_negative_log_marginal_likelihood()=0
virtual SGVector< float64_t > get_value()
Definition: Inference.h:255
CLikelihoodModel * get_model()
Definition: Inference.h:334
virtual void register_minimizer(Minimizer *minimizer)
Definition: Inference.cpp:128
virtual void set_features(CFeatures *feat)
Definition: Inference.h:272
virtual SGVector< float64_t > get_derivative_wrt_kernel(const TParameter *param)=0
#define SG_UNREF(x)
Definition: SGObject.h:55
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The Inference Method base class.
Definition: Inference.h:81
float64_t get_marginal_likelihood_estimate(int32_t num_importance_samples=1, float64_t ridge_size=1e-15)
Definition: Inference.cpp:139
virtual CMeanFunction * get_mean()
Definition: Inference.h:300
Minimizer * m_minimizer
Definition: Inference.h:466
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:94
The Kernel base class.
Definition: Kernel.h:159
virtual CMap< TParameter *, SGVector< float64_t > > * get_negative_log_marginal_likelihood_derivatives(CMap< TParameter *, CSGObject * > *parameters)
Definition: Inference.cpp:198
The minimizer base class.
Definition: Minimizer.h:43
virtual bool supports_multiclass() const
Definition: Inference.h:378
CLikelihoodModel * m_model
Definition: Inference.h:475
virtual void set_mean(CMeanFunction *m)
Definition: Inference.h:306
The Likelihood model base class.
SGVector< float64_t > m_alpha
Definition: Inference.h:484
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...
Definition: SGObject.h:39
virtual void check_members() const
Definition: Inference.cpp:322
virtual SGVector< float64_t > get_derivative_wrt_likelihood_model(const TParameter *param)=0

SHOGUN Machine Learning Toolbox - Documentation