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")))
110 Map<VectorXd> eigen_res(res.
vector, res.
vlen);
125 eigen_res+=eigen_lp*m_wgh[cidx];
137 Map<VectorXd> eigen_res(res.
vector, res.
vlen);
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",
177 Map<VectorXd> eigen_res(res.
vector, res.
vlen);
188 if (strcmp(param->
m_name,
"mu")==0)
197 Map<VectorXd> eigen_dlp(dlp.
vector, dlp.
vlen);
198 eigen_res+=eigen_dlp*m_wgh[cidx];
206 VectorXd eigen_sv=eigen_v.array().
sqrt().matrix();
213 Map<VectorXd> eigen_dlp(dlp.
vector, dlp.
vlen);
214 eigen_res+=((m_wgh[cidx]*0.5*m_xgh[cidx])*eigen_dlp.array()/(eigen_sv.array()+EPS)).matrix();
232 "Labels must be type of CBinaryLabels\n");
239 "Labels must be type of CRegressionLabels\n");
242 SG_ERROR(
"Unsupported Label type\n");
261 void CNumericalVGLikelihood::precompute()
269 Map<VectorXd> eigen_t(m_xgh.
vector, m_xgh.
vlen);
271 VectorXd eigen_sv=eigen_v.array().sqrt().matrix();
274 (eigen_t.replicate(1, eigen_v.rows()).array().transpose().colwise()
275 *eigen_sv.array()).colwise()+eigen_f.array()
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.
void sqrt()
square root of vector elements
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 void set_variational_distribution(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab)
virtual bool supports_regression() const
SGVector< float64_t > m_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
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
T * get_column_vector(index_t col) const
virtual SGVector< float64_t > get_variational_first_derivative(const TParameter *param) const
virtual void set_variational_distribution(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab)