46 using namespace Eigen;
51 #ifndef DOXYGEN_SHOULD_SKIP_THIS
85 void set_sigma(
float64_t sigma) { m_sigma=sigma; }
138 void set_sigma(
float64_t sigma) { m_sigma=sigma; }
179 class CProductFunction :
public CFunction
195 virtual ~CProductFunction()
209 return (*m_f)(x)*(*m_g)(x);
224 CLinearFunction() { }
226 virtual ~CLinearFunction() { }
241 class CQuadraticFunction :
public CFunction
245 CQuadraticFunction() { }
247 virtual ~CQuadraticFunction() { }
276 void CStudentsTLikelihood::init()
294 SG_SERROR(
"Provided likelihood is not of type CStudentsTLikelihood!\n")
316 eigen_result+=
CMath::exp(m_log_sigma*2.0)*df/(df-2.0)*
317 VectorXd::Ones(result.
vlen);
327 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
329 "Labels must be type of CRegressionLabels\n")
331 "length of the function vector\n")
345 VectorXd::Ones(r.
vlen);
348 eigen_r=eigen_y-eigen_f;
349 eigen_r=eigen_r.cwiseProduct(eigen_r)/(df*
CMath::exp(m_log_sigma*2.0));
350 eigen_r=eigen_lZ-(df+1)*
351 (eigen_r+VectorXd::Ones(r.
vlen)).array().log().matrix()/2.0;
360 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
362 "Labels must be type of CRegressionLabels\n")
364 "length of the function vector\n")
365 REQUIRE(i>=1 && i<=3,
"Index for derivative should be 1, 2 or 3\n")
376 eigen_r=eigen_y-eigen_f;
377 VectorXd eigen_r2=eigen_r.cwiseProduct(eigen_r);
381 VectorXd a=eigen_r2+VectorXd::Ones(r.
vlen)*df*
CMath::exp(m_log_sigma*2.0);
387 eigen_r=(df+1)*eigen_r.cwiseQuotient(a);
393 VectorXd b=eigen_r2-VectorXd::Ones(r.
vlen)*df*
CMath::exp(m_log_sigma*2.0);
395 eigen_r=(df+1)*b.cwiseQuotient(a.cwiseProduct(a));
401 VectorXd c=eigen_r2-VectorXd::Ones(r.
vlen)*3*df*
CMath::exp(m_log_sigma*2.0);
402 VectorXd a2=a.cwiseProduct(a);
404 eigen_r=(df+1)*2*eigen_r.cwiseProduct(c).cwiseQuotient(
415 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
417 "Labels must be type of CRegressionLabels\n")
419 "length of the function vector\n")
430 eigen_r=eigen_y-eigen_f;
431 VectorXd eigen_r2=eigen_r.cwiseProduct(eigen_r);
434 if (!strcmp(param->
m_name,
"log_df"))
442 eigen_r-=df*(VectorXd::Ones(r.vlen)+
443 eigen_r2/(df*
CMath::exp(m_log_sigma*2.0))).array().log().matrix()/2.0;
445 eigen_r+=(df/2.0+0.5)*eigen_r2.cwiseQuotient(
446 eigen_r2+VectorXd::Ones(r.vlen)*(df*
CMath::exp(m_log_sigma*2.0)));
448 eigen_r*=(1.0-1.0/df);
452 else if (!strcmp(param->
m_name,
"log_sigma"))
456 eigen_r=(df+1)*eigen_r2.cwiseQuotient(eigen_r2+
457 VectorXd::Ones(r.vlen)*(df*
CMath::exp(m_log_sigma*2.0)));
458 eigen_r-=VectorXd::Ones(r.vlen);
470 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
472 "Labels must be type of CRegressionLabels\n")
474 "length of the function vector\n")
485 eigen_r=eigen_y-eigen_f;
486 VectorXd eigen_r2=eigen_r.cwiseProduct(eigen_r);
490 VectorXd a=eigen_r2+
CMath::exp(m_log_sigma*2.0)*df*VectorXd::Ones(r.vlen);
491 VectorXd a2=a.cwiseProduct(a);
493 if (!strcmp(param->
m_name,
"log_df"))
497 eigen_r=df*eigen_r.cwiseProduct(a-
CMath::exp(m_log_sigma*2.0)*(df+1.0)*
498 VectorXd::Ones(r.vlen)).cwiseQuotient(a2);
499 eigen_r*=(1.0-1.0/df);
503 else if (!strcmp(param->
m_name,
"log_sigma"))
507 eigen_r=-(df+1.0)*2*df*
CMath::exp(m_log_sigma*2.0)*
508 eigen_r.cwiseQuotient(a2);
520 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
522 "Labels must be type of CRegressionLabels\n")
524 "length of the function vector\n")
535 eigen_r=eigen_y-eigen_f;
536 VectorXd eigen_r2=eigen_r.cwiseProduct(eigen_r);
540 VectorXd a=eigen_r2+
CMath::exp(m_log_sigma*2.0)*df*VectorXd::Ones(r.vlen);
541 VectorXd a3=(a.cwiseProduct(a)).cwiseProduct(a);
543 if (!strcmp(param->
m_name,
"log_df"))
549 eigen_r=df*(eigen_r2.cwiseProduct(eigen_r2-3*sigma2*(1.0+df)*
550 VectorXd::Ones(r.vlen))+(df*
CMath::sq(sigma2))*VectorXd::Ones(r.vlen));
551 eigen_r=eigen_r.cwiseQuotient(a3);
553 eigen_r*=(1.0-1.0/df);
557 else if (!strcmp(param->
m_name,
"log_sigma"))
561 eigen_r=(df+1.0)*2*df*
CMath::exp(m_log_sigma*2.0)*
562 (a-4.0*eigen_r2).cwiseQuotient(a3);
578 "Length of the vector of means (%d), length of the vector of "
579 "variances (%d) and number of labels (%d) should be the same\n",
582 "Labels must be type of CRegressionLabels\n")
589 "length of the vector of variances (%d) should be the same\n",
597 CNormalPDF* f=
new CNormalPDF();
600 CStudentsTPDF* g=
new CStudentsTPDF();
606 CProductFunction* h=
new CProductFunction(f, g);
638 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
640 "Length of the vector of means (%d), length of the vector of "
641 "variances (%d) and number of labels (%d) should be the same\n",
643 REQUIRE(i>=0 && i<=mu.
vlen,
"Index (%d) out of bounds!\n", i)
645 "Labels must be type of CRegressionLabels\n")
650 CNormalPDF* f=
new CNormalPDF(mu[i],
CMath::sqrt(s2[i]));
656 CProductFunction* h=
new CProductFunction(f, g);
659 CProductFunction* k=
new CProductFunction(
new CLinearFunction(), h);
680 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
682 "Length of the vector of means (%d), length of the vector of "
683 "variances (%d) and number of labels (%d) should be the same\n",
685 REQUIRE(i>=0 && i<=mu.
vlen,
"Index (%d) out of bounds!\n", i)
687 "Labels must be type of CRegressionLabels\n")
692 CNormalPDF* f=
new CNormalPDF(mu[i],
CMath::sqrt(s2[i]));
698 CProductFunction* h=
new CProductFunction(f, g);
701 CProductFunction* k=
new CProductFunction(
new CLinearFunction(), h);
705 CProductFunction* p=
new CProductFunction(
new CQuadraticFunction(), h);
virtual SGVector< float64_t > get_predictive_variances(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab=NULL) const
virtual ELabelType get_label_type() const =0
Real Labels are real-valued labels.
virtual float64_t get_second_moment(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab, index_t i) const
static float64_t lgamma(float64_t x)
static float64_t integrate_quadgk(CFunction *f, float64_t a, float64_t b, float64_t abs_tol=1e-10, float64_t rel_tol=1e-5, uint32_t max_iter=1000, index_t sn=10)
The class Labels models labels, i.e. class assignments of objects.
static const float64_t INFTY
infinity
virtual SGVector< float64_t > get_second_derivative(const CLabels *lab, SGVector< float64_t > func, const TParameter *param) const
virtual int32_t get_num_labels() const =0
real valued labels (e.g. for regression, classifier outputs)
virtual SGVector< float64_t > get_first_derivative(const CLabels *lab, SGVector< float64_t > func, const TParameter *param) const
virtual ELikelihoodModelType get_model_type() const
virtual SGVector< float64_t > get_predictive_means(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab=NULL) const
virtual SGVector< float64_t > get_log_probability_f(const CLabels *lab, SGVector< float64_t > func) const
float64_t get_degrees_freedom() const
virtual float64_t get_first_moment(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab, index_t i) const
virtual SGVector< float64_t > get_log_probability_derivative_f(const CLabels *lab, SGVector< float64_t > func, index_t i) const
Class of a function of one variable.
virtual ~CStudentsTLikelihood()
void set_sigma(float64_t sigma)
Class that models a Student's-t likelihood.
all of classes and functions are contained in the shogun namespace
static float64_t dlgamma(float64_t x)
void set_degrees_freedom(float64_t df)
static float64_t exp(float64_t x)
static float64_t log(float64_t v)
static CStudentsTLikelihood * obtain_from_generic(CLikelihoodModel *likelihood)
static float32_t sqrt(float32_t x)
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)
virtual SGVector< float64_t > get_log_zeroth_moments(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab) const
static const float64_t PI