Skip to content

Commit

Permalink
Merge pull request #1366 from karlnapf/develop
Browse files Browse the repository at this point in the history
Some minor changes towards x-validation for GPC
  • Loading branch information
karlnapf committed Aug 5, 2013
2 parents 74d2c7d + d968f7d commit 8935269
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/NEWS
Expand Up @@ -8,6 +8,7 @@
- Added a new class for classical probability distribution that can be
sampled and whose log-pdf can be evaluated. Added the multivariate
Gaussian with various numerical flavours.
- Cross-validation framework works now with Gaussian Processes
- Added nu-SVR for LibSVR class
- Modelselection is now supported for parameters of sub-kernels of
combined kernels in the MKL context. Thanks to Evangelos Anagnostopoulos
Expand Down
1 change: 1 addition & 0 deletions src/shogun/base/SGObject.cpp
Expand Up @@ -1176,6 +1176,7 @@ void CSGObject::get_parameter_incremental_hash(Parameter* param,
for (index_t i=0; i<param->get_num_parameters(); i++)
{
TParameter* p = param->get_parameter(i);
SG_DEBUG("Updating hash for parameter \"%s\"\n", p->m_name ? p->m_name : "(nil)");

if (!p || !p->is_valid())
continue;
Expand Down
Expand Up @@ -107,7 +107,7 @@ SGMatrix<float64_t> CGaussianDistribution::sample(int32_t num_samples,
return samples;
}

SGVector<float64_t> CGaussianDistribution::log_pdf(SGMatrix<float64_t> samples) const
SGVector<float64_t> CGaussianDistribution::log_pdf_multiple(SGMatrix<float64_t> samples) const
{
REQUIRE(samples.num_cols>0, "Number of samples must be positive, but is %d\n",
samples.num_cols);
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/distributions/classical/GaussianDistribution.h
Expand Up @@ -79,7 +79,7 @@ class CGaussianDistribution: public CProbabilityDistribution
* @param samples samples to compute log-pdf of (column vectors)
* @return vector with log-pdfs of given samples
*/
virtual SGVector<float64_t> log_pdf(SGMatrix<float64_t> samples) const;
virtual SGVector<float64_t> log_pdf_multiple(SGMatrix<float64_t> samples) const;

/** @return name of the SGSerializable */
virtual const char* get_name() const
Expand Down
Expand Up @@ -51,7 +51,7 @@ SGVector<float64_t> CProbabilityDistribution::sample() const
return result;
}

SGVector<float64_t> CProbabilityDistribution::log_pdf(
SGVector<float64_t> CProbabilityDistribution::log_pdf_multiple(
SGMatrix<float64_t> samples) const
{
SG_ERROR("Not implemented in sub-class\n");
Expand All @@ -66,7 +66,7 @@ float64_t CProbabilityDistribution::log_pdf(SGVector<float64_t> single_sample) c

SGMatrix<float64_t> s(m_dimension, 1);
memcpy(s.matrix, single_sample.vector, m_dimension*sizeof(float64_t));
return log_pdf(s)[0];
return log_pdf_multiple(s)[0];
}

void CProbabilityDistribution::init()
Expand Down
5 changes: 3 additions & 2 deletions src/shogun/distributions/classical/ProbabilityDistribution.h
Expand Up @@ -57,9 +57,10 @@ class CProbabilityDistribution: public CSGObject
* @param samples samples to compute log-pdf of (column vectors)
* @return vector with log-pdfs of given samples
*/
virtual SGVector<float64_t> log_pdf(SGMatrix<float64_t> samples) const;
virtual SGVector<float64_t> log_pdf_multiple(SGMatrix<float64_t> samples) const;

/** Computes the log-pdf for a single provided sample. Wrapper method.
/** Computes the log-pdf for a single provided sample. Wrapper method which
* calls log_pdf_multiple
*
* @param sample sample to compute log-pdf for
* @return log-pdf of the given sample
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/labels/DenseLabels.cpp
Expand Up @@ -82,7 +82,7 @@ void CDenseLabels::set_labels(SGVector<float64_t> v)
SGVector<float64_t> CDenseLabels::get_labels()
{
if (m_subset_stack->has_subsets())
SG_ERROR("get_labels() is not possible on subset")
return get_labels_copy();

return m_labels;
}
Expand Down
6 changes: 2 additions & 4 deletions src/shogun/labels/DenseLabels.h
Expand Up @@ -113,11 +113,9 @@ class CDenseLabels : public CLabels
*/
int32_t get_int_label(int32_t idx);

/** get labels
/** Getter for labels
*
* not possible with subset
*
* @return labels
* @return labels, a copy if a subset is set
*/
SGVector<float64_t> get_labels();

Expand Down
7 changes: 7 additions & 0 deletions src/shogun/machine/GaussianProcessMachine.h
Expand Up @@ -101,6 +101,13 @@ class CGaussianProcessMachine : public CMachine
m_method->set_labels(lab);
}

/** Stores feature data of underlying model.
* After this method has been called, it is possible to change
* the machine's feature data and call apply(), which is then performed
* on the training feature data that is part of the machine's model.
*/
virtual void store_model_features() { }

private:
void init();

Expand Down
4 changes: 2 additions & 2 deletions src/shogun/machine/gp/InferenceMethod.cpp
Expand Up @@ -114,7 +114,7 @@ float64_t CInferenceMethod::get_log_ml_estimate(
* log pdf of approximation, prior and likelihood */

/* log pdf q(f^i|y) */
SGVector<float64_t> log_pdf_post_approx=post_approx->log_pdf(samples);
SGVector<float64_t> log_pdf_post_approx=post_approx->log_pdf_multiple(samples);

/* dont need gaussian anymore, free memory */
SG_UNREF(post_approx);
Expand All @@ -133,7 +133,7 @@ float64_t CInferenceMethod::get_log_ml_estimate(

CGaussianDistribution* prior=new CGaussianDistribution(
m_mean->get_mean_vector(m_feature_matrix), scaled_kernel);
SGVector<float64_t> log_pdf_prior=prior->log_pdf(samples);
SGVector<float64_t> log_pdf_prior=prior->log_pdf_multiple(samples);
SG_UNREF(prior);
prior=NULL;

Expand Down
Expand Up @@ -45,7 +45,7 @@ TEST(GaussianDistribution,log_pdf_multiple_1d)
SGMatrix<float64_t> x(1,2);
x(0,0)=0;
x(0,1)=1;
SGVector<float64_t> result=(gauss)->log_pdf(x);
SGVector<float64_t> result=(gauss)->log_pdf_multiple(x);

EXPECT_NEAR(result[0], -1.5155121234846454, 1e-15);
EXPECT_NEAR(result[1], -1.2655121234846454, 1e-15);
Expand Down Expand Up @@ -92,7 +92,7 @@ TEST(GaussianDistribution,log_pdf_multiple_2d)
x(1,0)=2;
x(0,1)=3;
x(1,1)=4;
SGVector<float64_t> result=(gauss)->log_pdf(x);
SGVector<float64_t> result=(gauss)->log_pdf_multiple(x);

EXPECT_NEAR(result[0], -2.539698566136597, 1e-15);
EXPECT_NEAR(result[1], -3.620779647217678, 1e-15);
Expand Down

0 comments on commit 8935269

Please sign in to comment.