39 using namespace Eigen;
52 void CGaussianLikelihood::init()
68 SG_SERROR(
"Provided likelihood is not of type CGaussianLikelihood!\n")
86 eigen_result=eigen_result.array()+
CMath::exp(m_log_sigma*2.0);
95 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
97 "Labels must be type of CRegressionLabels\n")
99 "length of the function vector\n")
110 eigen_result=eigen_y-eigen_f;
111 eigen_result=-eigen_result.cwiseProduct(eigen_result)/(2.0*
CMath::exp(m_log_sigma*2.0))-
121 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
123 "Labels must be type of CRegressionLabels\n")
125 "length of the function vector\n")
126 REQUIRE(i>=1 && i<=3,
"Index for derivative should be 1, 2 or 3\n")
137 eigen_result=eigen_y-eigen_f;
143 eigen_result=-VectorXd::Ones(result.
vlen)/
CMath::exp(m_log_sigma*2.0);
145 eigen_result=VectorXd::Zero(result.
vlen);
153 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
155 "Labels must be type of CRegressionLabels\n")
157 "length of the function vector\n")
164 if (strcmp(param->
m_name,
"log_sigma"))
173 eigen_result=eigen_y-eigen_f;
174 eigen_result=eigen_result.cwiseProduct(eigen_result)/
CMath::exp(m_log_sigma*2.0);
175 eigen_result-=VectorXd::Ones(result.
vlen);
183 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
185 "Labels must be type of CRegressionLabels\n")
187 "length of the function vector\n")
189 if (strcmp(param->
m_name,
"log_sigma"))
203 eigen_result=2.0*(eigen_f-eigen_y)/
CMath::exp(m_log_sigma*2.0);
211 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
213 "Labels must be type of CRegressionLabels\n")
215 "length of the function vector\n")
217 if (strcmp(param->
m_name,
"log_sigma"))
228 eigen_result=2.0*VectorXd::Ones(result.
vlen)/
CMath::exp(m_log_sigma*2.0);
241 "Length of the vector of means (%d), length of the vector of "
242 "variances (%d) and number of labels (%d) should be the same\n",
245 "Labels must be type of CRegressionLabels\n")
252 "length of the vector of variances (%d) should be the same\n",
268 eigen_s2=eigen_s2.array()+
CMath::exp(m_log_sigma*2.0);
269 eigen_result=-(eigen_y-eigen_mu).array().square()/(2.0*eigen_s2.array())-
270 (2.0*
CMath::PI*eigen_s2.array()).log()/2.0;
279 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
281 "Length of the vector of means (%d), length of the vector of "
282 "variances (%d) and number of labels (%d) should be the same\n",
284 REQUIRE(i>=0 && i<=mu.
vlen,
"Index (%d) out of bounds!\n", i)
286 "Labels must be type of CRegressionLabels\n")
300 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
302 "Length of the vector of means (%d), length of the vector of "
303 "variances (%d) and number of labels (%d) should be the same\n",
305 REQUIRE(i>=0 && i<=mu.
vlen,
"Index (%d) out of bounds!\n", i)
307 "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