45 using namespace Eigen;
50 #ifndef DOXYGEN_SHOULD_SKIP_THIS
84 void set_sigma(
float64_t sigma) { m_sigma=sigma; }
137 void set_sigma(
float64_t sigma) { m_sigma=sigma; }
178 class CProductFunction :
public CFunction
194 virtual ~CProductFunction()
208 return (*m_f)(x)*(*m_g)(x);
223 CLinearFunction() { }
225 virtual ~CLinearFunction() { }
240 class CQuadraticFunction :
public CFunction
244 CQuadraticFunction() { }
246 virtual ~CQuadraticFunction() { }
275 void CStudentsTLikelihood::init()
293 SG_SERROR(
"Provided likelihood is not of type CStudentsTLikelihood!\n")
315 eigen_result+=
CMath::exp(m_log_sigma*2.0)*df/(df-2.0)*
316 VectorXd::Ones(result.
vlen);
326 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
328 "Labels must be type of CRegressionLabels\n")
330 "length of the function vector\n")
344 VectorXd::Ones(r.
vlen);
347 eigen_r=eigen_y-eigen_f;
348 eigen_r=eigen_r.cwiseProduct(eigen_r)/(df*
CMath::exp(m_log_sigma*2.0));
349 eigen_r=eigen_lZ-(df+1)*
350 (eigen_r+VectorXd::Ones(r.
vlen)).array().log().matrix()/2.0;
359 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
361 "Labels must be type of CRegressionLabels\n")
363 "length of the function vector\n")
364 REQUIRE(i>=1 && i<=3,
"Index for derivative should be 1, 2 or 3\n")
375 eigen_r=eigen_y-eigen_f;
376 VectorXd eigen_r2=eigen_r.cwiseProduct(eigen_r);
380 VectorXd a=eigen_r2+VectorXd::Ones(r.
vlen)*df*
CMath::exp(m_log_sigma*2.0);
386 eigen_r=(df+1)*eigen_r.cwiseQuotient(a);
392 VectorXd b=eigen_r2-VectorXd::Ones(r.
vlen)*df*
CMath::exp(m_log_sigma*2.0);
394 eigen_r=(df+1)*b.cwiseQuotient(a.cwiseProduct(a));
400 VectorXd c=eigen_r2-VectorXd::Ones(r.
vlen)*3*df*
CMath::exp(m_log_sigma*2.0);
401 VectorXd a2=a.cwiseProduct(a);
403 eigen_r=(df+1)*2*eigen_r.cwiseProduct(c).cwiseQuotient(
414 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
416 "Labels must be type of CRegressionLabels\n")
418 "length of the function vector\n")
429 eigen_r=eigen_y-eigen_f;
430 VectorXd eigen_r2=eigen_r.cwiseProduct(eigen_r);
433 if (!strcmp(param->
m_name,
"log_df"))
441 eigen_r-=df*(VectorXd::Ones(r.vlen)+
442 eigen_r2/(df*
CMath::exp(m_log_sigma*2.0))).array().log().matrix()/2.0;
444 eigen_r+=(df/2.0+0.5)*eigen_r2.cwiseQuotient(
445 eigen_r2+VectorXd::Ones(r.vlen)*(df*
CMath::exp(m_log_sigma*2.0)));
447 eigen_r*=(1.0-1.0/df);
451 else if (!strcmp(param->
m_name,
"log_sigma"))
455 eigen_r=(df+1)*eigen_r2.cwiseQuotient(eigen_r2+
456 VectorXd::Ones(r.vlen)*(df*
CMath::exp(m_log_sigma*2.0)));
457 eigen_r-=VectorXd::Ones(r.vlen);
469 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
471 "Labels must be type of CRegressionLabels\n")
473 "length of the function vector\n")
484 eigen_r=eigen_y-eigen_f;
485 VectorXd eigen_r2=eigen_r.cwiseProduct(eigen_r);
489 VectorXd a=eigen_r2+
CMath::exp(m_log_sigma*2.0)*df*VectorXd::Ones(r.vlen);
490 VectorXd a2=a.cwiseProduct(a);
492 if (!strcmp(param->
m_name,
"log_df"))
496 eigen_r=df*eigen_r.cwiseProduct(a-
CMath::exp(m_log_sigma*2.0)*(df+1.0)*
497 VectorXd::Ones(r.vlen)).cwiseQuotient(a2);
498 eigen_r*=(1.0-1.0/df);
502 else if (!strcmp(param->
m_name,
"log_sigma"))
506 eigen_r=-(df+1.0)*2*df*
CMath::exp(m_log_sigma*2.0)*
507 eigen_r.cwiseQuotient(a2);
519 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
521 "Labels must be type of CRegressionLabels\n")
523 "length of the function vector\n")
534 eigen_r=eigen_y-eigen_f;
535 VectorXd eigen_r2=eigen_r.cwiseProduct(eigen_r);
539 VectorXd a=eigen_r2+
CMath::exp(m_log_sigma*2.0)*df*VectorXd::Ones(r.vlen);
540 VectorXd a3=(a.cwiseProduct(a)).cwiseProduct(a);
542 if (!strcmp(param->
m_name,
"log_df"))
548 eigen_r=df*(eigen_r2.cwiseProduct(eigen_r2-3*sigma2*(1.0+df)*
549 VectorXd::Ones(r.vlen))+(df*
CMath::sq(sigma2))*VectorXd::Ones(r.vlen));
550 eigen_r=eigen_r.cwiseQuotient(a3);
552 eigen_r*=(1.0-1.0/df);
556 else if (!strcmp(param->
m_name,
"log_sigma"))
560 eigen_r=(df+1.0)*2*df*
CMath::exp(m_log_sigma*2.0)*
561 (a-4.0*eigen_r2).cwiseQuotient(a3);
577 "Length of the vector of means (%d), length of the vector of "
578 "variances (%d) and number of labels (%d) should be the same\n",
581 "Labels must be type of CRegressionLabels\n")
588 "length of the vector of variances (%d) should be the same\n",
596 CNormalPDF* f=
new CNormalPDF();
599 CStudentsTPDF* g=
new CStudentsTPDF();
605 CProductFunction* h=
new CProductFunction(f, g);
637 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
639 "Length of the vector of means (%d), length of the vector of "
640 "variances (%d) and number of labels (%d) should be the same\n",
642 REQUIRE(i>=0 && i<=mu.
vlen,
"Index (%d) out of bounds!\n", i)
644 "Labels must be type of CRegressionLabels\n")
649 CNormalPDF* f=
new CNormalPDF(mu[i],
CMath::sqrt(s2[i]));
655 CProductFunction* h=
new CProductFunction(f, g);
658 CProductFunction* k=
new CProductFunction(
new CLinearFunction(), h);
679 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
681 "Length of the vector of means (%d), length of the vector of "
682 "variances (%d) and number of labels (%d) should be the same\n",
684 REQUIRE(i>=0 && i<=mu.
vlen,
"Index (%d) out of bounds!\n", i)
686 "Labels must be type of CRegressionLabels\n")
691 CNormalPDF* f=
new CNormalPDF(mu[i],
CMath::sqrt(s2[i]));
697 CProductFunction* h=
new CProductFunction(f, g);
700 CProductFunction* k=
new CProductFunction(
new CLinearFunction(), h);
704 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