shark::NeuronLayer< NeuronType, VectorType > Class Template Reference

#include <shark/Models/NeuronLayers.h>

+ Inheritance diagram for shark::NeuronLayer< NeuronType, VectorType >:

Public Types

typedef base_type::BatchInputType BatchInputType
 
typedef base_type::BatchOutputType BatchOutputType
 
typedef base_type::ParameterVectorType ParameterVectorType
 
- Public Types inherited from shark::AbstractModel< VectorType, VectorType, VectorType >
enum  Feature
 
typedef VectorType InputType
 Defines the input type of the model. More...
 
typedef VectorType OutputType
 Defines the output type of the model. More...
 
typedef AbstractModel< VectorType, VectorType, VectorTypeModelBaseType
 Defines the BaseType used by the model (this type). Useful for creating derived models. 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< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 
- Public Types inherited from shark::IParameterizable< VectorType >
typedef VectorType ParameterVectorType
 

Public Member Functions

 NeuronLayer (Shape const &shape=Shape())
 
std::string name () const
 From INameable: return the class name. More...
 
NeuronType const & neuron () const
 
NeuronType & neuron ()
 
Shape inputShape () const
 Returns the expected shape of the input. More...
 
Shape outputShape () const
 Returns the shape of the output. More...
 
ParameterVectorType parameterVector () const
 obtain the parameter vector More...
 
void setParameterVector (ParameterVectorType const &newParameters)
 overwrite the parameter vector More...
 
size_t numberOfParameters () const
 return the number of parameter More...
 
boost::shared_ptr< StatecreateState () const
 Creates an internal state of the model. More...
 
void eval (BatchInputType const &inputs, BatchOutputType &outputs) const
 Standard interface for evaluating the response of the model to a batch of patterns. More...
 
void eval (VectorType const &input, VectorType &output) const
 Standard interface for evaluating the response of the model to a single pattern. More...
 
void eval (BatchInputType const &inputs, BatchOutputType &outputs, State &state) const
 Standard interface for evaluating the response of the model to a batch of patterns. More...
 
void weightedParameterDerivative (BatchInputType const &inputs, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, ParameterVectorType &gradient) const
 Calculates the first derivative w.r.t the parameters and summing them up over all inputs of the last computed batch. More...
 
void weightedInputDerivative (BatchInputType const &inputs, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const
 Calculates the first derivative w.r.t the inputs and summs them up over all inputs of the last computed batch. More...
 
void read (InArchive &archive)
 From ISerializable. More...
 
void write (OutArchive &archive) const
 From ISerializable. More...
 
- Public Member Functions inherited from shark::AbstractModel< VectorType, VectorType, VectorType >
 AbstractModel ()
 
virtual ~AbstractModel ()
 
const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool hasFirstParameterDerivative () const
 Returns true when the first parameter derivative is implemented. More...
 
bool hasFirstInputDerivative () const
 Returns true when the first input derivative is implemented. More...
 
Data< OutputTypeoperator() (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 weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, RealVector &parameterDerivative, BatchInputType &inputDerivative) const
 calculates weighted input and parameter derivative at the same time More...
 
- Public Member Functions inherited from shark::IParameterizable< VectorType >
virtual ~IParameterizable ()
 
- 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 ()
 

Additional Inherited Members

- Protected Attributes inherited from shark::AbstractModel< VectorType, VectorType, VectorType >
Features m_features
 

Detailed Description

template<class NeuronType, class VectorType = RealVector>
class shark::NeuronLayer< NeuronType, VectorType >

Definition at line 215 of file NeuronLayers.h.

Member Typedef Documentation

◆ BatchInputType

template<class NeuronType , class VectorType = RealVector>
typedef base_type::BatchInputType shark::NeuronLayer< NeuronType, VectorType >::BatchInputType

Definition at line 222 of file NeuronLayers.h.

◆ BatchOutputType

template<class NeuronType , class VectorType = RealVector>
typedef base_type::BatchOutputType shark::NeuronLayer< NeuronType, VectorType >::BatchOutputType

Definition at line 223 of file NeuronLayers.h.

◆ ParameterVectorType

template<class NeuronType , class VectorType = RealVector>
typedef base_type::ParameterVectorType shark::NeuronLayer< NeuronType, VectorType >::ParameterVectorType

Definition at line 224 of file NeuronLayers.h.

Constructor & Destructor Documentation

◆ NeuronLayer()

template<class NeuronType , class VectorType = RealVector>
shark::NeuronLayer< NeuronType, VectorType >::NeuronLayer ( Shape const &  shape = Shape())
inline

Definition at line 226 of file NeuronLayers.h.

Member Function Documentation

◆ createState()

template<class NeuronType , class VectorType = RealVector>
boost::shared_ptr<State> shark::NeuronLayer< NeuronType, VectorType >::createState ( ) const
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< VectorType, VectorType, VectorType >.

Definition at line 261 of file NeuronLayers.h.

◆ eval() [1/3]

template<class NeuronType , class VectorType = RealVector>
void shark::NeuronLayer< NeuronType, VectorType >::eval ( BatchInputType const &  patterns,
BatchOutputType outputs 
) const
inlinevirtual

Standard interface for evaluating the response of the model to a batch of patterns.

Parameters
patternsthe inputs of the model
outputsthe predictions or response of the model to every pattern

Reimplemented from shark::AbstractModel< VectorType, VectorType, VectorType >.

Definition at line 267 of file NeuronLayers.h.

References shark::Shape::numElements(), and SIZE_CHECK.

◆ eval() [2/3]

template<class NeuronType , class VectorType = RealVector>
void shark::NeuronLayer< NeuronType, VectorType >::eval ( VectorType const &  pattern,
VectorType output 
) const
inlinevirtual

Standard interface for evaluating the response of the model to a single pattern.

Parameters
patternthe input of the model
outputthe prediction or response of the model to the pattern

Reimplemented from shark::AbstractModel< VectorType, VectorType, VectorType >.

Definition at line 274 of file NeuronLayers.h.

References shark::Shape::numElements(), and SIZE_CHECK.

◆ eval() [3/3]

template<class NeuronType , class VectorType = RealVector>
void shark::NeuronLayer< NeuronType, VectorType >::eval ( BatchInputType const &  patterns,
BatchOutputType outputs,
State state 
) const
inlinevirtual

Standard interface for evaluating the response of the model to a batch of patterns.

Parameters
patternsthe inputs of the model
outputsthe predictions or response of the model to every pattern
stateintermediate results stored by eval which can be reused for derivative computation.

Implements shark::AbstractModel< VectorType, VectorType, VectorType >.

Definition at line 280 of file NeuronLayers.h.

References shark::Shape::numElements(), and SIZE_CHECK.

◆ inputShape()

template<class NeuronType , class VectorType = RealVector>
Shape shark::NeuronLayer< NeuronType, VectorType >::inputShape ( ) const
inlinevirtual

Returns the expected shape of the input.

Implements shark::AbstractModel< VectorType, VectorType, VectorType >.

Definition at line 238 of file NeuronLayers.h.

◆ name()

template<class NeuronType , class VectorType = RealVector>
std::string shark::NeuronLayer< NeuronType, VectorType >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 232 of file NeuronLayers.h.

◆ neuron() [1/2]

template<class NeuronType , class VectorType = RealVector>
NeuronType const& shark::NeuronLayer< NeuronType, VectorType >::neuron ( ) const
inline

Definition at line 235 of file NeuronLayers.h.

◆ neuron() [2/2]

template<class NeuronType , class VectorType = RealVector>
NeuronType& shark::NeuronLayer< NeuronType, VectorType >::neuron ( )
inline

Definition at line 236 of file NeuronLayers.h.

◆ numberOfParameters()

template<class NeuronType , class VectorType = RealVector>
size_t shark::NeuronLayer< NeuronType, VectorType >::numberOfParameters ( ) const
inlinevirtual

return the number of parameter

Reimplemented from shark::IParameterizable< VectorType >.

Definition at line 257 of file NeuronLayers.h.

◆ outputShape()

template<class NeuronType , class VectorType = RealVector>
Shape shark::NeuronLayer< NeuronType, VectorType >::outputShape ( ) const
inlinevirtual

Returns the shape of the output.

Implements shark::AbstractModel< VectorType, VectorType, VectorType >.

Definition at line 242 of file NeuronLayers.h.

◆ parameterVector()

template<class NeuronType , class VectorType = RealVector>
ParameterVectorType shark::NeuronLayer< NeuronType, VectorType >::parameterVector ( ) const
inlinevirtual

obtain the parameter vector

Reimplemented from shark::IParameterizable< VectorType >.

Definition at line 247 of file NeuronLayers.h.

◆ read()

template<class NeuronType , class VectorType = RealVector>
void shark::NeuronLayer< NeuronType, VectorType >::read ( InArchive archive)
inlinevirtual

From ISerializable.

Reimplemented from shark::AbstractModel< VectorType, VectorType, VectorType >.

Definition at line 316 of file NeuronLayers.h.

◆ setParameterVector()

template<class NeuronType , class VectorType = RealVector>
void shark::NeuronLayer< NeuronType, VectorType >::setParameterVector ( ParameterVectorType const &  newParameters)
inlinevirtual

overwrite the parameter vector

Reimplemented from shark::IParameterizable< VectorType >.

Definition at line 252 of file NeuronLayers.h.

References SIZE_CHECK.

◆ weightedInputDerivative()

template<class NeuronType , class VectorType = RealVector>
void shark::NeuronLayer< NeuronType, VectorType >::weightedInputDerivative ( BatchInputType const &  inputs,
BatchOutputType const &  outputs,
BatchOutputType const &  coefficients,
State const &  state,
BatchInputType derivative 
) const
inlinevirtual

Calculates the first derivative w.r.t the inputs and summs them up over all inputs of the last computed batch.

Reimplemented from shark::AbstractModel< VectorType, VectorType, VectorType >.

Definition at line 299 of file NeuronLayers.h.

References SIZE_CHECK.

◆ weightedParameterDerivative()

template<class NeuronType , class VectorType = RealVector>
void shark::NeuronLayer< NeuronType, VectorType >::weightedParameterDerivative ( BatchInputType const &  inputs,
BatchOutputType const &  outputs,
BatchOutputType const &  coefficients,
State const &  state,
ParameterVectorType gradient 
) const
inlinevirtual

Calculates the first derivative w.r.t the parameters and summing them up over all inputs of the last computed batch.

Reimplemented from shark::AbstractModel< VectorType, VectorType, VectorType >.

Definition at line 288 of file NeuronLayers.h.

References SIZE_CHECK.

◆ write()

template<class NeuronType , class VectorType = RealVector>
void shark::NeuronLayer< NeuronType, VectorType >::write ( OutArchive archive) const
inlinevirtual

From ISerializable.

Reimplemented from shark::AbstractModel< VectorType, VectorType, VectorType >.

Definition at line 318 of file NeuronLayers.h.


The documentation for this class was generated from the following file: