13 #ifndef MLPACK_METHODS_ANN_FFN_HPP 14 #define MLPACK_METHODS_ANN_FFN_HPP 46 typename OutputLayerType = NegativeLogLikelihood<>,
47 typename InitializationRuleType = RandomInitialization,
48 typename... CustomLayers
69 FFN(OutputLayerType outputLayer = OutputLayerType(),
70 InitializationRuleType initializeRule = InitializationRuleType());
100 template<
typename OptimizerType>
101 void Train(arma::mat predictors,
103 OptimizerType& optimizer);
121 template<
typename OptimizerType = mlpack::optimization::RMSProp>
122 void Train(arma::mat predictors, arma::mat responses);
135 void Predict(arma::mat predictors, arma::mat& results);
145 double Evaluate(
const arma::mat& parameters);
160 double Evaluate(
const arma::mat& parameters,
162 const size_t batchSize,
163 const bool deterministic);
177 double Evaluate(
const arma::mat& parameters,
179 const size_t batchSize);
188 template<
typename GradType>
205 template<
typename GradType>
209 const size_t batchSize,
210 const bool deterministic);
225 template<
typename GradType>
229 const size_t batchSize);
243 void Gradient(
const arma::mat& parameters,
246 const size_t batchSize);
259 template <
class LayerType,
class... Args>
260 void Add(Args... args) { network.push_back(
new LayerType(args...)); }
278 const arma::mat&
Responses()
const {
return responses; }
293 template<
typename Archive>
294 void serialize(Archive& ar,
const unsigned int );
306 void Forward(arma::mat inputs, arma::mat& results);
335 double Backward(arma::mat targets, arma::mat& gradients);
345 void Forward(arma::mat&& input);
354 void ResetData(arma::mat predictors, arma::mat responses);
372 void ResetDeterministic();
377 void ResetGradients(arma::mat& gradient);
384 void Swap(
FFN& network);
387 OutputLayerType outputLayer;
391 InitializationRuleType initializeRule;
403 std::vector<
LayerTypes<CustomLayers...> > network;
406 arma::mat predictors;
421 arma::mat currentInput;
451 arma::mat inputParameter;
454 arma::mat outputParameter;
469 namespace serialization {
471 template<
typename OutputLayerType,
472 typename InitializationRuleType,
475 mlpack::ann::FFN<OutputLayerType, InitializationRuleType, CustomLayer...>>
477 BOOST_STATIC_CONSTANT(
int, value = 1);
484 #include "ffn_impl.hpp" DeleteVisitor executes the destructor of the instantiated object.
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 ...
OutputWidthVisitor exposes the OutputHeight() method of the given module.
arma::mat & Responses()
Modify the matrix of responses to the input data points.
void serialize(Archive &ar, const unsigned int)
Serialize the model.
size_t NumFunctions() const
Return the number of separable functions (the number of predictor points).
boost::variant< Add< arma::mat, arma::mat > *, AddMerge< 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< RectifierFunction, arma::mat, arma::mat > *, BatchNorm< arma::mat, arma::mat > *, BilinearInterpolation< arma::mat, arma::mat > *, Concat< 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 > *, TransposedConvolution< NaiveConvolution< ValidConvolution >, NaiveConvolution< FullConvolution >, NaiveConvolution< ValidConvolution >, arma::mat, arma::mat > *, DropConnect< arma::mat, arma::mat > *, Dropout< arma::mat, arma::mat > *, AlphaDropout< arma::mat, arma::mat > *, ELU< arma::mat, arma::mat > *, FlexibleReLU< arma::mat, arma::mat > *, Glimpse< 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 > *, LinearNoBias< arma::mat, arma::mat > *, LogSoftMax< arma::mat, arma::mat > *, Lookup< arma::mat, arma::mat > *, LSTM< arma::mat, arma::mat > *, GRU< arma::mat, arma::mat > *, FastLSTM< arma::mat, arma::mat > *, MaxPooling< arma::mat, arma::mat > *, MeanPooling< arma::mat, arma::mat > *, MultiplyConstant< arma::mat, arma::mat > *, MultiplyMerge< arma::mat, arma::mat > *, NegativeLogLikelihood< arma::mat, arma::mat > *, PReLU< arma::mat, arma::mat > *, Recurrent< arma::mat, arma::mat > *, RecurrentAttention< arma::mat, arma::mat > *, ReinforceNormal< arma::mat, arma::mat > *, Select< arma::mat, arma::mat > *, Sequential< arma::mat, arma::mat > *, VRClassReward< arma::mat, arma::mat > *, CustomLayers *... > LayerTypes
double Evaluate(const arma::mat ¶meters)
Evaluate the feedforward network with the given parameters.
void Predict(arma::mat predictors, arma::mat &results)
Predict the responses to a given set of predictors.
BaseLayer< ActivationFunction, InputDataType, OutputDataType > CustomLayer
Standard Sigmoid layer.
Set the serialization version of the FFN class.
This visitor is to support copy constructor for neural network module.
const arma::mat & Predictors() const
Get the matrix of data points (predictors).
The core includes that mlpack expects; standard C++ includes and Armadillo.
WeightSizeVisitor returns the number of weights of the given module.
void Forward(arma::mat inputs, arma::mat &results)
Perform the forward pass of the data in real batch mode.
void Train(arma::mat predictors, arma::mat responses, OptimizerType &optimizer)
Train the feedforward network on the given input data using the given optimizer.
FFN & operator=(FFN)
Copy/move assignment operator.
void Shuffle()
Shuffle the order of function visitation.
~FFN()
Destructor to release allocated memory.
const arma::mat & Responses() const
Get the matrix of responses to the input data points.
ResetVisitor executes the Reset() function.
double EvaluateWithGradient(const arma::mat ¶meters, GradType &gradient)
Evaluate the feedforward network with the given parameters.
OutputParameterVisitor exposes the output parameter of the given module.
void Add(LayerTypes< CustomLayers... > layer)
arma::mat & Parameters()
Modify the initial point for the optimization.
void ResetParameters()
Reset the module infomration (weights/parameters).
arma::mat & Predictors()
Modify the matrix of data points (predictors).
const arma::mat & Parameters() const
Return the initial point for the optimization.
DeltaVisitor exposes the delta parameter of the given module.
Implementation of a standard feed forward network.
OutputWidthVisitor exposes the OutputWidth() method of the given module.
double Backward(arma::mat targets, arma::mat &gradients)
Perform the backward pass of the data in real batch mode.
FFN(OutputLayerType outputLayer=OutputLayerType(), InitializationRuleType initializeRule=InitializationRuleType())
Create the FFN object.