Skip to content

Commit

Permalink
Merge remote-tracking branch 'shogun/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
pl8787 committed Mar 11, 2014
2 parents a8d2e32 + 7f9078d commit 33b3f70
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -27,6 +27,7 @@ configure.log
*.oct
.localvimrc
*.DS_Store
cscope.*

*~
\#*\#
Expand Down
21 changes: 21 additions & 0 deletions src/shogun/base/init.cpp
Expand Up @@ -15,6 +15,8 @@
#include <shogun/lib/Map.h>
#include <shogun/base/Parallel.h>
#include <shogun/base/Version.h>
#include <stdlib.h>
#include <string.h>

#ifdef TRACE_MEMORY_ALLOCS
shogun::CMap<void*, shogun::MemoryBlock>* sg_mallocs=NULL;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
4 changes: 4 additions & 0 deletions src/shogun/base/init.h
Expand Up @@ -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);

Expand Down
19 changes: 11 additions & 8 deletions src/shogun/machine/gp/GaussianLikelihood.cpp
Expand Up @@ -91,8 +91,8 @@ SGVector<float64_t> 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;
}
Expand Down Expand Up @@ -150,7 +150,8 @@ SGVector<float64_t> CGaussianLikelihood::get_first_derivative(const CLabels* lab
SGVector<float64_t> y=((CRegressionLabels*)lab)->get_labels();
Map<VectorXd> 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);
Expand Down Expand Up @@ -179,9 +180,10 @@ SGVector<float64_t> CGaussianLikelihood::get_second_derivative(const CLabels* la
SGVector<float64_t> y=((CRegressionLabels*)lab)->get_labels();
Map<VectorXd> 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;
}
Expand All @@ -203,9 +205,10 @@ SGVector<float64_t> CGaussianLikelihood::get_third_derivative(const CLabels* lab
SGVector<float64_t> result(func.vlen);
Map<VectorXd> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/machine/gp/GaussianLikelihood.h
Expand Up @@ -216,7 +216,7 @@ class CGaussianLikelihood: public CLikelihoodModel
virtual float64_t get_first_moment(SGVector<float64_t> mu,
SGVector<float64_t> 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$.
Expand Down

0 comments on commit 33b3f70

Please sign in to comment.