Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

PLearn::ReconstructionWeightsKernel Class Reference

#include <ReconstructionWeightsKernel.h>

Inheritance diagram for PLearn::ReconstructionWeightsKernel:

Inheritance graph
[legend]
Collaboration diagram for PLearn::ReconstructionWeightsKernel:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ReconstructionWeightsKernel ()
 Default constructor.

virtual void build ()
 Simply calls inherited::build() then build_().

virtual void makeDeepCopyFromShallowCopy (map< const void *, void * > &copies)
 Transforms a shallow copy into a deep copy.

 PLEARN_DECLARE_OBJECT (ReconstructionWeightsKernel)
virtual real evaluate (const Vec &x1, const Vec &x2) const
 Compute K(x1,x2).

virtual real evaluate_i_j (int i, int j) const
 returns evaluate(data(i),data(j))

virtual real evaluate_i_x (int i, const Vec &x, real squared_norm_of_x=-1) const
virtual real evaluate_x_i (const Vec &x, int i, real squared_norm_of_x=-1) const
 returns evaluate(x,data(i)) [default version calls evaluate_i_x if kernel is_symmetric]

virtual real evaluate_x_i_again (const Vec &x, int i, real squared_norm_of_x=-1, bool first_time=false) const
virtual void setDataForKernelMatrix (VMat the_data)
 ** Subclasses may overload these methods to provide efficient kernel matrix access **

virtual real evaluate_sum_k_i_k_j (int i, int j) const
 Return sum_k K(x_k, x_i) * K(x_k, x_j).

virtual void computeLLEMatrix (const Mat &lle_mat) const
 Fill 'lle_mat', which must be of size (n x n), with entries (i,j) equal to W_{ij} + W_{ji} - W_{ki} W_{kj} (this is used in LLE to compute the kernel Gram matrix).


Public Attributes

Ker distance_kernel
Ker dot_product_kernel
int ignore_nearest
int knn
real regularizer

Protected Member Functions

void computeWeights ()
 Precompute the weights W_{ij}.

void reconstruct (const Vec &x, const TVec< int > &neighbors, Vec &w) const
 Compute the reconstruction weights for a vector, given its nearest neighbors.


Static Protected Member Functions

void declareOptions (OptionList &ol)
 Declares this class' options.


Protected Attributes

Ker dist_ker
 The kernel used to compute distances (equal to 'distance_kernel' if specified, and otherwise the usual Euclidean distance).

Ker dp_ker
 The kernel used to compute dot products (equal to 'dot_product_kernel' if specified, and otherwise the usual DotProductKernel).

TMat< intneighbors
 The indices of the neighbors of each data point.

TVec< TMat< int > > is_neighbor_of
 The element i is a matrix whose first column is the list of the points which have i among their neighbors, and the second column is the index of i in these neighbors.

PP< SelectRowsVMatrixsub_data
 Points toward a subset of the training data (typically, a neighborhood).

Mat weights
 The matrix with the weights W_{ij}.


Private Types

typedef Kernel inherited

Private Member Functions

void build_ ()
 This does the actual building.


Private Attributes

bool build_in_progress
 True iff build() has been called but build_() has not been called yet.

bool new_data
 True iff the 'setDataForKernelMatrix' method has been called since last time we called 'reconstruct'.

Mat k_xi_x_sorted
 Used in 'evaluate_x_i_again' to store the distances from x to its nearest neighbors.

TVec< intneighbors_of_x
 Used in 'evaluate_x_i_again' to store the neighbors of x.

Vec weights_x
 Used in 'evaluate_x_i_again' to store the reconstruction weights of x.

Mat local_gram
 Used in 'reconstruct' to store the local Gram matrix.

PP< ShiftAndRescaleVMatrixcentered_neighborhood
 Used in 'reconstruct' to point toward the locally centered data.

Vec ones
 Used in 'reconstruct' to store a vector filled with 1.


Member Typedef Documentation

typedef Kernel PLearn::ReconstructionWeightsKernel::inherited [private]
 

Reimplemented from PLearn::Kernel.

Definition at line 59 of file ReconstructionWeightsKernel.h.


Constructor & Destructor Documentation

PLearn::ReconstructionWeightsKernel::ReconstructionWeightsKernel  ) 
 

Default constructor.

Definition at line 55 of file ReconstructionWeightsKernel.cc.

References sub_data.


Member Function Documentation

void PLearn::ReconstructionWeightsKernel::build  )  [virtual]
 

Simply calls inherited::build() then build_().

Reimplemented from PLearn::Kernel.

Definition at line 112 of file ReconstructionWeightsKernel.cc.

References build_(), and build_in_progress.

void PLearn::ReconstructionWeightsKernel::build_  )  [private]
 

This does the actual building.

Reimplemented from PLearn::Kernel.

Definition at line 122 of file ReconstructionWeightsKernel.cc.

References build_in_progress, dist_ker, distance_kernel, dot_product_kernel, dp_ker, ignore_nearest, knn, PLERROR, and setDataForKernelMatrix().

Referenced by build().

void PLearn::ReconstructionWeightsKernel::computeLLEMatrix const Mat lle_mat  )  const [virtual]
 

Fill 'lle_mat', which must be of size (n x n), with entries (i,j) equal to W_{ij} + W_{ji} - W_{ki} W_{kj} (this is used in LLE to compute the kernel Gram matrix).

Definition at line 151 of file ReconstructionWeightsKernel.cc.

References PLearn::TMat< T >::clear(), k, knn, PLearn::TMat< T >::length(), PLearn::Mat, neighbors, PLERROR, PLearn::ProgressBar::update(), weights, and PLearn::TMat< T >::width().

void PLearn::ReconstructionWeightsKernel::computeWeights  )  [protected]
 

Precompute the weights W_{ij}.

Definition at line 181 of file ReconstructionWeightsKernel.cc.

References dist_ker, PLearn::VMat::getSubRow(), ignore_nearest, is_neighbor_of, knn, PLearn::Mat, neighbors, PLERROR, reconstruct(), PLearn::TVec< TMat< int > >::resize(), PLearn::TMat< T >::resize(), PLearn::TVec< T >::resize(), PLearn::sortRows(), PLearn::ProgressBar::update(), PLearn::Vec, and weights.

Referenced by setDataForKernelMatrix().

void PLearn::ReconstructionWeightsKernel::declareOptions OptionList ol  )  [static, protected]
 

Declares this class' options.

Reimplemented from PLearn::Kernel.

Definition at line 83 of file ReconstructionWeightsKernel.cc.

References PLearn::declareOption(), and PLearn::OptionList.

real PLearn::ReconstructionWeightsKernel::evaluate const Vec x1,
const Vec x2
const [virtual]
 

Compute K(x1,x2).

Implements PLearn::Kernel.

Definition at line 229 of file ReconstructionWeightsKernel.cc.

References evaluate_x_i().

real PLearn::ReconstructionWeightsKernel::evaluate_i_j int  i,
int  j
const [virtual]
 

returns evaluate(data(i),data(j))

Reimplemented from PLearn::Kernel.

Definition at line 243 of file ReconstructionWeightsKernel.cc.

References ignore_nearest, k, knn, neighbors, PLERROR, weights, and PLearn::TMat< T >::width().

Referenced by evaluate_i_x().

real PLearn::ReconstructionWeightsKernel::evaluate_i_x int  i,
const Vec x,
real  squared_norm_of_x = -1
const [virtual]
 

returns evaluate(data(i),x) [squared_norm_of_x is just a hint that may allow to speed up computation if it is already known, but it's optional]

Reimplemented from PLearn::Kernel.

Definition at line 270 of file ReconstructionWeightsKernel.cc.

References evaluate_i_j(), and x.

real PLearn::ReconstructionWeightsKernel::evaluate_sum_k_i_k_j int  i,
int  j
const [virtual]
 

Return sum_k K(x_k, x_i) * K(x_k, x_j).

Definition at line 281 of file ReconstructionWeightsKernel.cc.

References ignore_nearest, is_neighbor_of, knn, PLearn::TMat< T >::length(), PLERROR, PLearn::sum(), weights, and PLearn::TMat< T >::width().

real PLearn::ReconstructionWeightsKernel::evaluate_x_i const Vec x,
int  i,
real  squared_norm_of_x = -1
const [virtual]
 

returns evaluate(x,data(i)) [default version calls evaluate_i_x if kernel is_symmetric]

Reimplemented from PLearn::Kernel.

Definition at line 319 of file ReconstructionWeightsKernel.cc.

References evaluate_x_i_again(), and x.

Referenced by evaluate().

real PLearn::ReconstructionWeightsKernel::evaluate_x_i_again const Vec x,
int  i,
real  squared_norm_of_x = -1,
bool  first_time = false
const [virtual]
 

Reimplemented from PLearn::Kernel.

Definition at line 326 of file ReconstructionWeightsKernel.cc.

References dist_ker, PLearn::TVec< int >::find(), ignore_nearest, k_xi_x_sorted, knn, neighbors_of_x, reconstruct(), PLearn::TVec< int >::resize(), PLearn::TMat< T >::subMat(), weights_x, and x.

Referenced by evaluate_x_i().

void PLearn::ReconstructionWeightsKernel::makeDeepCopyFromShallowCopy map< const void *, void * > &  copies  )  [virtual]
 

Transforms a shallow copy into a deep copy.

Definition at line 345 of file ReconstructionWeightsKernel.cc.

References PLERROR.

PLearn::ReconstructionWeightsKernel::PLEARN_DECLARE_OBJECT ReconstructionWeightsKernel   ) 
 

void PLearn::ReconstructionWeightsKernel::reconstruct const Vec x,
const TVec< int > &  neighbors,
Vec w
const [protected]
 

Compute the reconstruction weights for a vector, given its nearest neighbors.

Definition at line 362 of file ReconstructionWeightsKernel.cc.

References centered_neighborhood, dp_ker, PLearn::TVec< T >::fill(), PLearn::TVec< T >::length(), local_gram, new_data, ones, PLearn::regularizeMatrix(), regularizer, PLearn::TMat< T >::resize(), PLearn::TVec< T >::resize(), PLearn::solveLinearSystem(), sub_data, PLearn::sum(), weights_x, and x.

Referenced by computeWeights(), and evaluate_x_i_again().

void PLearn::ReconstructionWeightsKernel::setDataForKernelMatrix VMat  the_data  )  [virtual]
 

** Subclasses may overload these methods to provide efficient kernel matrix access **

This method sets the data VMat that will be used to define the kernel matrix. It may precompute values from this that may later accelerate the evaluation of a kernel matrix element

Reimplemented from PLearn::Kernel.

Definition at line 405 of file ReconstructionWeightsKernel.cc.

References build_in_progress, computeWeights(), dist_ker, new_data, and sub_data.

Referenced by build_().


Member Data Documentation

bool PLearn::ReconstructionWeightsKernel::build_in_progress [private]
 

True iff build() has been called but build_() has not been called yet.

Definition at line 62 of file ReconstructionWeightsKernel.h.

Referenced by build(), build_(), and setDataForKernelMatrix().

PP<ShiftAndRescaleVMatrix> PLearn::ReconstructionWeightsKernel::centered_neighborhood [mutable, private]
 

Used in 'reconstruct' to point toward the locally centered data.

Definition at line 83 of file ReconstructionWeightsKernel.h.

Referenced by reconstruct().

Ker PLearn::ReconstructionWeightsKernel::dist_ker [protected]
 

The kernel used to compute distances (equal to 'distance_kernel' if specified, and otherwise the usual Euclidean distance).

Definition at line 98 of file ReconstructionWeightsKernel.h.

Referenced by build_(), computeWeights(), evaluate_x_i_again(), and setDataForKernelMatrix().

Ker PLearn::ReconstructionWeightsKernel::distance_kernel
 

Definition at line 125 of file ReconstructionWeightsKernel.h.

Referenced by build_().

Ker PLearn::ReconstructionWeightsKernel::dot_product_kernel
 

Definition at line 126 of file ReconstructionWeightsKernel.h.

Referenced by build_().

Ker PLearn::ReconstructionWeightsKernel::dp_ker [protected]
 

The kernel used to compute dot products (equal to 'dot_product_kernel' if specified, and otherwise the usual DotProductKernel).

Definition at line 102 of file ReconstructionWeightsKernel.h.

Referenced by build_(), and reconstruct().

int PLearn::ReconstructionWeightsKernel::ignore_nearest
 

Definition at line 127 of file ReconstructionWeightsKernel.h.

Referenced by build_(), computeWeights(), evaluate_i_j(), evaluate_sum_k_i_k_j(), and evaluate_x_i_again().

TVec< TMat<int> > PLearn::ReconstructionWeightsKernel::is_neighbor_of [protected]
 

The element i is a matrix whose first column is the list of the points which have i among their neighbors, and the second column is the index of i in these neighbors.

The first column is sorted by increasing index, and does not contain i.

Definition at line 111 of file ReconstructionWeightsKernel.h.

Referenced by computeWeights(), and evaluate_sum_k_i_k_j().

Mat PLearn::ReconstructionWeightsKernel::k_xi_x_sorted [mutable, private]
 

Used in 'evaluate_x_i_again' to store the distances from x to its nearest neighbors.

Definition at line 71 of file ReconstructionWeightsKernel.h.

Referenced by evaluate_x_i_again().

int PLearn::ReconstructionWeightsKernel::knn
 

Definition at line 128 of file ReconstructionWeightsKernel.h.

Referenced by build_(), computeLLEMatrix(), computeWeights(), evaluate_i_j(), evaluate_sum_k_i_k_j(), and evaluate_x_i_again().

Mat PLearn::ReconstructionWeightsKernel::local_gram [mutable, private]
 

Used in 'reconstruct' to store the local Gram matrix.

Definition at line 80 of file ReconstructionWeightsKernel.h.

Referenced by reconstruct().

TMat<int> PLearn::ReconstructionWeightsKernel::neighbors [protected]
 

The indices of the neighbors of each data point.

Definition at line 105 of file ReconstructionWeightsKernel.h.

Referenced by computeLLEMatrix(), computeWeights(), and evaluate_i_j().

TVec<int> PLearn::ReconstructionWeightsKernel::neighbors_of_x [mutable, private]
 

Used in 'evaluate_x_i_again' to store the neighbors of x.

Definition at line 74 of file ReconstructionWeightsKernel.h.

Referenced by evaluate_x_i_again().

bool PLearn::ReconstructionWeightsKernel::new_data [mutable, private]
 

True iff the 'setDataForKernelMatrix' method has been called since last time we called 'reconstruct'.

This is necessary to ensure everything is correctly initialized in the 'reconstruct' method.

Definition at line 67 of file ReconstructionWeightsKernel.h.

Referenced by reconstruct(), and setDataForKernelMatrix().

Vec PLearn::ReconstructionWeightsKernel::ones [mutable, private]
 

Used in 'reconstruct' to store a vector filled with 1.

Definition at line 86 of file ReconstructionWeightsKernel.h.

Referenced by reconstruct().

real PLearn::ReconstructionWeightsKernel::regularizer
 

Definition at line 129 of file ReconstructionWeightsKernel.h.

Referenced by reconstruct().

PP<SelectRowsVMatrix> PLearn::ReconstructionWeightsKernel::sub_data [protected]
 

Points toward a subset of the training data (typically, a neighborhood).

Definition at line 114 of file ReconstructionWeightsKernel.h.

Referenced by reconstruct(), ReconstructionWeightsKernel(), and setDataForKernelMatrix().

Mat PLearn::ReconstructionWeightsKernel::weights [protected]
 

The matrix with the weights W_{ij}.

Definition at line 117 of file ReconstructionWeightsKernel.h.

Referenced by computeLLEMatrix(), computeWeights(), evaluate_i_j(), and evaluate_sum_k_i_k_j().

Vec PLearn::ReconstructionWeightsKernel::weights_x [mutable, private]
 

Used in 'evaluate_x_i_again' to store the reconstruction weights of x.

Definition at line 77 of file ReconstructionWeightsKernel.h.

Referenced by evaluate_x_i_again(), and reconstruct().


The documentation for this class was generated from the following files:
Generated on Tue Aug 17 16:23:41 2004 for PLearn by doxygen 1.3.7