Go to the documentation of this file.
13 #ifndef MLPACK_METHODS_ANN_FFN_HPP
14 #define MLPACK_METHODS_ANN_FFN_HPP
34 #include <ensmallen.hpp>
49 typename InitializationRuleType = RandomInitialization,
50 typename... CustomLayers
71 FFN(OutputLayerType outputLayer = OutputLayerType(),
72 InitializationRuleType initializeRule = InitializationRuleType());
95 template<
typename OptimizerType>
96 typename std::enable_if<
97 HasMaxIterations<OptimizerType,
size_t&(OptimizerType::*)()>
109 template<
typename OptimizerType>
110 typename std::enable_if<
111 !HasMaxIterations<OptimizerType,
size_t&(OptimizerType::*)()>
135 template<
typename OptimizerType,
typename... CallbackTypes>
138 OptimizerType& optimizer,
139 CallbackTypes&&... callbacks);
161 template<
typename OptimizerType = ens::RMSProp,
typename... CallbackTypes>
164 CallbackTypes&&... callbacks);
177 void Predict(arma::mat predictors, arma::mat& results);
186 template<
typename PredictorsType,
typename ResponsesType>
188 const ResponsesType& responses);
213 const size_t batchSize,
214 const bool deterministic);
230 const size_t batchSize);
240 template<
typename GradType>
255 template<
typename GradType>
259 const size_t batchSize);
276 const size_t batchSize);
289 template <
class LayerType,
class... Args>
290 void Add(Args... args) { network.push_back(
new LayerType(args...)); }
318 const arma::mat&
Responses()
const {
return responses; }
333 template<
typename Archive>
346 template<
typename PredictorsType,
typename ResponsesType>
347 void Forward(
const PredictorsType& inputs, ResponsesType& results);
360 template<
typename PredictorsType,
typename ResponsesType>
362 ResponsesType& results,
378 template<
typename PredictorsType,
379 typename TargetsType,
380 typename GradientsType>
382 const TargetsType& targets,
383 GradientsType& gradients);
393 template<
typename InputType>
394 void Forward(
const InputType& input);
403 void ResetData(arma::mat predictors, arma::mat responses);
415 template<
typename InputType>
416 void Gradient(
const InputType& input);
422 void ResetDeterministic();
427 void ResetGradients(arma::mat& gradient);
434 void Swap(
FFN& network);
437 OutputLayerType outputLayer;
441 InitializationRuleType initializeRule;
453 std::vector<
LayerTypes<CustomLayers...> > network;
456 arma::mat predictors;
501 arma::mat inputParameter;
504 arma::mat outputParameter;
515 typename InitializerType,
528 namespace serialization {
530 template<
typename OutputLayerType,
531 typename InitializationRuleType,
534 mlpack::ann::FFN<OutputLayerType, InitializationRuleType, CustomLayer...>>
543 #include "ffn_impl.hpp"
This visitor is to support copy constructor for neural network module.
LossVisitor exposes the Loss() method of the given module.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double EvaluateWithGradient(const arma::mat ¶meters, const size_t begin, GradType &gradient, const size_t batchSize)
Evaluate the feedforward network with the given parameters, but using only a number of data points.
double Evaluate(const arma::mat ¶meters, const size_t begin, const size_t batchSize)
Evaluate the feedforward network with the given parameters, but using only a number of data points.
const arma::mat & Parameters() const
Return the initial point for the optimization.
FFN(FFN &&)
Move constructor.
void ResetParameters()
Reset the module infomration (weights/parameters).
arma::mat & Parameters()
Modify the initial point for the optimization.
std::vector< LayerTypes< CustomLayers... > > & Model()
Modify the network model.
double Train(arma::mat predictors, arma::mat responses, OptimizerType &optimizer, CallbackTypes &&... callbacks)
Train the feedforward network on the given input data using the given optimizer.
void serialize(Archive &ar, const unsigned int)
Serialize the model.
Set the serialization version of the adaboost class.
const arma::mat & Predictors() const
Get the matrix of data points (predictors).
void Forward(const PredictorsType &inputs, ResponsesType &results, const size_t begin, const size_t end)
Perform a partial forward pass of the data.
void Predict(arma::mat predictors, arma::mat &results)
Predict the responses to a given set of predictors.
OutputHeightVisitor exposes the OutputHeight() method of the given module.
OutputWidthVisitor exposes the OutputWidth() method of the given module.
Linear algebra utility functions, generally performed on matrices or vectors.
void Shuffle()
Shuffle the order of function visitation.
BaseLayer< ActivationFunction, InputDataType, OutputDataType > CustomLayer
Standard Sigmoid layer.
double Evaluate(const arma::mat ¶meters)
Evaluate the feedforward network with the given parameters.
DeleteVisitor executes the destructor of the instantiated object.
double EvaluateWithGradient(const arma::mat ¶meters, GradType &gradient)
Evaluate the feedforward network with the given parameters.
double Backward(const PredictorsType &inputs, const TargetsType &targets, GradientsType &gradients)
Perform the backward pass of the data in real batch mode.
void Add(LayerTypes< CustomLayers... > layer)
double Train(arma::mat predictors, arma::mat responses, CallbackTypes &&... callbacks)
Train the feedforward network on the given input data.
ResetVisitor executes the Reset() function.
void Forward(const PredictorsType &inputs, ResponsesType &results)
Perform the forward pass of the data in real batch mode.
void Gradient(const arma::mat ¶meters, const size_t begin, arma::mat &gradient, const size_t batchSize)
Evaluate the gradient of the feedforward network with the given parameters, and with respect to only ...
boost::variant< AdaptiveMaxPooling< arma::mat, arma::mat > *, AdaptiveMeanPooling< arma::mat, arma::mat > *, Add< arma::mat, arma::mat > *, AddMerge< arma::mat, arma::mat > *, AlphaDropout< arma::mat, arma::mat > *, AtrousConvolution< NaiveConvolution< ValidConvolution >, NaiveConvolution< FullConvolution >, NaiveConvolution< ValidConvolution >, arma::mat, arma::mat > *, BaseLayer< LogisticFunction, arma::mat, arma::mat > *, BaseLayer< IdentityFunction, arma::mat, arma::mat > *, BaseLayer< TanhFunction, arma::mat, arma::mat > *, BaseLayer< SoftplusFunction, arma::mat, arma::mat > *, BaseLayer< RectifierFunction, arma::mat, arma::mat > *, BatchNorm< arma::mat, arma::mat > *, BilinearInterpolation< arma::mat, arma::mat > *, CELU< arma::mat, arma::mat > *, Concat< arma::mat, arma::mat > *, Concatenate< arma::mat, arma::mat > *, ConcatPerformance< NegativeLogLikelihood< arma::mat, arma::mat >, arma::mat, arma::mat > *, Constant< arma::mat, arma::mat > *, Convolution< NaiveConvolution< ValidConvolution >, NaiveConvolution< FullConvolution >, NaiveConvolution< ValidConvolution >, arma::mat, arma::mat > *, CReLU< arma::mat, arma::mat > *, DropConnect< arma::mat, arma::mat > *, Dropout< arma::mat, arma::mat > *, ELU< arma::mat, arma::mat > *, FastLSTM< arma::mat, arma::mat > *, FlexibleReLU< arma::mat, arma::mat > *, GRU< arma::mat, arma::mat > *, HardTanH< arma::mat, arma::mat > *, Join< arma::mat, arma::mat > *, LayerNorm< arma::mat, arma::mat > *, LeakyReLU< arma::mat, arma::mat > *, Linear< arma::mat, arma::mat, NoRegularizer > *, LinearNoBias< arma::mat, arma::mat, NoRegularizer > *, LogSoftMax< arma::mat, arma::mat > *, Lookup< arma::mat, arma::mat > *, LSTM< arma::mat, arma::mat > *, MaxPooling< arma::mat, arma::mat > *, MeanPooling< arma::mat, arma::mat > *, MiniBatchDiscrimination< arma::mat, arma::mat > *, MultiplyConstant< arma::mat, arma::mat > *, MultiplyMerge< arma::mat, arma::mat > *, NegativeLogLikelihood< arma::mat, arma::mat > *, NoisyLinear< arma::mat, arma::mat > *, Padding< arma::mat, arma::mat > *, PReLU< arma::mat, arma::mat > *, Softmax< arma::mat, arma::mat > *, SpatialDropout< arma::mat, arma::mat > *, TransposedConvolution< NaiveConvolution< ValidConvolution >, NaiveConvolution< ValidConvolution >, NaiveConvolution< ValidConvolution >, arma::mat, arma::mat > *, WeightNorm< arma::mat, arma::mat > *, MoreTypes, CustomLayers *... > LayerTypes
The implementation of the standard GAN module.
OutputParameterVisitor exposes the output parameter of the given module.
DeltaVisitor exposes the delta parameter of the given module.
FFN(const FFN &)
Copy constructor.
const std::vector< LayerTypes< CustomLayers... > > & Model() const
Get the network model.
double Evaluate(const PredictorsType &predictors, const ResponsesType &responses)
Evaluate the feedforward network with the given predictors and responses.
BOOST_STATIC_CONSTANT(int, value=2)
~FFN()
Destructor to release allocated memory.
double Evaluate(const arma::mat ¶meters, const size_t begin, const size_t batchSize, const bool deterministic)
Evaluate the feedforward network with the given parameters, but using only a number of data points.
arma::mat & Predictors()
Modify the matrix of data points (predictors).
FFN(OutputLayerType outputLayer=OutputLayerType(), InitializationRuleType initializeRule=InitializationRuleType())
Create the FFN object.
const arma::mat & Responses() const
Get the matrix of responses to the input data points.
size_t NumFunctions() const
Return the number of separable functions (the number of predictor points).
WeightSizeVisitor returns the number of weights of the given module.
std::enable_if< HasMaxIterations< OptimizerType, size_t &(OptimizerType::*)()>::value, void >::type WarnMessageMaxIterations(OptimizerType &optimizer, size_t samples) const
Check if the optimizer has MaxIterations() parameter, if it does then check if it's value is less tha...
Implementation of a standard feed forward network.
FFN & operator=(FFN)
Copy/move assignment operator.
std::enable_if< !HasMaxIterations< OptimizerType, size_t &(OptimizerType::*)()>::value, void >::type WarnMessageMaxIterations(OptimizerType &optimizer, size_t samples) const
Check if the optimizer has MaxIterations() parameter, if it doesn't then simply return from the funct...
arma::mat & Responses()
Modify the matrix of responses to the input data points.