diff --git a/.gitignore b/.gitignore index cf5438fe697..8402d16e054 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ configure.log *.oct .localvimrc *.DS_Store +cscope.* *~ \#*\# diff --git a/src/shogun/base/init.cpp b/src/shogun/base/init.cpp index 33c3ac86416..e3281ca9927 100644 --- a/src/shogun/base/init.cpp +++ b/src/shogun/base/init.cpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include #ifdef TRACE_MEMORY_ALLOCS shogun::CMap* sg_mallocs=NULL; @@ -72,6 +74,8 @@ namespace shogun sg_print_warning=print_warning; sg_print_error=print_error; sg_cancel_computations=cancel_computations; + + init_from_env(); } void sg_global_print_default(FILE* target, const char* str) @@ -170,4 +174,21 @@ namespace shogun SG_REF(sg_rand); return sg_rand; } + + void init_from_env() + { + char* env_log_val = NULL; + SGIO* io = get_global_io(); + env_log_val = getenv("SHOGUN_LOG_LEVEL"); + if (env_log_val) + { + if(strncmp(env_log_val, "DEBUG", 5) == 0) + io->set_loglevel(MSG_DEBUG); + else if(strncmp(env_log_val, "WARN", 4) == 0) + io->set_loglevel(MSG_WARN); + else if(strncmp(env_log_val, "ERROR", 5) == 0) + io->set_loglevel(MSG_ERROR); + } + SG_UNREF(io); + } } diff --git a/src/shogun/base/init.h b/src/shogun/base/init.h index 2056ab3ee13..3e1a0f3bd29 100644 --- a/src/shogun/base/init.h +++ b/src/shogun/base/init.h @@ -106,6 +106,10 @@ void set_global_rand(CRandom* rand); */ CRandom* get_global_rand(); +/** Checks environment variables and modifies global objects + */ +void init_from_env(); + /// function called to print normal messages extern void (*sg_print_message)(FILE* target, const char* str); diff --git a/src/shogun/machine/gp/GaussianLikelihood.cpp b/src/shogun/machine/gp/GaussianLikelihood.cpp index d364f61dbd2..42d451b8422 100644 --- a/src/shogun/machine/gp/GaussianLikelihood.cpp +++ b/src/shogun/machine/gp/GaussianLikelihood.cpp @@ -91,8 +91,8 @@ SGVector CGaussianLikelihood::get_log_probability_f(const CLabels* la // compute log probability: lp=-(y-f).^2./sigma^2/2-log(2*pi*sigma^2)/2 eigen_result=eigen_y-eigen_f; - eigen_result=-eigen_result.cwiseProduct(eigen_result)/(2*CMath::sq(m_sigma))- - VectorXd::Ones(result.vlen)*log(2*CMath::PI*CMath::sq(m_sigma))/2.0; + eigen_result=-eigen_result.cwiseProduct(eigen_result)/(2.0*CMath::sq(m_sigma))- + VectorXd::Ones(result.vlen)*log(2.0*CMath::PI*CMath::sq(m_sigma))/2.0; return result; } @@ -150,7 +150,8 @@ SGVector CGaussianLikelihood::get_first_derivative(const CLabels* lab SGVector y=((CRegressionLabels*)lab)->get_labels(); Map eigen_y(y.vector, y.vlen); - // compute derivative of log probability wrt sigma: + // compute derivative of log probability wrt log_sigma: + // dlp_dlogsigma // lp_dsigma=(y-f).^2/sigma^2-1 eigen_result=eigen_y-eigen_f; eigen_result=eigen_result.cwiseProduct(eigen_result)/CMath::sq(m_sigma); @@ -179,9 +180,10 @@ SGVector CGaussianLikelihood::get_second_derivative(const CLabels* la SGVector y=((CRegressionLabels*)lab)->get_labels(); Map eigen_y(y.vector, y.vlen); - // compute derivative of the first derivative of log probability wrt sigma: + // compute derivative of (the first log_sigma derivative of log probability) wrt f: + // d2lp_dlogsigma_df == d2lp_df_dlogsigma // dlp_dsigma=2*(f-y)/sigma^2 - eigen_result=2*(eigen_f-eigen_y)/CMath::sq(m_sigma); + eigen_result=2.0*(eigen_f-eigen_y)/CMath::sq(m_sigma); return result; } @@ -203,9 +205,10 @@ SGVector CGaussianLikelihood::get_third_derivative(const CLabels* lab SGVector result(func.vlen); Map eigen_result(result.vector, result.vlen); - // compute derivative of the second derivative of log probability wrt sigma: - // d2lp_dsigma=1/sigma^2 - eigen_result=2*VectorXd::Ones(result.vlen)/CMath::sq(m_sigma); + // compute derivative of (the derivative of the first log_sigma derivative of log probability) wrt f: + // d3lp_dlogsigma_df_df == d3lp_df_df_dlogsigma + // d2lp_dsigma=2/sigma^2 + eigen_result=2.0*VectorXd::Ones(result.vlen)/CMath::sq(m_sigma); return result; } diff --git a/src/shogun/machine/gp/GaussianLikelihood.h b/src/shogun/machine/gp/GaussianLikelihood.h index a1b66dd92ae..c5970fde45e 100644 --- a/src/shogun/machine/gp/GaussianLikelihood.h +++ b/src/shogun/machine/gp/GaussianLikelihood.h @@ -216,7 +216,7 @@ class CGaussianLikelihood: public CLikelihoodModel virtual float64_t get_first_moment(SGVector mu, SGVector s2, const CLabels* lab, index_t i) const; - /** returns the second moment of a given (unnormalized) probability + /** returns the second central moment of a given (unnormalized) probability * distribution \f$q(f_i) = Z_i^-1 * p(y_i|f_i)\mathcal{N}(f_i|\mu,\sigma^2)\f$, where \f$ Z_i=\int * p(y_i|f_i)\mathcal{N}(f_i|\mu,\sigma^2) df_i\f$.