SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LaplacianInferenceBase.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) The Shogun Machine Learning Toolbox
3  * Written (w) 2014 Wu Lin
4  * Written (W) 2013 Roman Votyakov
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * The views and conclusions contained in the software and documentation are those
28  * of the authors and should not be interpreted as representing official policies,
29  * either expressed or implied, of the Shogun Development Team.
30  *
31  */
32 
34 
35 #ifdef HAVE_EIGEN3
36 
38 #include <shogun/lib/external/brent.h>
40 
41 using namespace shogun;
42 using namespace Eigen;
43 
44 namespace shogun
45 {
46 
48 {
49  init();
50 }
51 
53  CFeatures* feat, CMeanFunction* m, CLabels* lab, CLikelihoodModel* mod)
54  : CInferenceMethod(kern, feat, m, lab, mod)
55 {
56  init();
57 }
58 
59 void CLaplacianInferenceBase::init()
60 {
61  m_iter=20;
62  m_tolerance=1e-6;
63  m_opt_tolerance=1e-10;
64  m_opt_max=10;
65 
66  SG_ADD(&m_dlp, "dlp", "derivative of log likelihood with respect to function location", MS_NOT_AVAILABLE);
67  SG_ADD(&m_mu, "mu", "mean vector of the approximation to the posterior", MS_NOT_AVAILABLE);
68  SG_ADD(&m_Sigma, "Sigma", "covariance matrix of the approximation to the posterior", MS_NOT_AVAILABLE);
69  SG_ADD(&m_W, "W", "the noise matrix", MS_NOT_AVAILABLE);
70  SG_ADD(&m_tolerance, "tolerance", "amount of tolerance for Newton's iterations", MS_NOT_AVAILABLE);
71  SG_ADD(&m_iter, "iter", "max Newton's iterations", MS_NOT_AVAILABLE);
72  SG_ADD(&m_opt_tolerance, "opt_tolerance", "amount of tolerance for Brent's minimization method", MS_NOT_AVAILABLE);
73  SG_ADD(&m_opt_max, "opt_max", "max iterations for Brent's minimization method", MS_NOT_AVAILABLE);
74 }
75 
77 {
78 }
79 
81 {
83 
84  if (!m_gradient_update)
85  {
87  update_deriv();
88  m_gradient_update=true;
90  }
91 }
93 {
94  SG_DEBUG("entering\n");
95 
97  update_alpha();
98  update_chol();
99  m_gradient_update=false;
101 
102  SG_DEBUG("leaving\n");
103 }
104 
105 SGVector<float64_t> CLaplacianInferenceBase::get_alpha()
106 {
108  update();
109 
111  return result;
112 
113 }
114 
116 {
118  update();
119 
120  return SGMatrix<float64_t>(m_L);
121 
122 }
123 
125 {
127 
129 }
130 
131 }
132 
133 #endif /* HAVE_EIGEN3 */
virtual void update_parameter_hash()
Definition: SGObject.cpp:248
virtual void update_alpha()=0
SGVector< float64_t > m_alpha
virtual void update_approx_cov()=0
The Inference Method base class.
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
Definition: SGMatrix.h:20
An abstract class of the mean function.
Definition: MeanFunction.h:49
SGMatrix< float64_t > m_L
virtual SGMatrix< float64_t > get_cholesky()
#define SG_DEBUG(...)
Definition: SGIO.h:107
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The class Features is the base class of all feature objects.
Definition: Features.h:68
virtual void update_chol()=0
virtual SGMatrix< float64_t > get_posterior_covariance()
The Kernel base class.
Definition: Kernel.h:158
#define SG_ADD(...)
Definition: SGObject.h:81
virtual void update_deriv()=0
virtual bool parameter_hash_changed()
Definition: SGObject.cpp:262
The Likelihood model base class.

SHOGUN Machine Learning Toolbox - Documentation