49 using namespace Eigen;
54 CNumericalVGLikelihood::CNumericalVGLikelihood()
64 void CNumericalVGLikelihood::init()
66 SG_ADD(&m_log_lam,
"log_lam",
67 "The result of used for computing variational expection\n",
71 "Gaussian-Hermite quadrature base points (abscissas)\n",
75 "Gaussian-Hermite quadrature weight factors\n",
79 "The number of Gaussian-Hermite quadrature point\n",
82 SG_ADD(&m_is_init_GHQ,
"is_init_GHQ",
83 "Whether Gaussian-Hermite quadrature points are initialized or not\n",
92 REQUIRE(n>0,
"The number (%d) of Gaussian Hermite point should be positive\n",n);
103 REQUIRE(param,
"Param is required (param should not be NULL)\n");
104 REQUIRE(param->
m_name,
"Param name is required (param->m_name should not be NULL)\n");
105 if (!(strcmp(param->
m_name,
"mu") && strcmp(param->
m_name,
"sigma2")))
125 eigen_res+=eigen_lp*m_wgh[cidx];
152 eigen_res+=eigen_lp*m_wgh[cidx];
166 REQUIRE(param,
"Param is required (param should not be NULL)\n");
167 REQUIRE(param->
m_name,
"Param name is required (param->m_name should not be NULL)\n");
170 "Can't compute derivative of the variational expection ",
171 "of log LogitLikelihood using numerical integration ",
172 "wrt %s.%s parameter. The function only accepts mu and sigma2 as parameter\n",
188 if (strcmp(param->
m_name,
"mu")==0)
198 eigen_res+=eigen_dlp*m_wgh[cidx];
206 VectorXd eigen_sv=eigen_v.array().sqrt().matrix();
214 eigen_res+=((m_wgh[cidx]*0.5*m_xgh[cidx])*eigen_dlp.array()/(eigen_sv.array()+EPS)).matrix();
235 "Labels must be type of CBinaryLabels\n");
242 "Labels must be type of CRegressionLabels\n");
245 SG_ERROR(
"Unsupported Label type\n");
268 void CNumericalVGLikelihood::precompute()
278 VectorXd eigen_sv=eigen_v.array().sqrt().matrix();
281 (eigen_t.replicate(1, eigen_v.rows()).array().transpose().colwise()
282 *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