SHOGUN  6.1.3
KLDualInferenceMethod.cpp
Go to the documentation of this file.
1  /*
2  * Copyright (c) The Shogun Machine Learning Toolbox
3  * Written (w) 2014 Wu Lin
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * The views and conclusions contained in the software and documentation are those
27  * of the authors and should not be interpreted as representing official policies,
28  * either expressed or implied, of the Shogun Development Team.
29  *
30  * Code adapted from
31  * http://hannes.nickisch.org/code/approxXX.tar.gz
32  * and Gaussian Process Machine Learning Toolbox
33  * http://www.gaussianprocess.org/gpml/code/matlab/doc/
34  * and the reference paper is
35  * Mohammad Emtiyaz Khan, Aleksandr Y. Aravkin, Michael P. Friedlander, Matthias Seeger
36  * Fast Dual Variational Inference for Non-Conjugate Latent Gaussian Models. ICML2013*
37  *
38  * This code specifically adapted from function in approxKL.m and infKL.m
39  */
40 
42 
48 
49 using namespace Eigen;
50 
51 namespace shogun
52 {
53 #ifndef DOXYGEN_SHOULD_SKIP_THIS
54 class KLDualInferenceMethodCostFunction: public FirstOrderCostFunction
55 {
56 friend class CKLDualInferenceMethodMinimizer;
57 public:
58  KLDualInferenceMethodCostFunction():FirstOrderCostFunction() { init(); }
59  virtual ~KLDualInferenceMethodCostFunction() { SG_UNREF(m_obj); }
60  void set_target(CKLDualInferenceMethod *obj)
61  {
62  REQUIRE(obj, "Obj must set\n");
63  if(m_obj != obj)
64  {
65  SG_REF(obj);
66  SG_UNREF(m_obj);
67  m_obj=obj;
68  }
69  }
70  void unset_target(bool is_unref)
71  {
72  if(is_unref)
73  {
74  SG_UNREF(m_obj);
75  }
76  m_obj=NULL;
77  }
78  virtual float64_t get_cost()
79  {
80  REQUIRE(m_obj,"Object not set\n");
81  bool status=m_obj->precompute();
82  if (status)
83  {
84  float64_t nlml=m_obj->get_dual_objective_wrt_parameters();
85  return nlml;
86  }
87  return CMath::NOT_A_NUMBER;
88  }
89  virtual SGVector<float64_t> obtain_variable_reference()
90  {
91  REQUIRE(m_obj,"Object not set\n");
92  m_derivatives = SGVector<float64_t>((m_obj->m_W).vlen);
93  return m_obj->m_W;
94  }
95  virtual SGVector<float64_t> get_gradient()
96  {
97  REQUIRE(m_obj,"Object not set\n");
98  m_obj->get_gradient_of_dual_objective_wrt_parameters(m_derivatives);
99  return m_derivatives;
100  }
101  virtual const char* get_name() const { return "KLDualInferenceMethodCostFunction"; }
102 private:
103  SGVector<float64_t> m_derivatives;
104  void init()
105  {
106  m_obj=NULL;
107  m_derivatives = SGVector<float64_t>();
108  SG_ADD(&m_derivatives, "KLDualInferenceMethodCostFunction__m_derivatives",
109  "derivatives in KLDualInferenceMethodCostFunction", MS_NOT_AVAILABLE);
110  SG_ADD((CSGObject **)&m_obj, "KLDualInferenceMethodCostFunction__m_obj",
111  "obj in KLDualInferenceMethodCostFunction", MS_NOT_AVAILABLE);
112  }
113  CKLDualInferenceMethod *m_obj;
114  CDualVariationalGaussianLikelihood* get_dual_variational_likelihood() const
115  {
116  REQUIRE(m_obj,"Object not set\n");
117  return m_obj->get_dual_variational_likelihood();
118  }
119 };
120 #endif //DOXYGEN_SHOULD_SKIP_THIS
121 
122 void CKLDualInferenceMethodMinimizer::init_minimization()
123 {
124  ELBFGSLineSearch linesearch=LBFGSLineSearchHelper::get_lbfgs_linear_search(m_linesearch_id);
125  REQUIRE((linesearch == BACKTRACKING_ARMIJO) ||
126  (linesearch == BACKTRACKING_WOLFE) ||
127  (linesearch == BACKTRACKING_STRONG_WOLFE),
128  "The provided line search method is not supported. Please use backtracking line search methods\n");
129  CLBFGSMinimizer::init_minimization();
130 }
131 
132 float64_t CKLDualInferenceMethodMinimizer::minimize()
133 {
134  lbfgs_parameter_t lbfgs_param;
135  lbfgs_param.m = m_m;
136  lbfgs_param.max_linesearch = m_max_linesearch;
137  lbfgs_param.linesearch = LBFGSLineSearchHelper::get_lbfgs_linear_search(m_linesearch_id);
138  lbfgs_param.max_iterations = m_max_iterations;
139  lbfgs_param.delta = m_delta;
140  lbfgs_param.past = m_past;
141  lbfgs_param.epsilon = m_epsilon;
142  lbfgs_param.min_step = m_min_step;
143  lbfgs_param.max_step = m_max_step;
144  lbfgs_param.ftol = m_ftol;
145  lbfgs_param.wolfe = m_wolfe;
146  lbfgs_param.gtol = m_gtol;
147  lbfgs_param.xtol = m_xtol;
148  lbfgs_param.orthantwise_c = m_orthantwise_c;
149  lbfgs_param.orthantwise_start = m_orthantwise_start;
150  lbfgs_param.orthantwise_end = m_orthantwise_end;
151 
152  init_minimization();
153 
154  float64_t cost=0.0;
155  int error_code=lbfgs(m_target_variable.vlen, m_target_variable.vector,
156  &cost, CKLDualInferenceMethodMinimizer::evaluate,
157  NULL, this, &lbfgs_param, CKLDualInferenceMethodMinimizer::adjust_step);
158 
159  if(error_code!=0 && error_code!=LBFGS_ALREADY_MINIMIZED)
160  {
161  SG_SWARNING("Error(s) happened during L-BFGS optimization (error code:%d)\n",
162  error_code);
163  }
164  return cost;
165 }
166 
167 float64_t CKLDualInferenceMethodMinimizer::evaluate(void *obj, const float64_t *variable,
168  float64_t *gradient, const int dim, const float64_t step)
169 {
170  /* Note that parameters = parameters_pre_iter - step * gradient_pre_iter */
172  = static_cast<CKLDualInferenceMethodMinimizer *>(obj);
173 
174  REQUIRE(obj_prt, "The instance object passed to L-BFGS optimizer should not be NULL\n");
175 
176  float64_t cost=obj_prt->m_fun->get_cost();
177  if (CMath::is_nan(cost) || CMath::is_infinity(cost))
178  return cost;
179  //get the gradient wrt variable_new
180  SGVector<float64_t> grad=obj_prt->m_fun->get_gradient();
181  REQUIRE(grad.vlen==dim,
182  "The length of gradient (%d) and the length of variable (%d) do not match\n",
183  grad.vlen,dim);
184 
185  std::copy(grad.vector,grad.vector+dim,gradient);
186  return cost;
187 }
188 
189 float64_t CKLDualInferenceMethodMinimizer::adjust_step(void *obj, const float64_t *parameters,
190  const float64_t *direction, const int dim, const float64_t step)
191 {
192  /* Note that parameters = parameters_pre_iter - step * gradient_pre_iter */
194  = static_cast<CKLDualInferenceMethodMinimizer *>(obj);
195 
196  REQUIRE(obj_prt, "The instance object passed to L-BFGS optimizer should not be NULL\n");
197 
198  float64_t *non_const_direction=const_cast<float64_t *>(direction);
199  SGVector<float64_t> sg_direction(non_const_direction, dim, false);
200 
201  KLDualInferenceMethodCostFunction* fun=dynamic_cast<KLDualInferenceMethodCostFunction*>(obj_prt->m_fun);
202  REQUIRE(fun, "The cost function must be KLDualInferenceMethodCostFunction\n");
203 
204  CDualVariationalGaussianLikelihood* lik=fun->get_dual_variational_likelihood();
205 
206  float64_t adjust_stp=lik->adjust_step_wrt_dual_parameter(sg_direction, step);
207  return adjust_stp;
208 }
209 
210 CKLDualInferenceMethod::CKLDualInferenceMethod() : CKLInference()
211 {
212  init();
213 }
214 
216  CFeatures* feat, CMeanFunction* m, CLabels* lab, CLikelihoodModel* mod)
217  : CKLInference(kern, feat, m, lab, mod)
218 {
219  init();
220 }
221 
223  CInference* inference)
224 {
225  if (inference==NULL)
226  return NULL;
227 
228  if (inference->get_inference_type()!=INF_KL_DUAL)
229  {
230  SG_SERROR("Provided inference is not of type CKLDualInferenceMethod!\n");
231  }
232 
233  SG_REF(inference);
234  return (CKLDualInferenceMethod*)inference;
235 }
236 
238 {
240  update();
241 
243  return result;
244 }
245 
247 {
248 }
249 
251 {
253  REQUIRE(lik,
254  "The provided likelihood model is not a variational dual Likelihood model.\n");
255 }
256 
258 {
261 }
262 
264 {
267  return lik;
268 }
269 
271 {
273  REQUIRE(opt,"The minimizer must be an instance of CKLDualInferenceMethodMinimizer\n");
275 }
276 
277 
278 void CKLDualInferenceMethod::init()
279 {
280  SG_ADD(&m_W, "W",
281  "noise matrix W",
283  SG_ADD(&m_sW, "sW",
284  "Square root of noise matrix W",
286  SG_ADD(&m_dv, "dv",
287  "the gradient of the variational expection wrt sigma2",
289  SG_ADD(&m_df, "df",
290  "the gradient of the variational expection wrt mu",
292  SG_ADD(&m_is_dual_valid, "is_dual_valid",
293  "whether the lambda (m_W) is valid or not",
295 
296  m_is_dual_valid=false;
298 }
299 
301 {
304  Map<VectorXd> eigen_W(m_W.vector, m_W.vlen);
305 
306  lik->set_dual_parameters(m_W, m_labels);
307  m_is_dual_valid=lik->dual_parameters_valid();
308 
309  if (!m_is_dual_valid)
310  return false;
311 
312  //construct alpha
314  Map<VectorXd> eigen_alpha(m_alpha.vector, m_alpha.vlen);
315  eigen_alpha=-eigen_alpha;
316 
317  Map<VectorXd> eigen_sW(m_sW.vector, m_sW.vlen);
318  eigen_sW=eigen_W.array().sqrt().matrix();
319 
322 
323  //solve L'*V=diag(sW)*K
324  Map<MatrixXd> eigen_V(m_V.matrix, m_V.num_rows, m_V.num_cols);
325  eigen_V=eigen_L.triangularView<Upper>().adjoint().solve(eigen_sW.asDiagonal()*eigen_K*CMath::exp(m_log_scale*2.0));
326  Map<VectorXd> eigen_s2(m_s2.vector, m_s2.vlen);
327  //Sigma=inv(inv(K)+diag(W))=K-K*diag(sW)*inv(L)'*inv(L)*diag(sW)*K
328  //v=abs(diag(Sigma))
329  eigen_s2=(eigen_K.diagonal().array()*CMath::exp(m_log_scale*2.0)-(eigen_V.array().pow(2).colwise().sum().transpose())).abs().matrix();
330 
331  //construct mu
333  Map<VectorXd> eigen_mean(mean.vector, mean.vlen);
334  Map<VectorXd> eigen_mu(m_mu.vector, m_mu.vlen);
335  //mu=K*alpha+m
336  eigen_mu=eigen_K*CMath::exp(m_log_scale*2.0)*eigen_alpha+eigen_mean;
337  return true;
338 }
339 
341 {
342  if (!m_is_dual_valid)
343  return CMath::INFTY;
344 
346  Map<VectorXd> eigen_mean(mean.vector, mean.vlen);
347  Map<VectorXd> eigen_mu(m_mu.vector, m_mu.vlen);
348  Map<VectorXd> eigen_alpha(m_alpha.vector, m_alpha.vlen);
350 
352 
354  float64_t result=0.5*eigen_alpha.dot(eigen_mu-eigen_mean)+a;
355  result+=eigen_mean.dot(eigen_alpha);
356  result-=eigen_L.diagonal().array().log().sum();
357 
358  return result;
359 }
360 
362 {
363  REQUIRE(gradient.vlen==m_alpha.vlen,
364  "The length of gradients (%d) should the same as the length of parameters (%d)\n",
365  gradient.vlen, m_alpha.vlen);
366 
367  if (!m_is_dual_valid)
368  return;
369 
370  Map<VectorXd> eigen_gradient(gradient.vector, gradient.vlen);
371 
373 
374  TParameter* lambda_param=lik->m_parameters->get_parameter("lambda");
375  SGVector<float64_t>d_lambda=lik->get_dual_first_derivative(lambda_param);
376  Map<VectorXd> eigen_d_lambda(d_lambda.vector, d_lambda.vlen);
377 
378  Map<VectorXd> eigen_mu(m_mu.vector, m_mu.vlen);
379  Map<VectorXd> eigen_s2(m_s2.vector, m_s2.vlen);
380 eigen_gradient=-eigen_mu-0.5*eigen_s2+eigen_d_lambda;
381 }
382 
383 float64_t CKLDualInferenceMethod::get_nlml_wrapper(SGVector<float64_t> alpha, SGVector<float64_t> mu, SGMatrix<float64_t> L)
384 {
385  Map<MatrixXd> eigen_L(L.matrix, L.num_rows, L.num_cols);
386  Map<VectorXd> eigen_alpha(alpha.vector, alpha.vlen);
388  //get mean vector and create eigen representation of it
390  Map<VectorXd> eigen_mu(mu.vector, mu.vlen);
391  Map<VectorXd> eigen_mean(mean.vector, mean.vlen);
392 
394 
395  SGVector<float64_t>lab=((CBinaryLabels*)m_labels)->get_labels();
396  Map<VectorXd> eigen_lab(lab.vector, lab.vlen);
397 
399 
400  float64_t trace=0;
401  //L_inv=L\eye(n);
402  //trace(L_inv'*L_inv) %V*inv(K)
403  MatrixXd eigen_t=eigen_L.triangularView<Upper>().adjoint().solve(MatrixXd::Identity(eigen_L.rows(),eigen_L.cols()));
404 
405  for(index_t idx=0; idx<eigen_t.rows(); idx++)
406  trace +=(eigen_t.col(idx).array().pow(2)).sum();
407 
408  //nlZ = -a -logdet(V*inv(K))/2 -n/2 +(alpha'*K*alpha)/2 +trace(V*inv(K))/2;
409  float64_t result=-a+eigen_L.diagonal().array().log().sum();
410 
411  result+=0.5*(-eigen_K.rows()+eigen_alpha.dot(eigen_mu-eigen_mean)+trace);
412  return result;
413 }
414 
416 {
418  bool status = lik->set_variational_distribution(m_mu, m_s2, m_labels);
419  if (status)
420  return get_nlml_wrapper(m_alpha, m_mu, m_L);
421  return CMath::NOT_A_NUMBER;
422 }
423 
425 {
426  Map<MatrixXd> eigen_dK(dK.matrix, dK.num_rows, dK.num_cols);
428  Map<VectorXd> eigen_W(m_W.vector, m_W.vlen);
430  Map<VectorXd> eigen_sW(m_sW.vector, m_sW.vlen);
432  Map<VectorXd> eigen_alpha(m_alpha.vector, m_alpha.vlen);
433 
434  Map<VectorXd> eigen_dv(m_dv.vector, m_dv.vlen);
435  Map<VectorXd> eigen_df(m_df.vector, m_df.vlen);
436 
437  index_t len=m_W.vlen;
438  //U=inv(L')*diag(sW)
439  MatrixXd eigen_U=eigen_L.triangularView<Upper>().adjoint().solve(MatrixXd(eigen_sW.asDiagonal()));
440  //A=I-K*diag(sW)*inv(L)*inv(L')*diag(sW)
441  Map<MatrixXd> eigen_V(m_V.matrix, m_V.num_rows, m_V.num_cols);
442  MatrixXd eigen_A=MatrixXd::Identity(len, len)-eigen_V.transpose()*eigen_U;
443 
444  //AdK = A*dK;
445  MatrixXd AdK=eigen_A*eigen_dK;
446 
447  //z = diag(AdK) + sum(A.*AdK,2) - sum(A'.*AdK,1)';
448  VectorXd z=AdK.diagonal()+(eigen_A.array()*AdK.array()).rowwise().sum().matrix()
449  -(eigen_A.transpose().array()*AdK.array()).colwise().sum().transpose().matrix();
450 
451  float64_t result=eigen_alpha.dot(eigen_dK*(eigen_alpha/2.0-eigen_df))-z.dot(eigen_dv);
452 
453  return result;
454 }
455 
457 {
458  float64_t nlml_new=0;
459  float64_t nlml_def=0;
460 
463 
465  {
468  SGVector<float64_t> W_tmp(len);
469  Map<VectorXd> eigen_W(W_tmp.vector, W_tmp.vlen);
470  eigen_W.fill(0.5);
471  SGVector<float64_t> sW_tmp(len);
472  Map<VectorXd> eigen_sW(sW_tmp.vector, sW_tmp.vlen);
473  eigen_sW=eigen_W.array().sqrt().matrix();
475  Map<MatrixXd> eigen_L(L_tmp.matrix, L_tmp.num_rows, L_tmp.num_cols);
476 
477  lik->set_dual_parameters(W_tmp, m_labels);
478 
479  //construct alpha
481  Map<VectorXd> eigen_alpha(alpha_tmp.vector, alpha_tmp.vlen);
482  eigen_alpha=-eigen_alpha;
483  //construct mu
485  Map<VectorXd> eigen_mean(mean.vector, mean.vlen);
486  SGVector<float64_t> mu_tmp(len);
487  Map<VectorXd> eigen_mu(mu_tmp.vector, mu_tmp.vlen);
488  //mu=K*alpha+m
489  eigen_mu=eigen_K*CMath::exp(m_log_scale*2.0)*eigen_alpha+eigen_mean;
490  //construct s2
491  MatrixXd eigen_V=eigen_L.triangularView<Upper>().adjoint().solve(eigen_sW.asDiagonal()*eigen_K*CMath::exp(m_log_scale*2.0));
492  SGVector<float64_t> s2_tmp(len);
493  Map<VectorXd> eigen_s2(s2_tmp.vector, s2_tmp.vlen);
494  eigen_s2=(eigen_K.diagonal().array()*CMath::exp(m_log_scale*2.0)-(eigen_V.array().pow(2).colwise().sum().transpose())).abs().matrix();
495 
496  lik->set_variational_distribution(mu_tmp, s2_tmp, m_labels);
497 
498  nlml_def=get_nlml_wrapper(alpha_tmp, mu_tmp, L_tmp);
499 
500  if (nlml_new<=nlml_def)
501  {
502  lik->set_dual_parameters(m_W, m_labels);
504  }
505  }
506 
507  if (m_alpha.vlen != m_labels->get_num_labels() || nlml_def<nlml_new)
508  {
511 
512  index_t len=m_alpha.vlen;
513 
514  m_W=SGVector<float64_t>(len);
515  for (index_t i=0; i<m_W.vlen; i++)
516  m_W[i]=0.5;
517 
518  lik->set_dual_parameters(m_W, m_labels);
519  m_sW=SGVector<float64_t>(len);
522  m_Sigma=SGMatrix<float64_t>(len, len);
523  m_Sigma.zero();
524  m_V=SGMatrix<float64_t>(len, len);
525  }
526 
527  nlml_new=optimization();
529  TParameter* s2_param=lik->m_parameters->get_parameter("sigma2");
530  m_dv=lik->get_variational_first_derivative(s2_param);
531  TParameter* mu_param=lik->m_parameters->get_parameter("mu");
532  m_df=lik->get_variational_first_derivative(mu_param);
533 }
534 
536 {
538  REQUIRE(minimizer,"The minimizer must be an instance of KLDualInferenceMethodMinimizer\n");
540  cost_fun->set_target(this);
541  bool cleanup=false;
542 
543  if(this->ref_count()>1)
544  cleanup=true;
545 
546  minimizer->set_cost_function(cost_fun);
547  float64_t nlml_opt = minimizer->minimize();
548  minimizer->unset_cost_function(false);
549  cost_fun->unset_target(cleanup);
550  SG_UNREF(cost_fun);
551  return nlml_opt;
552 }
553 
555 {
557  update();
558 
559  return SGVector<float64_t>(m_sW);
560 }
561 
563 {
564  /* get_derivative_related_cov(MatrixXd eigen_dK) does the similar job
565  * Therefore, this function body is empty
566  */
567 }
568 
570 {
571  /* L is automatically updated when update_alpha is called
572  * Therefore, this function body is empty
573  */
574 }
575 
577 {
579 }
580 
581 } /* namespace shogun */
582 
virtual SGVector< float64_t > get_gradient()=0
float64_t m_log_scale
Definition: Inference.h:485
virtual CDualVariationalGaussianLikelihood * get_dual_variational_likelihood() const
int32_t lbfgs(int32_t n, float64_t *x, float64_t *ptr_fx, lbfgs_evaluate_t proc_evaluate, lbfgs_progress_t proc_progress, void *instance, lbfgs_parameter_t *_param, lbfgs_adjust_step_t proc_adjust_step)
Definition: lbfgs.cpp:210
virtual void update()
virtual void set_dual_parameters(SGVector< float64_t > the_lambda, const CLabels *lab)
static SGMatrix< float64_t > get_choleksy(SGVector< float64_t > W, SGVector< float64_t > sW, SGMatrix< float64_t > kernel, float64_t scale)
virtual SGVector< float64_t > get_mu_dual_parameter() const =0
int32_t index_t
Definition: common.h:72
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
static const float64_t INFTY
infinity
Definition: Math.h:1868
virtual EInferenceType get_inference_type() const
Definition: Inference.h:104
virtual int32_t get_num_labels() const =0
static T sum(T *vec, int32_t len)
Return sum(vec)
Definition: SGVector.h:418
static SGMatrix< float64_t > get_inverse(SGMatrix< float64_t > L, SGMatrix< float64_t > kernel, SGVector< float64_t > sW, SGMatrix< float64_t > V, float64_t scale)
#define SG_SWARNING(...)
Definition: SGIO.h:163
TParameter * get_parameter(int32_t idx)
virtual void set_model(CLikelihoodModel *mod)
float64_t orthantwise_c
Definition: lbfgs.h:313
Definition: SGMatrix.h:25
FirstOrderCostFunction * m_fun
parameter struct
virtual SGVector< float64_t > get_dual_objective_value()=0
#define REQUIRE(x,...)
Definition: SGIO.h:181
Parameter * m_parameters
Definition: SGObject.h:609
virtual SGVector< float64_t > get_mean_vector(const CFeatures *features) const =0
Build-in minimizer for KLDualInference.
An abstract class of the mean function.
Definition: MeanFunction.h:49
std::enable_if<!std::is_same< T, complex128_t >::value, float64_t >::type mean(const Container< T > &a)
#define SG_REF(x)
Definition: SGObject.h:52
T trace(const SGMatrix< T > &A)
CFeatures * m_features
Definition: Inference.h:473
SGMatrix< float64_t > m_ktrtr
Definition: Inference.h:488
CMeanFunction * m_mean
Definition: Inference.h:467
virtual float64_t adjust_step_wrt_dual_parameter(SGVector< float64_t > direction, const float64_t step) const
virtual void check_dual_inference(CLikelihoodModel *mod) const
The dual KL approximation inference method class.
virtual void register_minimizer(Minimizer *minimizer)
void set_model(CLikelihoodModel *mod)
The KL approximation inference method class.
Definition: KLInference.h:75
virtual void get_gradient_of_dual_objective_wrt_parameters(SGVector< float64_t > gradient)
virtual SGVector< float64_t > get_alpha()
CLabels * m_labels
Definition: Inference.h:476
virtual void unset_cost_function(bool is_unref=true)
static CKLDualInferenceMethod * obtain_from_generic(CInference *inference)
double float64_t
Definition: common.h:60
virtual bool set_variational_distribution(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab)
index_t num_rows
Definition: SGMatrix.h:495
virtual SGVector< float64_t > get_dual_first_derivative(const TParameter *param) const =0
SGVector< float64_t > m_mu
Definition: KLInference.h:367
SGMatrix< float64_t > m_L
Definition: Inference.h:482
Matrix< float64_t,-1,-1, 0,-1,-1 > MatrixXd
Definition: KLInference.h:52
index_t num_cols
Definition: SGMatrix.h:497
virtual float64_t get_cost()=0
SGMatrix< float64_t > m_Sigma
Definition: KLInference.h:370
virtual float64_t get_derivative_related_cov(SGMatrix< float64_t > dK)
virtual void register_minimizer(Minimizer *minimizer)
Definition: Inference.cpp:116
SGVector< float64_t > m_s2
Definition: KLInference.h:375
#define SG_UNREF(x)
Definition: SGObject.h:53
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
T sum(const Container< T > &a, bool no_diag=false)
The Inference Method base class.
Definition: Inference.h:81
Minimizer * m_minimizer
Definition: Inference.h:461
The class Features is the base class of all feature objects.
Definition: Features.h:69
ELBFGSLineSearch
Definition: lbfgscommon.h:13
#define SG_SERROR(...)
Definition: SGIO.h:164
static float64_t exp(float64_t x)
Definition: Math.h:551
The Kernel base class.
Binary Labels for binary classification.
Definition: BinaryLabels.h:37
int32_t ref_count()
Definition: SGObject.cpp:193
The minimizer base class.
Definition: Minimizer.h:43
#define SG_ADD(...)
Definition: SGObject.h:93
virtual float64_t get_dual_objective_wrt_parameters()
virtual float64_t get_negative_log_marginal_likelihood_helper()
virtual SGVector< float64_t > get_diagonal_vector()
CLikelihoodModel * m_model
Definition: Inference.h:470
virtual SGVector< float64_t > get_variational_first_derivative(const TParameter *param) const
virtual bool parameter_hash_changed()
Definition: SGObject.cpp:296
Class that models dual variational likelihood.
The Likelihood model base class.
static const float64_t NOT_A_NUMBER
not a number
Definition: Math.h:1866
virtual void set_cost_function(FirstOrderCostFunction *fun)
index_t vlen
Definition: SGVector.h:571
SGVector< float64_t > m_alpha
Definition: Inference.h:479

SHOGUN Machine Learning Toolbox - Documentation