40 using namespace Eigen;
53 void CGaussianLikelihood::init()
69 SG_SERROR(
"Provided likelihood is not of type CGaussianLikelihood!\n")
87 eigen_result=eigen_result.array()+
CMath::exp(m_log_sigma*2.0);
96 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
98 "Labels must be type of CRegressionLabels\n")
100 "length of the function vector\n")
111 eigen_result=eigen_y-eigen_f;
112 eigen_result=-eigen_result.cwiseProduct(eigen_result)/(2.0*
CMath::exp(m_log_sigma*2.0))-
122 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
124 "Labels must be type of CRegressionLabels\n")
126 "length of the function vector\n")
127 REQUIRE(i>=1 && i<=3,
"Index for derivative should be 1, 2 or 3\n")
138 eigen_result=eigen_y-eigen_f;
144 eigen_result=-VectorXd::Ones(result.
vlen)/
CMath::exp(m_log_sigma*2.0);
146 eigen_result=VectorXd::Zero(result.
vlen);
154 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
156 "Labels must be type of CRegressionLabels\n")
158 "length of the function vector\n")
165 if (strcmp(param->
m_name,
"log_sigma"))
174 eigen_result=eigen_y-eigen_f;
175 eigen_result=eigen_result.cwiseProduct(eigen_result)/
CMath::exp(m_log_sigma*2.0);
176 eigen_result-=VectorXd::Ones(result.
vlen);
184 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
186 "Labels must be type of CRegressionLabels\n")
188 "length of the function vector\n")
190 if (strcmp(param->
m_name,
"log_sigma"))
204 eigen_result=2.0*(eigen_f-eigen_y)/
CMath::exp(m_log_sigma*2.0);
212 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
214 "Labels must be type of CRegressionLabels\n")
216 "length of the function vector\n")
218 if (strcmp(param->
m_name,
"log_sigma"))
229 eigen_result=2.0*VectorXd::Ones(result.
vlen)/
CMath::exp(m_log_sigma*2.0);
242 "Length of the vector of means (%d), length of the vector of "
243 "variances (%d) and number of labels (%d) should be the same\n",
246 "Labels must be type of CRegressionLabels\n")
253 "length of the vector of variances (%d) should be the same\n",
269 eigen_s2=eigen_s2.array()+
CMath::exp(m_log_sigma*2.0);
270 eigen_result=-(eigen_y-eigen_mu).array().square()/(2.0*eigen_s2.array())-
271 (2.0*
CMath::PI*eigen_s2.array()).log()/2.0;
280 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
282 "Length of the vector of means (%d), length of the vector of "
283 "variances (%d) and number of labels (%d) should be the same\n",
285 REQUIRE(i>=0 && i<=mu.
vlen,
"Index (%d) out of bounds!\n", i)
287 "Labels must be type of CRegressionLabels\n")
301 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
303 "Length of the vector of means (%d), length of the vector of "
304 "variances (%d) and number of labels (%d) should be the same\n",
306 REQUIRE(i>=0 && i<=mu.
vlen,
"Index (%d) out of bounds!\n", i)
308 "Labels must be type of CRegressionLabels\n")
virtual ELabelType get_label_type() const =0
Class that models Gaussian likelihood.
Real Labels are real-valued labels.
virtual SGVector< float64_t > get_log_probability_f(const CLabels *lab, SGVector< float64_t > func) const
The class Labels models labels, i.e. class assignments of objects.
virtual int32_t get_num_labels() const =0
real valued labels (e.g. for regression, classifier outputs)
virtual ELikelihoodModelType get_model_type() const
void set_sigma(float64_t sigma)
virtual float64_t get_second_moment(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab, index_t i) const
virtual ~CGaussianLikelihood()
virtual SGVector< float64_t > get_first_derivative(const CLabels *lab, SGVector< float64_t > func, const TParameter *param) const
virtual SGVector< float64_t > get_predictive_variances(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab=NULL) const
virtual SGVector< float64_t > get_predictive_means(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab=NULL) const
virtual float64_t get_first_moment(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab, index_t i) const
static CGaussianLikelihood * obtain_from_generic(CLikelihoodModel *lik)
virtual SGVector< float64_t > get_second_derivative(const CLabels *lab, SGVector< float64_t > func, const TParameter *param) const
virtual SGVector< float64_t > get_log_zeroth_moments(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab) const
all of classes and functions are contained in the shogun namespace
static float64_t exp(float64_t x)
virtual SGVector< float64_t > get_log_probability_derivative_f(const CLabels *lab, SGVector< float64_t > func, index_t i) const
virtual SGVector< float64_t > get_third_derivative(const CLabels *lab, SGVector< float64_t > func, const TParameter *param) const
The Likelihood model base class.
void set_const(T const_elem)
static const float64_t PI