SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
34 #ifdef HAVE_EIGEN3
41 
42 using namespace Eigen;
43 
44 namespace shogun
45 {
46 
47 CLogitDVGLikelihood::CLogitDVGLikelihood()
49 {
50  init();
51 }
52 
54 {
55 }
56 
58 {
60 
61  return lambda;
62 }
63 
65 {
67 
68  for (index_t i=0; i<alpha.vlen; i++)
69  alpha[i]-=m_lab[i];
70 
71  return alpha;
72 }
73 
75 {
77 
78  if (!m_is_valid)
79  {
80  Map<VectorXd> eigen_reslut(result.vector, result.vlen);
81  eigen_reslut.fill(CMath::INFTY);
82  return result;
83  }
84 
85  for (index_t i=0; i<result.vlen; ++i)
86  {
87  float64_t lambda=m_lambda[i];
88  result[i]=lambda*CMath::log(lambda)+(1.0-lambda)*CMath::log(1.0-lambda);
89  }
90  return result;
91 }
92 
94  const TParameter* param) const
95 {
96  REQUIRE(param, "Param is required (param should not be NULL)\n");
97  REQUIRE(param->m_name, "Param name is required (param->m_name should not be NULL)\n");
98  REQUIRE(!strcmp(param->m_name, "lambda"),
99  "Can't compute derivative of the variational expection ",
100  "of log LogitLikelihood in dual setting",
101  "wrt %s.%s parameter. The function only accepts lambda as parameter\n",
102  get_name(), param->m_name);
103 
105 
106  if (!m_is_valid)
107  {
108  Map<VectorXd> eigen_reslut(result.vector, result.vlen);
109  eigen_reslut.fill(CMath::INFTY);
110  return result;
111  }
112 
113  for (index_t i=0; i<result.vlen; ++i)
114  {
115  float64_t lambda=m_lambda[i];
116  result[i]=CMath::log(lambda)-CMath::log(1.0-lambda);
117  }
118  return result;
119 }
120 
122 {
124 }
125 
126 void CLogitDVGLikelihood::init()
127 {
128  init_likelihood();
129 }
130 
131 } /* namespace shogun */
132 #endif /* HAVE_EIGEN3 */
int32_t index_t
Definition: common.h:62
static const float64_t INFTY
infinity
Definition: Math.h:2048
Definition: SGMatrix.h:20
parameter struct
#define REQUIRE(x,...)
Definition: SGIO.h:206
index_t vlen
Definition: SGVector.h:494
virtual void set_likelihood(CLikelihoodModel *lik)
double float64_t
Definition: common.h:50
virtual SGVector< float64_t > get_dual_objective_value()
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:922
SGVector< T > clone() const
Definition: SGVector.cpp:209
Class that models dual variational likelihood.
virtual SGVector< float64_t > get_mu_dual_parameter() const
virtual SGVector< float64_t > get_variance_dual_parameter() const
virtual SGVector< float64_t > get_dual_first_derivative(const TParameter *param) const

SHOGUN Machine Learning Toolbox - Documentation