50 using namespace Eigen;
55 CNumericalVGLikelihood::CNumericalVGLikelihood()
65 void CNumericalVGLikelihood::init()
67 SG_ADD(&m_log_lam,
"log_lam",
68 "The result of used for computing variational expection\n",
72 "Gaussian-Hermite quadrature base points (abscissas)\n",
76 "Gaussian-Hermite quadrature weight factors\n",
80 "The number of Gaussian-Hermite quadrature point\n",
83 SG_ADD(&m_is_init_GHQ,
"is_init_GHQ",
84 "Whether Gaussian-Hermite quadrature points are initialized or not\n",
93 REQUIRE(n>0,
"The number (%d) of Gaussian Hermite point should be positive\n",n);
104 REQUIRE(param,
"Param is required (param should not be NULL)\n");
105 REQUIRE(param->
m_name,
"Param name is required (param->m_name should not be NULL)\n");
106 if (!(strcmp(param->
m_name,
"mu") && strcmp(param->
m_name,
"sigma2")))
126 eigen_res+=eigen_lp*m_wgh[cidx];
153 eigen_res+=eigen_lp*m_wgh[cidx];
167 REQUIRE(param,
"Param is required (param should not be NULL)\n");
168 REQUIRE(param->
m_name,
"Param name is required (param->m_name should not be NULL)\n");
171 "Can't compute derivative of the variational expection ",
172 "of log LogitLikelihood using numerical integration ",
173 "wrt %s.%s parameter. The function only accepts mu and sigma2 as parameter\n",
189 if (strcmp(param->
m_name,
"mu")==0)
199 eigen_res+=eigen_dlp*m_wgh[cidx];
207 VectorXd eigen_sv=eigen_v.array().sqrt().matrix();
215 eigen_res+=((m_wgh[cidx]*0.5*m_xgh[cidx])*eigen_dlp.array()/(eigen_sv.array()+EPS)).matrix();
236 "Labels must be type of CBinaryLabels\n");
243 "Labels must be type of CRegressionLabels\n");
246 SG_ERROR(
"Unsupported Label type\n");
269 void CNumericalVGLikelihood::precompute()
279 VectorXd eigen_sv=eigen_v.array().sqrt().matrix();
282 (eigen_t.replicate(1, eigen_v.rows()).array().transpose().colwise()
283 *eigen_sv.array()).colwise()+eigen_f.array()
virtual bool set_variational_distribution(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab)
virtual ~CNumericalVGLikelihood()
virtual ELabelType get_label_type() const =0
virtual const char * get_name() const
Real Labels are real-valued labels.
The class Labels models labels, i.e. class assignments of objects.
real valued labels (e.g. for regression, classifier outputs)
The variational Gaussian Likelihood base class. The variational distribution is Gaussian.
static void generate_gauher(SGVector< float64_t > xgh, SGVector< float64_t > wgh)
virtual SGVector< float64_t > get_first_derivative(const CLabels *lab, SGVector< float64_t > func, const TParameter *param) const
virtual bool supports_regression() const
SGVector< float64_t > m_lab
virtual bool set_variational_distribution(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab)
virtual void set_GHQ_number(index_t n)
virtual SGVector< float64_t > get_variational_expection()
virtual SGVector< float64_t > get_log_probability_f(const CLabels *lab, SGVector< float64_t > func) const
virtual SGVector< float64_t > get_log_probability_derivative_f(const CLabels *lab, SGVector< float64_t > func, index_t i) const
T * get_column_vector(index_t col) const
all of classes and functions are contained in the shogun namespace
virtual bool supports_binary() const
Binary Labels for binary classification.
SGVector< float64_t > m_mu
virtual SGVector< float64_t > get_first_derivative_wrt_hyperparameter(const TParameter *param) const
SGVector< float64_t > m_s2
virtual SGVector< float64_t > get_variational_first_derivative(const TParameter *param) const