SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
InferenceMethod.h
浏览该文件的文档.
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 CINFERENCEMETHOD_H_
35 #define CINFERENCEMETHOD_H_
36 
37 #include <shogun/lib/config.h>
38 
39 #ifdef HAVE_EIGEN3
40 
41 #include <shogun/base/SGObject.h>
42 #include <shogun/kernel/Kernel.h>
44 #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:
86 
95  CInferenceMethod(CKernel* kernel, CFeatures* features,
96  CMeanFunction* mean, CLabels* labels, CLikelihoodModel* model);
97 
98  virtual ~CInferenceMethod();
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 
202  virtual SGVector<float64_t> get_diagonal_vector()=0;
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 
390 protected:
392  virtual void check_members() const;
393 
395  virtual void update_alpha()=0;
396 
398  virtual void update_chol()=0;
399 
403  virtual void update_deriv()=0;
404 
406  virtual void update_train_kernel();
407 
416  const TParameter* param)=0;
417 
426  const TParameter* param)=0;
427 
436  const TParameter* param)=0;
437 
446  const TParameter* param)=0;
447 
451  static void* get_derivative_helper(void* p);
452 
454  virtual void compute_gradient();
455 private:
456  void init();
457 
458 protected:
461 
464 
467 
470 
473 
476 
479 
482 
485 
488 
491 };
492 }
493 #endif /* HAVE_EIGEN3 */
494 #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:49
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 机器学习工具包 - 项目文档