Skip to content

Commit

Permalink
Merge pull request #585 from puffin444/master
Browse files Browse the repository at this point in the history
Gaussian Process Regression Framework.
  • Loading branch information
Soeren Sonnenburg committed Jun 20, 2012
2 parents c000355 + 694d9c8 commit 5609bab
Show file tree
Hide file tree
Showing 18 changed files with 1,341 additions and 210 deletions.
29 changes: 28 additions & 1 deletion src/shogun/kernel/GaussianKernel.cpp
Expand Up @@ -121,10 +121,37 @@ void CGaussianKernel::precompute_squared()
precompute_squared_helper(sq_rhs, (CDotFeatures*) rhs);
}

SGMatrix<float64_t> CGaussianKernel::get_parameter_gradient(const char* param_name)
{

if(strcmp(param_name, "width") == 0)
{
SGMatrix<float64_t> derivative = SGMatrix<float64_t>(num_lhs, num_rhs);
for(int j = 0; j < num_lhs; j++)
{
for(int k = 0; k < num_rhs; k++)
{
float64_t element = sq_lhs[j]+sq_rhs[k]-2*CDotKernel::compute(j,k);
derivative(j,k) = exp(-element/width)*element/(width*width);
}
}

return derivative;
}

else
{
SG_ERROR("Gradient calculation not implemented for parameter %s.",
param_name);
SG_ERROR("Returning Empty Matrix\n");
return SGMatrix<float64_t>(0,0);
}
}

void CGaussianKernel::init()
{
set_width(1.0);
set_compact_enabled(false);
set_compact_enabled(false);
sq_lhs=NULL;
sq_rhs=NULL;
SG_ADD(&width, "width", "Kernel width.", MS_AVAILABLE);
Expand Down
8 changes: 8 additions & 0 deletions src/shogun/kernel/GaussianKernel.h
Expand Up @@ -126,6 +126,14 @@ class CGaussianKernel: public CDotKernel
{
return m_compact;
}

/** return derivative with respect to specified parameter
*
* @param name of parameter
* @return gradient with respect to parameter
*/
virtual SGMatrix<float64_t> get_parameter_gradient(const char* param_name);


protected:
/** compute kernel function for features a and b
Expand Down
6 changes: 6 additions & 0 deletions src/shogun/kernel/Kernel.cpp
Expand Up @@ -945,3 +945,9 @@ void CKernel::init()

set_normalizer(new CIdentityKernelNormalizer());
}

SGMatrix<float64_t> CKernel::get_parameter_gradient(const char* param_name)
{
SG_ERROR("Derivative with respect to parameter %s not implemented in kernel (%s).",
param_name, get_name());
}
6 changes: 6 additions & 0 deletions src/shogun/kernel/Kernel.h
Expand Up @@ -759,6 +759,12 @@ class CKernel : public CSGObject
*/
virtual void set_subkernel_weights(SGVector<float64_t> weights);

/** get kernel derivative with respect to parameters
*
* @param name of parameter used to take derivative
* @return kernel gradient with respect to parameter
*/
virtual SGMatrix<float64_t> get_parameter_gradient(const char* param_name);
protected:
/** set property
*
Expand Down

0 comments on commit 5609bab

Please sign in to comment.