SHOGUN  4.0.0
InferenceMethod.h
浏览该文件的文档.
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  * Copyright (C) 2012 Jacob Walker
10  * Copyright (C) 2013 Roman Votyakov
11  */
12 
13 #ifndef CINFERENCEMETHOD_H_
14 #define CINFERENCEMETHOD_H_
15 
16 #include <shogun/lib/config.h>
17 
18 #ifdef HAVE_EIGEN3
19 
20 #include <shogun/base/SGObject.h>
21 #include <shogun/kernel/Kernel.h>
23 #include <shogun/labels/Labels.h>
27 
28 namespace shogun
29 {
30 
33 {
38  INF_EP=40,
39  INF_KL=50
40 };
41 
52 {
53 public:
56 
65  CInferenceMethod(CKernel* kernel, CFeatures* features,
66  CMeanFunction* mean, CLabels* labels, CLikelihoodModel* model);
67 
68  virtual ~CInferenceMethod();
69 
74  virtual EInferenceType get_inference_type() const { return INF_NONE; }
75 
88 
125  float64_t get_marginal_likelihood_estimate(int32_t num_importance_samples=1,
126  float64_t ridge_size=1e-15);
127 
143  CSGObject*>* parameters);
144 
158  virtual SGVector<float64_t> get_alpha()=0;
159 
165  virtual SGMatrix<float64_t> get_cholesky()=0;
166 
172  virtual SGVector<float64_t> get_diagonal_vector()=0;
173 
190 
207 
216  CMap<TParameter*, CSGObject*>* parameters)
217  {
219  }
220 
226  {
227  SGVector<float64_t> result(1);
229  return result;
230  }
231 
237 
242  virtual void set_features(CFeatures* feat)
243  {
244  SG_REF(feat);
246  m_features=feat;
247  }
248 
253  virtual CKernel* get_kernel() { SG_REF(m_kernel); return m_kernel; }
254 
259  virtual void set_kernel(CKernel* kern)
260  {
261  SG_REF(kern);
263  m_kernel=kern;
264  }
265 
270  virtual CMeanFunction* get_mean() { SG_REF(m_mean); return m_mean; }
271 
276  virtual void set_mean(CMeanFunction* m)
277  {
278  SG_REF(m);
279  SG_UNREF(m_mean);
280  m_mean=m;
281  }
282 
287  virtual CLabels* get_labels() { SG_REF(m_labels); return m_labels; }
288 
293  virtual void set_labels(CLabels* lab)
294  {
295  SG_REF(lab);
297  m_labels=lab;
298  }
299 
305 
310  virtual void set_model(CLikelihoodModel* mod)
311  {
312  SG_REF(mod);
313  SG_UNREF(m_model);
314  m_model=mod;
315  }
316 
321  virtual float64_t get_scale() const { return m_scale; }
322 
327  virtual void set_scale(float64_t scale) { m_scale=scale; }
328 
334  virtual bool supports_regression() const { return false; }
335 
341  virtual bool supports_binary() const { return false; }
342 
348  virtual bool supports_multiclass() const { return false; }
349 
351  virtual void update();
352 
359 
360 protected:
362  virtual void check_members() const;
363 
365  virtual void update_alpha()=0;
366 
368  virtual void update_chol()=0;
369 
373  virtual void update_deriv()=0;
374 
376  virtual void update_train_kernel();
377 
386  const TParameter* param)=0;
387 
396  const TParameter* param)=0;
397 
406  const TParameter* param)=0;
407 
416  const TParameter* param)=0;
417 
421  static void* get_derivative_helper(void* p);
422 
423 private:
424  void init();
425 
426 protected:
429 
432 
435 
438 
441 
444 
447 
450 
453 
456 };
457 }
458 #endif /* HAVE_EIGEN3 */
459 #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
Definition: Parameter.h:32
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()
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...
Definition: SGObject.h:36
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:83
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:153
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
static void * get_derivative_helper(void *p)

SHOGUN 机器学习工具包 - 项目文档