shark::SigmoidModel Class Reference

Standard sigmoid function. More...

#include <shark/Models/SigmoidModel.h>

+ Inheritance diagram for shark::SigmoidModel:

Public Member Functions

SHARK_EXPORT_SYMBOL SigmoidModel (bool transform_for_unconstrained=true)
 
std::string name () const
 From INameable: return the class name. More...
 
SHARK_EXPORT_SYMBOL RealVector parameterVector () const
 Return the parameter vector. More...
 
SHARK_EXPORT_SYMBOL void setParameterVector (RealVector const &newParameters)
 
std::size_t numberOfParameters () const
 Return the number of parameters. More...
 
SHARK_EXPORT_SYMBOL void setOffsetActivity (bool enable_offset)
 
bool hasOffset () const
 
bool slopeIsExpEncoded () const
 
virtual SHARK_EXPORT_SYMBOL double sigmoid (double x) const
 activation function \(g_{output}(x)\) More...
 
virtual double sigmoidDerivative (double gx) const
 Computes the derivative of the activation function \(g_{output}(x)\) for the output given the last response of the model gx=g(x) More...
 
boost::shared_ptr< StatecreateState () const
 Creates an internal state of the model. More...
 
SHARK_EXPORT_SYMBOL void eval (BatchInputType const &pattern, BatchOutputType &output, State &state) const
 Standard interface for evaluating the response of the model to a batch of patterns. More...
 
SHARK_EXPORT_SYMBOL void eval (BatchInputType const &pattern, BatchOutputType &output) const
 Standard interface for evaluating the response of the model to a batch of patterns. More...
 
SHARK_EXPORT_SYMBOL void weightedParameterDerivative (BatchInputType const &pattern, 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 &pattern, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const
 calculates the weighted sum of derivatives w.r.t the inputs More...
 
std::size_t inputSize () const
 
std::size_t outputSize () const
 
void setMinLogValue (double logvalue=-230.0)
 
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< RealVector, RealVector >
 AbstractModel ()
 
virtual ~AbstractModel ()
 
const Featuresfeatures () 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< 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 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, 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 &parameterDerivative, 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 ()
 

Protected Attributes

RealVector m_parameters
 the parameter vector More...
 
bool m_useOffset
 whether or not to allow non-zero offset values More...
 
bool m_transformForUnconstrained
 flag for encoding variant More...
 
double m_minLogValue
 what value should be returned as log-encoded slope if the true slope is actually zero More...
 
- Protected Attributes inherited from shark::AbstractModel< RealVector, RealVector >
Features m_features
 

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< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 

Detailed Description

Standard sigmoid function.

This model maps a real-valued input to the unit interval by the sigmoid function \( f(x) = \frac{1}{1 + \exp(-Ax+B))} \), where the real-valued model parameter A controls the slope, and the real-valued offset model parameter B controls the position of the symmetry point. This is a special case of a feed forward neural network consisting of a single sigmoid layer. Note that the parameter A is expected to be non-negative (and hence does not incorporate the minus sign in the sigmoid's equation). Also, the offset parameter can be disabled using the setOffsetActivity() member function.
See also
TanhSigmoidModel SimpleSigmoidModel

Definition at line 51 of file SigmoidModel.h.

Constructor & Destructor Documentation

◆ SigmoidModel()

SHARK_EXPORT_SYMBOL shark::SigmoidModel::SigmoidModel ( bool  transform_for_unconstrained = true)

default ctor

Parameters
transform_for_unconstrainedwhen a new paramVector is set, should the exponent of the first parameter be used as the sigmoid's slope?

Member Function Documentation

◆ createState()

boost::shared_ptr<State> shark::SigmoidModel::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< RealVector, RealVector >.

Definition at line 102 of file SigmoidModel.h.

References eval(), SHARK_EXPORT_SYMBOL, weightedInputDerivative(), and weightedParameterDerivative().

◆ eval() [1/2]

SHARK_EXPORT_SYMBOL void shark::SigmoidModel::eval ( BatchInputType const &  patterns,
BatchOutputType outputs,
State state 
) const
virtual

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< RealVector, RealVector >.

Referenced by createState().

◆ eval() [2/2]

SHARK_EXPORT_SYMBOL void shark::SigmoidModel::eval ( BatchInputType const &  patterns,
BatchOutputType outputs 
) const
virtual

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< RealVector, RealVector >.

◆ hasOffset()

bool shark::SigmoidModel::hasOffset ( ) const
inline

Definition at line 83 of file SigmoidModel.h.

References m_useOffset.

◆ inputSize()

std::size_t shark::SigmoidModel::inputSize ( ) const
inline

Definition at line 118 of file SigmoidModel.h.

◆ name()

std::string shark::SigmoidModel::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Reimplemented in shark::TanhSigmoidModel, and shark::SimpleSigmoidModel.

Definition at line 68 of file SigmoidModel.h.

References parameterVector(), setParameterVector(), and SHARK_EXPORT_SYMBOL.

◆ numberOfParameters()

std::size_t shark::SigmoidModel::numberOfParameters ( ) const
inlinevirtual

Return the number of parameters.

Reimplemented from shark::IParameterizable.

Definition at line 77 of file SigmoidModel.h.

References setOffsetActivity(), and SHARK_EXPORT_SYMBOL.

◆ outputSize()

std::size_t shark::SigmoidModel::outputSize ( ) const
inline

Definition at line 121 of file SigmoidModel.h.

References read(), setMinLogValue(), and write().

◆ parameterVector()

SHARK_EXPORT_SYMBOL RealVector shark::SigmoidModel::parameterVector ( ) const
virtual

Return the parameter vector.

Reimplemented from shark::IParameterizable.

Referenced by shark::SvmLogisticInterpretation< InputType >::evalDerivative(), and name().

◆ read()

void shark::SigmoidModel::read ( InArchive archive)
virtual

From ISerializable, reads a model from an archive.

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

Referenced by outputSize().

◆ setMinLogValue()

void shark::SigmoidModel::setMinLogValue ( double  logvalue = -230.0)

set the minimum log value that should be returned as log-encoded slope if the true slope is actually zero. default in ctor sets -230. param logvalue the new minimum log value

Referenced by outputSize().

◆ setOffsetActivity()

SHARK_EXPORT_SYMBOL void shark::SigmoidModel::setOffsetActivity ( bool  enable_offset)

Referenced by numberOfParameters().

◆ setParameterVector()

SHARK_EXPORT_SYMBOL void shark::SigmoidModel::setParameterVector ( RealVector const &  newParameters)
virtual

note that the parameters are not expected to incorporate the minus sign in the sigmoid's equation

Parameters
newParametersthe new parameter vector A and offset B concatenated

Reimplemented from shark::IParameterizable.

Referenced by name().

◆ sigmoid()

virtual SHARK_EXPORT_SYMBOL double shark::SigmoidModel::sigmoid ( double  x) const
virtual

activation function \(g_{output}(x)\)

Reimplemented in shark::TanhSigmoidModel, and shark::SimpleSigmoidModel.

Referenced by slopeIsExpEncoded().

◆ sigmoidDerivative()

virtual double shark::SigmoidModel::sigmoidDerivative ( double  gx) const
virtual

Computes the derivative of the activation function \(g_{output}(x)\) for the output given the last response of the model gx=g(x)

Reimplemented in shark::TanhSigmoidModel, and shark::SimpleSigmoidModel.

Referenced by slopeIsExpEncoded().

◆ slopeIsExpEncoded()

bool shark::SigmoidModel::slopeIsExpEncoded ( ) const
inline

◆ weightedInputDerivative()

SHARK_EXPORT_SYMBOL void shark::SigmoidModel::weightedInputDerivative ( BatchInputType const &  pattern,
BatchOutputType const &  coefficients,
State const &  state,
BatchInputType derivative 
) const
virtual

calculates the weighted sum of derivatives w.r.t the inputs

Parameters
patternthe patterns to evaluate
coefficientsthe coefficients which are used to calculate the weighted sum for every pattern
stateintermediate results stored by eval to sped up calculations of the derivatives
derivativethe calculated derivative for every pattern

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

Referenced by createState().

◆ weightedParameterDerivative()

SHARK_EXPORT_SYMBOL void shark::SigmoidModel::weightedParameterDerivative ( BatchInputType const &  pattern,
BatchOutputType const &  coefficients,
State const &  state,
RealVector &  derivative 
) const
virtual

calculates the weighted sum of derivatives w.r.t the parameters.

Parameters
patternthe patterns to evaluate
coefficientsthe coefficients which are used to calculate the weighted sum for every pattern
stateintermediate results stored by eval to speed up calculations of the derivatives
derivativethe calculated derivative as sum over all derivates of all patterns

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

Referenced by createState().

◆ write()

void shark::SigmoidModel::write ( OutArchive archive) const
virtual

From ISerializable, writes a model to an archive.

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

Referenced by outputSize().

Member Data Documentation

◆ m_minLogValue

double shark::SigmoidModel::m_minLogValue
protected

what value should be returned as log-encoded slope if the true slope is actually zero

Definition at line 140 of file SigmoidModel.h.

◆ m_parameters

RealVector shark::SigmoidModel::m_parameters
protected

the parameter vector

Definition at line 136 of file SigmoidModel.h.

◆ m_transformForUnconstrained

bool shark::SigmoidModel::m_transformForUnconstrained
protected

flag for encoding variant

Definition at line 139 of file SigmoidModel.h.

Referenced by slopeIsExpEncoded().

◆ m_useOffset

bool shark::SigmoidModel::m_useOffset
protected

whether or not to allow non-zero offset values

Definition at line 137 of file SigmoidModel.h.

Referenced by hasOffset().


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