#include <shark/Models/Softmax.h>
Public Member Functions | |
SHARK_EXPORT_SYMBOL | Softmax (size_t inputs) |
Constructor. More... | |
SHARK_EXPORT_SYMBOL | Softmax () |
Constructor. More... | |
std::string | name () const |
From INameable: return the class name. More... | |
RealVector | parameterVector () const |
Return the parameter vector. More... | |
void | setParameterVector (RealVector const &newParameters) |
Set the parameter vector. More... | |
size_t | inputSize () const |
size_t | outputSize () const |
size_t | numberOfParameters () const |
Return the number of parameters. More... | |
boost::shared_ptr< State > | createState () const |
Creates an internal state of the model. More... | |
SHARK_EXPORT_SYMBOL void | eval (BatchInputType const &patterns, BatchOutputType &output) const |
Standard interface for evaluating the response of the model to a batch of patterns. More... | |
SHARK_EXPORT_SYMBOL void | eval (BatchInputType const &patterns, BatchOutputType &output, State &state) const |
Standard interface for evaluating the response of the model to a batch of patterns. More... | |
SHARK_EXPORT_SYMBOL void | weightedParameterDerivative (BatchInputType const &patterns, BatchOutputType const &coefficients, State const &state, RealVector &gradient) const |
calculates the weighted sum of derivatives w.r.t the parameters. More... | |
SHARK_EXPORT_SYMBOL void | weightedInputDerivative (BatchInputType const &patterns, RealMatrix const &coefficients, State const &state, BatchOutputType &gradient) const |
void | setStructure (std::size_t inputSize) |
SHARK_EXPORT_SYMBOL void | read (InArchive &archive) |
From ISerializable, reads a model from an archive. More... | |
SHARK_EXPORT_SYMBOL void | write (OutArchive &archive) const |
From ISerializable, writes a model to an archive. More... | |
Public Member Functions inherited from shark::AbstractModel< RealVector, 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 (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, 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::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 | |
Public Types inherited from shark::AbstractModel< RealVector, RealVector > | |
enum | Feature |
typedef RealVector | 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 |
Protected Attributes inherited from shark::AbstractModel< RealVector, RealVector > | |
Features | m_features |
Softmax function.
\[ f_i(x) = \frac{\exp(x_i)}{\sum_j \exp(x_j)} \]
This also corresponds to the exponential norm of the input.in the case of n=1, the output is
\[ f_i(x) = \frac{\exp((2i-1)x)}{\exp(x_j)+\exp(-x_j)} \]
and the output dimension is 2.
This convention ensures that all models that are trained via CrossEntropy can be used as input to this model and the output will be the probability of the labels.
SHARK_EXPORT_SYMBOL shark::Softmax::Softmax | ( | size_t | inputs | ) |
Constructor.
SHARK_EXPORT_SYMBOL shark::Softmax::Softmax | ( | ) |
Constructor.
|
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< RealVector, RealVector >.
Definition at line 103 of file Softmax.h.
References eval(), SHARK_EXPORT_SYMBOL, weightedInputDerivative(), and weightedParameterDerivative().
|
virtual |
Standard interface for evaluating the response of the model to a batch of patterns.
patterns | the inputs of the model |
outputs | the predictions or response of the model to every pattern |
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Referenced by createState().
|
virtual |
Standard interface for evaluating the response of the model to a batch of patterns.
patterns | the inputs of the model |
outputs | the predictions or response of the model to every pattern |
state | intermediate results stored by eval which can be reused for derivative computation. |
Implements shark::AbstractModel< RealVector, RealVector >.
|
inline |
Definition at line 93 of file Softmax.h.
Referenced by setStructure().
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
|
inlinevirtual |
Return the number of parameters.
Reimplemented from shark::IParameterizable.
|
inlinevirtual |
Return the parameter vector.
Reimplemented from shark::IParameterizable.
|
virtual |
From ISerializable, reads a model from an archive.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Referenced by setStructure().
|
inlinevirtual |
Set the parameter vector.
Reimplemented from shark::IParameterizable.
Definition at line 89 of file Softmax.h.
References SIZE_CHECK.
|
inline |
Definition at line 118 of file Softmax.h.
References inputSize(), read(), SHARK_EXPORT_SYMBOL, and write().
SHARK_EXPORT_SYMBOL void shark::Softmax::weightedInputDerivative | ( | BatchInputType const & | patterns, |
RealMatrix const & | coefficients, | ||
State const & | state, | ||
BatchOutputType & | gradient | ||
) | const |
Referenced by createState().
|
virtual |
calculates the weighted sum of derivatives w.r.t the parameters.
pattern | the patterns to evaluate |
coefficients | the coefficients which are used to calculate the weighted sum for every pattern |
state | intermediate results stored by eval to speed up calculations of the derivatives |
derivative | the calculated derivative as sum over all derivates of all patterns |
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Referenced by createState().
|
virtual |
From ISerializable, writes a model to an archive.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Referenced by setStructure().