![]() |
MeLOn
|
This class represents a feed foward artificial network to be used in the MAiNGO solver. More...
#include <ffNet.h>
Public Member Functions | |
FeedForwardNet () | |
Constructor for creating object with no model loaded. More... | |
FeedForwardNet (std::string modelName, MODEL_FILE_TYPE fileType) | |
Constructor for creating object from file with the modelName relative to the current working directory. More... | |
FeedForwardNet (std::string modelPath, std::string modelName, MODEL_FILE_TYPE fileType) | |
Constructor for creating object from file with the modelName being relative to modelPath. More... | |
FeedForwardNet (std::shared_ptr< AnnData > modelData) | |
Constructor for creating object from existing AnnData object. More... | |
~FeedForwardNet ()=default | |
Default Destructor. More... | |
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) More... | |
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) More... | |
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. More... | |
unsigned int | get_number_of_full_space_variables () |
Get the number of internal network variables. More... | |
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. More... | |
![]() | |
virtual | ~MelonModel ()=default |
Default destructor. More... | |
void | load_model (std::string modelName, MODEL_FILE_TYPE fileType) |
Loads new model from file. More... | |
void | load_model (std::string modelPath, std::string modelName, MODEL_FILE_TYPE fileType) |
Loads new model from file. More... | |
void | load_model (std::shared_ptr< const ModelData > modelData) |
Loads new model from file. More... | |
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. More... | |
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. More... | |
void | _set_data_object (std::shared_ptr< const ModelData > modelData) override |
Sets data object containing model parameters. More... | |
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 | |
![]() | |
MelonModel (std::shared_ptr< ModelParserFactory > parserFactory) | |
Constructor. More... | |
template<typename RandomAccessIterator > | |
void | _set_constraints (std::vector< T > &constraints, std::vector< T > &constraintEvaluation, RandomAccessIterator &constraintValue) |
Sets constraints required for fullspace opimization. More... | |
template<typename RandomAccessIterator > | |
void | _set_constraints (std::vector< T > &constraints, T &constraintEvaluation, RandomAccessIterator &constraintValue) |
Sets constraints required for fullspace opimization. More... | |
![]() | |
bool | _modelLoaded { false } |
std::shared_ptr< ModelParserFactory > | _parserFactory |
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.
|
inline |
Constructor for creating object with no model loaded.
|
inline |
Constructor for creating object from file with the modelName relative to the current working directory.
[in] | modelName | is the name of the network |
[in] | fileType | specifies the data format of the network file |
|
inline |
Constructor for creating object from file with the modelName being relative to modelPath.
[in] | modelPath | is the path to the directory in which the network is located |
[in] | modelName | is the name of the network |
[in] | fileType | specifies the data format of the network file |
|
inline |
|
default |
Default Destructor.
|
private |
Calculates the activations for a layer given its inputs.
[in] | v | is a vector containing the summed inputs for each neuron in the layer |
[in] | activationFunction | is an enum that determines which activation function should be applied to the layer |
|
private |
Calculates the prediction of the feed forward net for a given point.
[in] | input | is a vector containing input variables based on which the network is evaluated |
[in] | internalVariables | is a vector containing values for the internal variables of the Network |
[in] | fullSpace | indicates 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] | constraints | is a vector of constraints which are the difference of the given (in the vector variables) and calulated internal network variables. |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
overrideprivatevirtual |
Sets data object containing model parameters.
[in] | modelData | is a ModelData object containing the data which defines the model |
Implements melon::MelonModel< T >.
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inlinestaticprivate |
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)
[in] | input | is a vector containing input values for which the network is evaluated |
[in] | internalVariables | is a vector containing values for the internal variables of the Network |
[out] | constraints | is a vector containing all intermediate variables |
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)
[in] | input | is a vector containing input values for which the network is evaluated |
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.
[out] | variableNumber | is the number of internal network variables |
[out] | variableNames | is a vector containing the names of all internal network variables |
[out] | variableBounds | is a vector of pairs containing the bounds of the internal variables |
unsigned int melon::FeedForwardNet< T >::get_number_of_full_space_variables |
Get the number of internal network variables.
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.
[in] | reformulation | enum representing the desired tanh reformulation |
|
private |
|
private |
Object for scaling input data
|
private |
Object for scaling output data
|
private |
pointer to the function used as formulation for the tanh