SHOGUN  6.1.3
LogitDVGLikelihood.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  */
31 
33 
40 
41 using namespace Eigen;
42 
43 namespace shogun
44 {
45 
46 CLogitDVGLikelihood::CLogitDVGLikelihood()
48 {
49  init();
50 }
51 
53 {
54 }
55 
57 {
59 
60  return lambda;
61 }
62 
64 {
66 
67  for (index_t i=0; i<alpha.vlen; i++)
68  alpha[i]-=m_lab[i];
69 
70  return alpha;
71 }
72 
74 {
76 
77  if (!m_is_valid)
78  {
79  Map<VectorXd> eigen_reslut(result.vector, result.vlen);
80  eigen_reslut.fill(CMath::INFTY);
81  return result;
82  }
83 
84  for (index_t i=0; i<result.vlen; ++i)
85  {
86  float64_t lambda=m_lambda[i];
87  result[i]=lambda*CMath::log(lambda)+(1.0-lambda)*CMath::log(1.0-lambda);
88  }
89  return result;
90 }
91 
93  const TParameter* param) const
94 {
95  REQUIRE(param, "Param is required (param should not be NULL)\n");
96  REQUIRE(param->m_name, "Param name is required (param->m_name should not be NULL)\n");
97  REQUIRE(!strcmp(param->m_name, "lambda"),
98  "Can't compute derivative of the variational expection ",
99  "of log LogitLikelihood in dual setting",
100  "wrt %s.%s parameter. The function only accepts lambda as parameter\n",
101  get_name(), param->m_name);
102 
104 
105  if (!m_is_valid)
106  {
107  Map<VectorXd> eigen_reslut(result.vector, result.vlen);
108  eigen_reslut.fill(CMath::INFTY);
109  return result;
110  }
111 
112  for (index_t i=0; i<result.vlen; ++i)
113  {
114  float64_t lambda=m_lambda[i];
115  result[i]=CMath::log(lambda)-CMath::log(1.0-lambda);
116  }
117  return result;
118 }
119 
121 {
123 }
124 
125 void CLogitDVGLikelihood::init()
126 {
127  init_likelihood();
128 }
129 
130 } /* namespace shogun */
int32_t index_t
Definition: common.h:72
static const float64_t INFTY
infinity
Definition: Math.h:1868
Definition: SGMatrix.h:25
parameter struct
#define REQUIRE(x,...)
Definition: SGIO.h:181
virtual void set_likelihood(CLikelihoodModel *lik)
double float64_t
Definition: common.h:60
virtual SGVector< float64_t > get_dual_objective_value()
SGVector< T > clone() const
Definition: SGVector.cpp:262
virtual const char * get_name() const
Class that models Logit likelihood and uses numerical integration to approximate the following variat...
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
static float64_t log(float64_t v)
Definition: Math.h:714
Class that models dual variational likelihood.
virtual SGVector< float64_t > get_mu_dual_parameter() const
virtual SGVector< float64_t > get_variance_dual_parameter() const
index_t vlen
Definition: SGVector.h:571
virtual SGVector< float64_t > get_dual_first_derivative(const TParameter *param) const

SHOGUN Machine Learning Toolbox - Documentation