MeLOn
Loading...
Searching...
No Matches
melon::FeedForwardNet< T > Class Template Reference

This class represents a feed foward artificial network to be used in the MAiNGO solver. More...

#include <ffNet.h>

Inheritance diagram for melon::FeedForwardNet< T >:
melon::MelonModel< T >

Public Member Functions

 FeedForwardNet ()
 Constructor for creating object with no model loaded.
 
 FeedForwardNet (std::string modelName, MODEL_FILE_TYPE fileType)
 Constructor for creating object from file with the modelName relative to the current working directory.
 
 FeedForwardNet (std::string modelPath, std::string modelName, MODEL_FILE_TYPE fileType)
 Constructor for creating object from file with the modelName being relative to modelPath.
 
 FeedForwardNet (std::shared_ptr< AnnData > modelData)
 Constructor for creating object from existing AnnData object.
 
 ~FeedForwardNet ()=default
 Default Destructor.
 
std::vector< T > calculate_prediction_reduced_space (const std::vector< T > input)
 Calculates the prediction of the feed forward net for a given point in reduced space mode (only values network inputs are given)
 
std::vector< T > calculate_prediction_full_space (const std::vector< T > input, const std::vector< T > internalVariables, std::vector< T > &constraints)
 Calculates the prediction of the feed forward net for a given point in full space mode (values for all internal variables are given and a set of constraints is returned)
 
void set_tanh_formulation (const TANH_REFORMULATION &reformulation)
 Changes the reformulation to be used for tanh evaluations. The reformulations are intended to be used when solvers do not support the tanh function. As reformulations change the tightness of the McCormick envelopes when used with MAiNGO it is recommended to use the standard tanh whenever possible.
 
unsigned int get_number_of_full_space_variables ()
 Get the number of internal network variables.
 
void get_full_space_variables (unsigned int &variableNumber, std::vector< std::string > &variableNames, std::vector< std::pair< double, double > > &variableBounds)
 Returns the number and the names of the internal variables of the network.
 
- Public Member Functions inherited from melon::MelonModel< T >
virtual ~MelonModel ()=default
 Default destructor.
 
void load_model (std::string modelName, MODEL_FILE_TYPE fileType)
 Loads new model from file.
 
void load_model (std::string modelPath, std::string modelName, MODEL_FILE_TYPE fileType)
 Loads new model from file.
 
void load_model (std::shared_ptr< const ModelData > modelData)
 Loads new model from file.
 

Private Member Functions

std::vector< T > _calculate_layer_activation (const std::vector< T > &v, const ACTIVATION_FUNCTION activationFunction)
 Calculates the activations for a layer given its inputs.
 
std::vector< T > _calculate_prediction (const std::vector< T > input, const std::vector< T > internalVariables, const bool fullSpace, std::vector< T > &constraints)
 Calculates the prediction of the feed forward net for a given point.
 
void _set_data_object (std::shared_ptr< const ModelData > modelData) override
 Sets data object containing model parameters.
 

Static Private Member Functions

static T _tanh (T x)
 
static T _tanh_reformulation_1 (T x)
 
static T _tanh_reformulation_2 (T x)
 
static T _tanh_reformulation_3 (T x)
 
static T _tanh_reformulation_4 (T x)
 
static T _relu (T x)
 
static T _relu6 (T x)
 

Private Attributes

std::shared_ptr< const AnnData_annData
 
std::unique_ptr< Scaler< T > > _inputScaler
 
std::unique_ptr< Scaler< T > > _outputScaler
 
T(* _tanh_formulation )(T) = &_tanh
 

Additional Inherited Members

- Protected Member Functions inherited from melon::MelonModel< T >
 MelonModel (std::shared_ptr< ModelParserFactory > parserFactory)
 Constructor.
 
template<typename RandomAccessIterator >
void _set_constraints (std::vector< T > &constraints, std::vector< T > &constraintEvaluation, RandomAccessIterator &constraintValue) const
 Sets constraints required for fullspace opimization.
 
template<typename RandomAccessIterator >
void _set_constraints (std::vector< T > &constraints, T &constraintEvaluation, RandomAccessIterator &constraintValue) const
 Sets constraints required for fullspace opimization.
 
- Protected Attributes inherited from melon::MelonModel< T >
bool _modelLoaded { false }
 
std::shared_ptr< ModelParserFactory_parserFactory
 

Detailed Description

template<typename T>
class melon::FeedForwardNet< T >

This class represents a feed foward artificial network to be used in the MAiNGO solver.

This class is used to enable the solution of optimization problems in MAiNGO containing feed foward ANNs. The trained ANNs can be loaded from csv/xml files created in matlab/keras.

Constructor & Destructor Documentation

◆ FeedForwardNet() [1/4]

template<typename T >
melon::FeedForwardNet< T >::FeedForwardNet ( )
inline

Constructor for creating object with no model loaded.

◆ FeedForwardNet() [2/4]

template<typename T >
melon::FeedForwardNet< T >::FeedForwardNet ( std::string modelName,
MODEL_FILE_TYPE fileType )
inline

Constructor for creating object from file with the modelName relative to the current working directory.

Parameters
[in]modelNameis the name of the network
[in]fileTypespecifies the data format of the network file

◆ FeedForwardNet() [3/4]

template<typename T >
melon::FeedForwardNet< T >::FeedForwardNet ( std::string modelPath,
std::string modelName,
MODEL_FILE_TYPE fileType )
inline

Constructor for creating object from file with the modelName being relative to modelPath.

Parameters
[in]modelPathis the path to the directory in which the network is located
[in]modelNameis the name of the network
[in]fileTypespecifies the data format of the network file

◆ FeedForwardNet() [4/4]

template<typename T >
melon::FeedForwardNet< T >::FeedForwardNet ( std::shared_ptr< AnnData > modelData)
inline

Constructor for creating object from existing AnnData object.

Parameters
[in]modelDatais a AnnData object containing the data which defines the network

◆ ~FeedForwardNet()

template<typename T >
melon::FeedForwardNet< T >::~FeedForwardNet ( )
default

Default Destructor.

Member Function Documentation

◆ _calculate_layer_activation()

template<typename T >
std::vector< T > melon::FeedForwardNet< T >::_calculate_layer_activation ( const std::vector< T > & v,
const ACTIVATION_FUNCTION activationFunction )
private

Calculates the activations for a layer given its inputs.

Parameters
[in]vis a vector containing the summed inputs for each neuron in the layer
[in]activationFunctionis an enum that determines which activation function should be applied to the layer
Returns
returns a vector containing the activation for each neuron in the layer

◆ _calculate_prediction()

template<typename T >
std::vector< T > melon::FeedForwardNet< T >::_calculate_prediction ( const std::vector< T > input,
const std::vector< T > internalVariables,
const bool fullSpace,
std::vector< T > & constraints )
private

Calculates the prediction of the feed forward net for a given point.

Parameters
[in]inputis a vector containing input variables based on which the network is evaluated
[in]internalVariablesis a vector containing values for the internal variables of the Network
[in]fullSpaceindicates wether the network should be evaluated in fullspace mode (all internal variables are pre-set and given in variables and a vector of constraints is returned)
[out]constraintsis a vector of constraints which are the difference of the given (in the vector variables) and calulated internal network variables.
Returns
returns a vector containing the network output values for the given input

◆ _relu()

template<typename T >
static T melon::FeedForwardNet< T >::_relu ( T x)
inlinestaticprivate

◆ _relu6()

template<typename T >
static T melon::FeedForwardNet< T >::_relu6 ( T x)
inlinestaticprivate

◆ _set_data_object()

template<typename T >
void melon::FeedForwardNet< T >::_set_data_object ( std::shared_ptr< const ModelData > modelData)
overrideprivatevirtual

Sets data object containing model parameters.

Parameters
[in]modelDatais a ModelData object containing the data which defines the model

Implements melon::MelonModel< T >.

◆ _tanh()

template<typename T >
static T melon::FeedForwardNet< T >::_tanh ( T x)
inlinestaticprivate

◆ _tanh_reformulation_1()

template<typename T >
static T melon::FeedForwardNet< T >::_tanh_reformulation_1 ( T x)
inlinestaticprivate

◆ _tanh_reformulation_2()

template<typename T >
static T melon::FeedForwardNet< T >::_tanh_reformulation_2 ( T x)
inlinestaticprivate

◆ _tanh_reformulation_3()

template<typename T >
static T melon::FeedForwardNet< T >::_tanh_reformulation_3 ( T x)
inlinestaticprivate

◆ _tanh_reformulation_4()

template<typename T >
static T melon::FeedForwardNet< T >::_tanh_reformulation_4 ( T x)
inlinestaticprivate

◆ calculate_prediction_full_space()

template<typename T >
std::vector< T > melon::FeedForwardNet< T >::calculate_prediction_full_space ( const std::vector< T > input,
const std::vector< T > internalVariables,
std::vector< T > & constraints )

Calculates the prediction of the feed forward net for a given point in full space mode (values for all internal variables are given and a set of constraints is returned)

Parameters
[in]inputis a vector containing input values for which the network is evaluated
[in]internalVariablesis a vector containing values for the internal variables of the Network
[out]constraintsis a vector containing all intermediate variables
Returns
returns a vector containing the network output values for the given input

◆ calculate_prediction_reduced_space()

template<typename T >
std::vector< T > melon::FeedForwardNet< T >::calculate_prediction_reduced_space ( const std::vector< T > input)

Calculates the prediction of the feed forward net for a given point in reduced space mode (only values network inputs are given)

Parameters
[in]inputis a vector containing input values for which the network is evaluated
Returns
returns a vector containing the network output values for the given input

◆ get_full_space_variables()

template<typename T >
void melon::FeedForwardNet< T >::get_full_space_variables ( unsigned int & variableNumber,
std::vector< std::string > & variableNames,
std::vector< std::pair< double, double > > & variableBounds )

Returns the number and the names of the internal variables of the network.

Parameters
[out]variableNumberis the number of internal network variables
[out]variableNamesis a vector containing the names of all internal network variables
[out]variableBoundsis a vector of pairs containing the bounds of the internal variables

◆ get_number_of_full_space_variables()

template<typename T >
unsigned int melon::FeedForwardNet< T >::get_number_of_full_space_variables ( )

Get the number of internal network variables.

Returns
returns number of internal variables

◆ set_tanh_formulation()

template<typename T >
void melon::FeedForwardNet< T >::set_tanh_formulation ( const TANH_REFORMULATION & reformulation)

Changes the reformulation to be used for tanh evaluations. The reformulations are intended to be used when solvers do not support the tanh function. As reformulations change the tightness of the McCormick envelopes when used with MAiNGO it is recommended to use the standard tanh whenever possible.

Parameters
[in]reformulationenum representing the desired tanh reformulation

Member Data Documentation

◆ _annData

template<typename T >
std::shared_ptr<const AnnData> melon::FeedForwardNet< T >::_annData
private

◆ _inputScaler

template<typename T >
std::unique_ptr<Scaler<T> > melon::FeedForwardNet< T >::_inputScaler
private

Object for scaling input data

◆ _outputScaler

template<typename T >
std::unique_ptr<Scaler<T> > melon::FeedForwardNet< T >::_outputScaler
private

Object for scaling output data

◆ _tanh_formulation

template<typename T >
T(* melon::FeedForwardNet< T >::_tanh_formulation) (T) = &_tanh
private

pointer to the function used as formulation for the tanh


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