13 #ifndef MLPACK_METHODS_ANN_FFN_HPP 14 #define MLPACK_METHODS_ANN_FFN_HPP 34 #include <ensmallen.hpp> 48 typename OutputLayerType = NegativeLogLikelihood<>,
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>
136 double Train(arma::mat predictors,
138 OptimizerType& optimizer,
139 CallbackTypes&&... callbacks);
161 template<
typename OptimizerType = ens::RMSProp,
typename... CallbackTypes>
162 double Train(arma::mat predictors,
164 CallbackTypes&&... callbacks);
177 void Predict(arma::mat predictors, arma::mat& results);
186 template<
typename PredictorsType,
typename ResponsesType>
187 double Evaluate(
const PredictorsType& predictors,
188 const ResponsesType& responses);
196 double Evaluate(
const arma::mat& parameters);
211 double Evaluate(
const arma::mat& parameters,
213 const size_t batchSize,
214 const bool deterministic);
228 double Evaluate(
const arma::mat& parameters,
230 const size_t batchSize);
240 template<
typename GradType>
255 template<
typename GradType>
259 const size_t batchSize);
273 void Gradient(
const arma::mat& parameters,
276 const size_t batchSize);
289 template <
class LayerType,
class... Args>
290 void Add(Args... args) { network.push_back(
new LayerType(args...)); }
297 void Add(LayerTypes<CustomLayers...> layer) { network.push_back(layer); }
300 const std::vector<LayerTypes<CustomLayers...> >&
Model()
const 307 std::vector<LayerTypes<CustomLayers...> >&
Model() {
return network; }
318 const arma::mat&
Responses()
const {
return responses; }
333 template<
typename Archive>
334 void serialize(Archive& ar,
const uint32_t );
346 template<
typename PredictorsType,
typename ResponsesType>
347 void Forward(
const PredictorsType& inputs, ResponsesType& results);
360 template<
typename PredictorsType,
typename ResponsesType>
361 void Forward(
const PredictorsType& inputs ,
362 ResponsesType& results,
378 template<
typename PredictorsType,
379 typename TargetsType,
380 typename GradientsType>
381 double Backward(
const PredictorsType& inputs,
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,
DeleteVisitor executes the destructor of the instantiated object.
Definition: delete_visitor.hpp:27
size_t NumFunctions() const
Return the number of separable functions (the number of predictor points).
Definition: ffn.hpp:310
OutputHeightVisitor exposes the OutputHeight() method of the given module.
Definition: output_height_visitor.hpp:27
Implementation of the Add module class.
Definition: add.hpp:34
const arma::mat & Parameters() const
Return the initial point for the optimization.
Definition: ffn.hpp:313
double EvaluateWithGradient(const arma::mat ¶meters, GradType &gradient)
Evaluate the feedforward network with the given parameters.
Definition: ffn_impl.hpp:345
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
LossVisitor exposes the Loss() method of the given module.
Definition: loss_visitor.hpp:26
FFN & operator=(FFN)
Copy/move assignment operator.
Definition: ffn_impl.hpp:672
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...
Definition: ffn_impl.hpp:77
This visitor is to support copy constructor for neural network module.
Definition: copy_visitor.hpp:26
The core includes that mlpack expects; standard C++ includes and Armadillo.
FFN(OutputLayerType outputLayer=OutputLayerType(), InitializationRuleType initializeRule=InitializationRuleType())
Create the FFN object.
Definition: ffn_impl.hpp:34
WeightSizeVisitor returns the number of weights of the given module.
Definition: weight_size_visitor.hpp:27
void ResetParameters()
Reset the module infomration (weights/parameters).
Definition: ffn_impl.hpp:424
double Backward(const PredictorsType &inputs, const TargetsType &targets, GradientsType &gradients)
Perform the backward pass of the data in real batch mode.
Definition: ffn_impl.hpp:200
const arma::mat & Responses() const
Get the matrix of responses to the input data points.
Definition: ffn.hpp:318
ResetVisitor executes the Reset() function.
Definition: reset_visitor.hpp:26
OutputParameterVisitor exposes the output parameter of the given module.
Definition: output_parameter_visitor.hpp:27
void serialize(Archive &ar, const uint32_t)
Serialize the model.
Definition: ffn_impl.hpp:557
~FFN()
Destructor to release allocated memory.
Definition: ffn_impl.hpp:49
arma::mat & Predictors()
Modify the matrix of data points (predictors).
Definition: ffn.hpp:325
arma::mat & Parameters()
Modify the initial point for the optimization.
Definition: ffn.hpp:315
arma::mat & Responses()
Modify the matrix of responses to the input data points.
Definition: ffn.hpp:320
void Forward(const PredictorsType &inputs, ResponsesType &results)
Perform the forward pass of the data in real batch mode.
Definition: ffn_impl.hpp:163
void Shuffle()
Shuffle the order of function visitation.
Definition: ffn_impl.hpp:416
DeltaVisitor exposes the delta parameter of the given module.
Definition: delta_visitor.hpp:27
The implementation of the standard GAN module.
Definition: gan.hpp:63
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 ...
Definition: ffn_impl.hpp:405
Implementation of a standard feed forward network.
Definition: ffn.hpp:52
std::vector< LayerTypes< CustomLayers... > > & Model()
Modify the network model.
Definition: ffn.hpp:307
OutputWidthVisitor exposes the OutputWidth() method of the given module.
Definition: output_width_visitor.hpp:27
const arma::mat & Predictors() const
Get the matrix of data points (predictors).
Definition: ffn.hpp:323
void Predict(arma::mat predictors, arma::mat &results)
Predict the responses to a given set of predictors.
Definition: ffn_impl.hpp:227
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.
Definition: ffn_impl.hpp:108
const std::vector< LayerTypes< CustomLayers... > > & Model() const
Get the network model.
Definition: ffn.hpp:300
double Evaluate(const PredictorsType &predictors, const ResponsesType &responses)
Evaluate the feedforward network with the given predictors and responses.
Definition: ffn_impl.hpp:263