Nearest neighbor regression model. More...
#include <shark/Models/NearestNeighborRegression.h>
Inheritance diagram for shark::NearestNeighborRegression< InputType >:
Collaboration diagram for shark::NearestNeighborRegression< InputType >:Public Types | |
| typedef AbstractNearestNeighbors < InputType, RealVector > | NearestNeighbors |
| typedef base_type::BatchInputType | BatchInputType |
| typedef base_type::BatchOutputType | BatchOutputType |
Public Types inherited from shark::AbstractModel< InputType, RealVector > | |
| enum | Feature |
| typedef InputType | InputType |
| Defines the input type of the model. More... | |
| typedef RealVector | OutputType |
| Defines the output type of the model. More... | |
| typedef Batch< InputType >::type | BatchInputType |
| defines the batch type of the input type. More... | |
| typedef Batch< OutputType >::type | BatchOutputType |
| defines the batch type of the output type More... | |
| typedef TypedFlags< Feature > | Features |
| typedef TypedFeatureNotAvailableException < Feature > | FeatureNotAvailableException |
Public Member Functions | |
| NearestNeighborRegression (NearestNeighbors const *algorithm, unsigned int neighbors=3) | |
| Constructor. More... | |
| std::string | name () const |
| From INameable: return the class name. More... | |
| unsigned int | neighbors () const |
| return the number of neighbors More... | |
| void | setNeighbors (unsigned int neighbors) |
| set the number of neighbors More... | |
| void | configure (PropertyTree const &node) |
| configures the classifier. More... | |
| virtual RealVector | parameterVector () const |
| get internal parameters of the model More... | |
| virtual void | setParameterVector (RealVector const &newParameters) |
| set internal parameters of the model More... | |
| virtual std::size_t | numberOfParameters () const |
| return the size of the parameter vector More... | |
| boost::shared_ptr< State > | createState () const |
| Creates an internal state of the model. More... | |
| void | eval (BatchInputType const &patterns, BatchOutputType &output, State &state) const |
| soft k-nearest-neighbor prediction More... | |
| void | read (InArchive &archive) |
| from ISerializable, reads a model from an archive More... | |
| void | write (OutArchive &archive) const |
| from ISerializable, writes a model to an archive More... | |
Public Member Functions inherited from shark::AbstractModel< InputType, RealVector > | |
| AbstractModel () | |
| virtual | ~AbstractModel () |
| const Features & | features () const |
| virtual void | updateFeatures () |
| bool | hasFirstParameterDerivative () const |
| Returns true when the first parameter derivative is implemented. More... | |
| bool | hasSecondParameterDerivative () const |
| Returns true when the second parameter derivative is implemented. More... | |
| bool | hasFirstInputDerivative () const |
| Returns true when the first input derivative is implemented. More... | |
| bool | hasSecondInputDerivative () const |
| Returns true when the second parameter derivative is implemented. More... | |
| bool | isSequential () const |
| virtual void | eval (BatchInputType const &patterns, BatchOutputType &outputs) const |
| Standard interface for evaluating the response of the model to a batch of patterns. More... | |
| virtual void | eval (InputType const &pattern, OutputType &output) const |
| Standard interface for evaluating the response of the model to a single pattern. More... | |
| Data< OutputType > | operator() (Data< InputType > const &patterns) const |
| Model evaluation as an operator for a whole dataset. This is a convenience function. More... | |
| OutputType | operator() (InputType const &pattern) const |
| Model evaluation as an operator for a single pattern. This is a convenience function. More... | |
| BatchOutputType | operator() (BatchInputType const &patterns) const |
| Model evaluation as an operator for a single pattern. This is a convenience function. More... | |
| virtual void | weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, State const &state, RealVector &derivative) const |
| calculates the weighted sum of derivatives w.r.t the parameters. More... | |
| virtual void | weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, Batch< RealMatrix >::type const &errorHessian, State const &state, RealVector &derivative, RealMatrix &hessian) const |
| calculates the weighted sum of derivatives w.r.t the parameters More... | |
| virtual void | weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const |
| calculates the weighted sum of derivatives w.r.t the inputs More... | |
| virtual void | weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, typename Batch< RealMatrix >::type const &errorHessian, State const &state, RealMatrix &derivative, Batch< RealMatrix >::type &hessian) const |
| calculates the weighted sum of derivatives w.r.t the inputs More... | |
| virtual void | weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &coefficients, State const &state, RealVector ¶meterDerivative, BatchInputType &inputDerivative) const |
| calculates weighted input and parameter derivative at the same time More... | |
Public Member Functions inherited from shark::IParameterizable | |
| virtual | ~IParameterizable () |
Public Member Functions inherited from shark::IConfigurable | |
| virtual | ~IConfigurable () |
| Virtual d'tor. More... | |
Public Member Functions inherited from shark::INameable | |
| virtual | ~INameable () |
Public Member Functions inherited from shark::ISerializable | |
| virtual | ~ISerializable () |
| Virtual d'tor. More... | |
| void | load (InArchive &archive, unsigned int version) |
| Versioned loading of components, calls read(...). More... | |
| void | save (OutArchive &archive, unsigned int version) const |
| Versioned storing of components, calls write(...). More... | |
| BOOST_SERIALIZATION_SPLIT_MEMBER () | |
Protected Attributes | |
| NearestNeighbors const * | m_algorithm |
| unsigned int | m_classes |
| number of classes More... | |
| unsigned int | m_neighbors |
| number of neighbors to be taken into account More... | |
Protected Attributes inherited from shark::AbstractModel< InputType, RealVector > | |
| Features | m_features |
Nearest neighbor regression model.
The NearestNeighborClassifier predicts a class label according to a local majority decision among its k nearest neighbors. It is not specified how ties are broken.
| InputType | Type of input data |
| tree_type | Type of binary tree for nearest neighbor search. See KDTree and LCTree for Euclidean distance, and KHCTree for kernel distance. |
Definition at line 56 of file NearestNeighborRegression.h.
| typedef base_type::BatchInputType shark::NearestNeighborRegression< InputType >::BatchInputType |
Definition at line 62 of file NearestNeighborRegression.h.
| typedef base_type::BatchOutputType shark::NearestNeighborRegression< InputType >::BatchOutputType |
Definition at line 63 of file NearestNeighborRegression.h.
| typedef AbstractNearestNeighbors<InputType,RealVector> shark::NearestNeighborRegression< InputType >::NearestNeighbors |
Definition at line 60 of file NearestNeighborRegression.h.
|
inline |
Constructor.
| algorithm | the used algorithm for nearst neighbor search |
| classes,: | number of classes |
| neighbors,: | number of neighbors |
Definition at line 70 of file NearestNeighborRegression.h.
|
inlinevirtual |
configures the classifier.
Reimplemented from shark::IConfigurable.
Definition at line 89 of file NearestNeighborRegression.h.
References shark::NearestNeighborRegression< InputType >::m_neighbors.
|
inlinevirtual |
Creates an internal state of the model.
The state is needed when the derivatives are to be calculated. Eval can store a state which is then reused to speed up the calculations of the derivatives. This also allows eval to be evaluated in parallel!
Reimplemented from shark::AbstractModel< InputType, RealVector >.
Definition at line 114 of file NearestNeighborRegression.h.
|
inlinevirtual |
soft k-nearest-neighbor prediction
Implements shark::AbstractModel< InputType, RealVector >.
Definition at line 121 of file NearestNeighborRegression.h.
References shark::AbstractNearestNeighbors< InputType, LabelType >::getNeighbors(), shark::NearestNeighborRegression< InputType >::m_algorithm, shark::NearestNeighborRegression< InputType >::m_neighbors, shark::NearestNeighborRegression< InputType >::neighbors(), shark::blas::noalias(), shark::blas::row(), shark::size(), and shark::zero().
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 74 of file NearestNeighborRegression.h.
|
inline |
return the number of neighbors
Definition at line 79 of file NearestNeighborRegression.h.
References shark::NearestNeighborRegression< InputType >::m_neighbors.
Referenced by shark::NearestNeighborRegression< InputType >::eval(), and shark::NearestNeighborRegression< InputType >::setNeighbors().
|
inlinevirtual |
return the size of the parameter vector
Reimplemented from shark::IParameterizable.
Definition at line 110 of file NearestNeighborRegression.h.
|
inlinevirtual |
get internal parameters of the model
Reimplemented from shark::IParameterizable.
Definition at line 94 of file NearestNeighborRegression.h.
References shark::NearestNeighborRegression< InputType >::m_neighbors, and shark::parameters().
|
inlinevirtual |
from ISerializable, reads a model from an archive
Reimplemented from shark::AbstractModel< InputType, RealVector >.
Definition at line 136 of file NearestNeighborRegression.h.
References shark::NearestNeighborRegression< InputType >::m_classes, and shark::NearestNeighborRegression< InputType >::m_neighbors.
|
inline |
set the number of neighbors
Definition at line 84 of file NearestNeighborRegression.h.
References shark::NearestNeighborRegression< InputType >::m_neighbors, and shark::NearestNeighborRegression< InputType >::neighbors().
|
inlinevirtual |
set internal parameters of the model
Reimplemented from shark::IParameterizable.
Definition at line 101 of file NearestNeighborRegression.h.
References shark::NearestNeighborRegression< InputType >::m_neighbors, and SHARK_CHECK.
|
inlinevirtual |
from ISerializable, writes a model to an archive
Reimplemented from shark::AbstractModel< InputType, RealVector >.
Definition at line 142 of file NearestNeighborRegression.h.
References shark::NearestNeighborRegression< InputType >::m_classes, and shark::NearestNeighborRegression< InputType >::m_neighbors.
|
protected |
Definition at line 148 of file NearestNeighborRegression.h.
Referenced by shark::NearestNeighborRegression< InputType >::eval().
|
protected |
number of classes
Definition at line 151 of file NearestNeighborRegression.h.
Referenced by shark::NearestNeighborRegression< InputType >::read(), and shark::NearestNeighborRegression< InputType >::write().
|
protected |
number of neighbors to be taken into account
Definition at line 154 of file NearestNeighborRegression.h.
Referenced by shark::NearestNeighborRegression< InputType >::configure(), shark::NearestNeighborRegression< InputType >::eval(), shark::NearestNeighborRegression< InputType >::neighbors(), shark::NearestNeighborRegression< InputType >::parameterVector(), shark::NearestNeighborRegression< InputType >::read(), shark::NearestNeighborRegression< InputType >::setNeighbors(), shark::NearestNeighborRegression< InputType >::setParameterVector(), and shark::NearestNeighborRegression< InputType >::write().