diff --git a/HISTORY.md b/HISTORY.md index 4508b6cb0f..ba59702d4f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -27,8 +27,6 @@ * Fix `no_intercept` and probability computation for linear SVM bindings (#2419). - * Add copy constructor in all layers of ANN (#2325). - ### mlpack 3.3.1 ###### 2020-04-29 * Minor Julia and Python documentation fixes (#2373). diff --git a/src/mlpack/methods/ann/brnn.hpp b/src/mlpack/methods/ann/brnn.hpp index 64c8a109d0..681a1c8431 100644 --- a/src/mlpack/methods/ann/brnn.hpp +++ b/src/mlpack/methods/ann/brnn.hpp @@ -79,14 +79,6 @@ class BRNN MergeOutputType* mergeOutput = new MergeOutputType(), InitializationRuleType initializeRule = InitializationRuleType()); - /** - * Copy the BRNN object. - * - * Warning: Copying BRNN is a memory-intensive task: two RNNs need to - * be copied. - */ - BRNN(const BRNN&); - ~BRNN(); /** @@ -401,7 +393,7 @@ class BRNN //! Locally-stored delete visitor. DeleteVisitor deleteVisitor; - //! Locally-stored copy visitor. + //! Locally-stored delete visitor. CopyVisitor copyVisitor; //! The current evaluation mode (training or testing). diff --git a/src/mlpack/methods/ann/brnn_impl.hpp b/src/mlpack/methods/ann/brnn_impl.hpp index a5088d313a..b1a6bf3f17 100644 --- a/src/mlpack/methods/ann/brnn_impl.hpp +++ b/src/mlpack/methods/ann/brnn_impl.hpp @@ -60,57 +60,6 @@ BRNN -BRNN::BRNN( - const BRNN& network) : - rho(network.rho), - outputLayer(network.outputLayer), - initializeRule(network.initializeRule), - inputSize(network.inputSize), - outputSize(network.outputSize), - targetSize(network.targetSize), - reset(network.reset), - single(network.single), - numFunctions(network.numFunctions), - deterministic(network.deterministic), - parameter(network.parameter), - predictors(network.predictors), - responses(network.responses), - forwardRNN(network.rho, network.single, network.outputLayer, - network.initializeRule), - backwardRNN(network.rho, network.single, network.outputLayer, - network.initializeRule) -{ - mergeLayer = boost::apply_visitor(copyVisitor, network.mergeLayer); - mergeOutput = boost::apply_visitor(copyVisitor, network.mergeOutput); - - // Build new layers according to source network. - for (size_t i = 0; i < network.forwardRNN.network.size(); ++i) - { - this->forwardRNN.network.push_back(boost::apply_visitor(copyVisitor, - network.forwardRNN.network[i])); - } - - // Build new layers according to source network. - for (size_t i = 0; i < network.backwardRNN.network.size(); ++i) - { - this->backwardRNN.network.push_back(boost::apply_visitor(copyVisitor, - network.backwardRNN.network[i])); - } - - boost::apply_visitor(AddVisitor( - forwardRNN.network.back()), mergeLayer); - boost::apply_visitor(AddVisitor( - backwardRNN.network.back()), mergeLayer); - boost::apply_visitor(RunSetVisitor(false), mergeLayer); - - forwardRNN.Parameters() = network.forwardRNN.Parameters(); - backwardRNN.Parameters() = network.backwardRNN.Parameters(); -} - template diff --git a/src/mlpack/methods/ann/ffn.hpp b/src/mlpack/methods/ann/ffn.hpp index b31ccff054..2c1f6828ea 100644 --- a/src/mlpack/methods/ann/ffn.hpp +++ b/src/mlpack/methods/ann/ffn.hpp @@ -71,12 +71,7 @@ class FFN FFN(OutputLayerType outputLayer = OutputLayerType(), InitializationRuleType initializeRule = InitializationRuleType()); - /** - * Copy the FFN object. - * - * Warning: Copying FFN is a memory-intensive task: multiple layers as well - * as parameters needed to be copied. - */ + //! Copy constructor. FFN(const FFN&); //! Move constructor. diff --git a/src/mlpack/methods/ann/gan/gan.hpp b/src/mlpack/methods/ann/gan/gan.hpp index 040c5bc80b..1febe6577e 100644 --- a/src/mlpack/methods/ann/gan/gan.hpp +++ b/src/mlpack/methods/ann/gan/gan.hpp @@ -92,12 +92,7 @@ class GAN const double clippingParameter = 0.01, const double lambda = 10.0); - /** - * Copy the GAN object. - * - * Warning: Copying a GAN is a memory-intensive task: the Generator and Discriminator - * networks will be copied. - */ + //! Copy constructor. GAN(const GAN&); //! Move constructor. diff --git a/src/mlpack/methods/ann/layer/add_merge.hpp b/src/mlpack/methods/ann/layer/add_merge.hpp index d1367b2a11..c6adb819f0 100644 --- a/src/mlpack/methods/ann/layer/add_merge.hpp +++ b/src/mlpack/methods/ann/layer/add_merge.hpp @@ -17,7 +17,6 @@ #include "../visitor/delete_visitor.hpp" #include "../visitor/delta_visitor.hpp" -#include "../visitor/copy_visitor.hpp" #include "../visitor/output_parameter_visitor.hpp" #include "layer_types.hpp" @@ -60,9 +59,6 @@ class AddMerge */ AddMerge(const bool model, const bool run, const bool ownsLayers); - //! Copy constructor. - AddMerge(const AddMerge&); - //! Destructor to release allocated memory. ~AddMerge(); diff --git a/src/mlpack/methods/ann/layer/add_merge_impl.hpp b/src/mlpack/methods/ann/layer/add_merge_impl.hpp index 8a07d0a3bb..c6d799146f 100644 --- a/src/mlpack/methods/ann/layer/add_merge_impl.hpp +++ b/src/mlpack/methods/ann/layer/add_merge_impl.hpp @@ -41,17 +41,6 @@ AddMerge::AddMerge( // Nothing to do here. } -template -AddMerge::AddMerge( - const AddMerge& layer) : - model(layer.model), - run(layer.run), - ownsLayers(layer.ownsLayers) -{ - // Nothing to do here. -} - template AddMerge::~AddMerge() diff --git a/src/mlpack/methods/ann/layer/atrous_convolution.hpp b/src/mlpack/methods/ann/layer/atrous_convolution.hpp index 0f0c35d09a..3a84c0fa7f 100644 --- a/src/mlpack/methods/ann/layer/atrous_convolution.hpp +++ b/src/mlpack/methods/ann/layer/atrous_convolution.hpp @@ -125,9 +125,6 @@ class AtrousConvolution const size_t dilationHeight = 1, const std::string& paddingType = "None"); - //! Copy constructor. - AtrousConvolution(const AtrousConvolution&); - /* * Set the weight and bias term. */ diff --git a/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp b/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp index bd9abbd341..0d2f240cdb 100644 --- a/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp +++ b/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp @@ -37,39 +37,6 @@ AtrousConvolution< // Nothing to do here. } -template< - typename ForwardConvolutionRule, - typename BackwardConvolutionRule, - typename GradientConvolutionRule, - typename InputDataType, - typename OutputDataType -> -AtrousConvolution< - ForwardConvolutionRule, - BackwardConvolutionRule, - GradientConvolutionRule, - InputDataType, - OutputDataType ->::AtrousConvolution( - const AtrousConvolution& layer) : - inSize(layer.inSize), - outSize(layer.outSize), - kernelWidth(layer.kernelWidth), - kernelHeight(layer.kernelHeight), - weights(layer.weights), - strideWidth(layer.strideWidth), - strideHeight(layer.strideHeight), - inputWidth(layer.inputWidth), - inputHeight(layer.inputHeight), - outputWidth(layer.outputWidth), - outputHeight(layer.outputHeight), - dilationWidth(layer.dilationWidth), - dilationHeight(layer.dilationHeight), - padding(layer.padding) -{ - Reset(); -} - template< typename ForwardConvolutionRule, typename BackwardConvolutionRule, diff --git a/src/mlpack/methods/ann/layer/batch_norm.hpp b/src/mlpack/methods/ann/layer/batch_norm.hpp index 1bb98c40cf..aef6a205c7 100644 --- a/src/mlpack/methods/ann/layer/batch_norm.hpp +++ b/src/mlpack/methods/ann/layer/batch_norm.hpp @@ -67,9 +67,6 @@ class BatchNorm */ BatchNorm(const size_t size, const double eps = 1e-8); - //! Copy constructor. - BatchNorm(const BatchNorm&); - /** * Reset the layer parameters */ diff --git a/src/mlpack/methods/ann/layer/batch_norm_impl.hpp b/src/mlpack/methods/ann/layer/batch_norm_impl.hpp index 465eb9fbbe..cbb78a26a4 100644 --- a/src/mlpack/methods/ann/layer/batch_norm_impl.hpp +++ b/src/mlpack/methods/ann/layer/batch_norm_impl.hpp @@ -30,22 +30,6 @@ BatchNorm::BatchNorm() : { // Nothing to do here. } - -template -BatchNorm::BatchNorm( - const BatchNorm& layer) : - size(layer.size), - eps(layer.eps), - gamma(layer.gamma), - beta(layer.beta), - weights(layer.weights), - count(layer.count), - runningMean(layer.runningMean), - runningVariance(layer.runningVariance) -{ - Reset(); -} - template BatchNorm::BatchNorm( const size_t size, const double eps) : diff --git a/src/mlpack/methods/ann/layer/bilinear_interpolation.hpp b/src/mlpack/methods/ann/layer/bilinear_interpolation.hpp index 73332cf90f..fc99937eb2 100644 --- a/src/mlpack/methods/ann/layer/bilinear_interpolation.hpp +++ b/src/mlpack/methods/ann/layer/bilinear_interpolation.hpp @@ -57,9 +57,6 @@ class BilinearInterpolation const size_t outColSize, const size_t depth); - //! Copy constructor. - BilinearInterpolation(const BilinearInterpolation&); - /** * Forward pass through the layer. The layer interpolates * the matrix using the given Bilinear Interpolation method. diff --git a/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp b/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp index e5220e8e59..5c958e6156 100644 --- a/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp +++ b/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp @@ -51,19 +51,6 @@ BilinearInterpolation( // Nothing to do here. } -template -BilinearInterpolation:: -BilinearInterpolation(const BilinearInterpolation& layer): - inRowSize(layer.inRowSize), - inColSize(layer.inColSize), - outRowSize(layer.outRowSize), - outColSize(layer.outColSize), - depth(layer.depth), - batchSize(layer.batchSize) -{ - // Nothing to do here. -} - template template void BilinearInterpolation::Forward( diff --git a/src/mlpack/methods/ann/layer/concat.hpp b/src/mlpack/methods/ann/layer/concat.hpp index 42723769c1..30bfe4f3b5 100644 --- a/src/mlpack/methods/ann/layer/concat.hpp +++ b/src/mlpack/methods/ann/layer/concat.hpp @@ -67,9 +67,6 @@ class Concat const bool model = false, const bool run = true); - //! Copy constructor. - Concat(const Concat&); - /** * Destroy the layers held by the model. */ diff --git a/src/mlpack/methods/ann/layer/concat_impl.hpp b/src/mlpack/methods/ann/layer/concat_impl.hpp index aa4a46e5a1..a75fea8697 100644 --- a/src/mlpack/methods/ann/layer/concat_impl.hpp +++ b/src/mlpack/methods/ann/layer/concat_impl.hpp @@ -36,53 +36,6 @@ Concat::Concat( parameters.set_size(0, 0); } -template -Concat::Concat( - const Concat& layer) : - inputSize(layer.inputSize), - axis(layer.axis), - useAxis(layer.useAxis), - model(layer.model), - run(layer.run) -{ - parameters.set_size(0, 0); - - // Parameters to help calculate the number of channels. - size_t oldColSize = 1, newColSize = 1; - // Axis is specified and useAxis is true. - if (useAxis) - { - // Axis is specified without input dimension. - // Throw an error. - if (inputSize.n_elem > 0) - { - // Calculate rowSize, newColSize based on the axis - // of concatenation. Finally concat along cols and - // reshape to original format i.e. (input, batch_size). - size_t i = std::min(axis + 1, (size_t) inputSize.n_elem); - for (; i < inputSize.n_elem; ++i) - { - newColSize *= inputSize[i]; - } - } - else - { - throw std::logic_error("Input dimensions not specified."); - } - } - else - { - channels = 1; - } - if (newColSize <= 0) - { - throw std::logic_error("Col size is zero."); - } - channels = newColSize / oldColSize; - inputSize.clear(); -} - template Concat::Concat( diff --git a/src/mlpack/methods/ann/layer/concat_performance.hpp b/src/mlpack/methods/ann/layer/concat_performance.hpp index 8c8b6d262e..c4f6bffed7 100644 --- a/src/mlpack/methods/ann/layer/concat_performance.hpp +++ b/src/mlpack/methods/ann/layer/concat_performance.hpp @@ -48,9 +48,6 @@ class ConcatPerformance ConcatPerformance(const size_t inSize = 0, OutputLayerType&& outputLayer = OutputLayerType()); - //! Copy constructor. - ConcatPerformance(const ConcatPerformance&); - /* * Computes the Negative log likelihood. * diff --git a/src/mlpack/methods/ann/layer/concat_performance_impl.hpp b/src/mlpack/methods/ann/layer/concat_performance_impl.hpp index 5a2d7e1804..65a37ded79 100644 --- a/src/mlpack/methods/ann/layer/concat_performance_impl.hpp +++ b/src/mlpack/methods/ann/layer/concat_performance_impl.hpp @@ -34,22 +34,6 @@ ConcatPerformance< // Nothing to do here. } -template< - typename OutputLayerType, - typename InputDataType, - typename OutputDataType -> -ConcatPerformance< - OutputLayerType, - InputDataType, - OutputDataType ->::ConcatPerformance(const ConcatPerformance& layer) : - inSize(layer.inSize), - outputLayer(layer.outputLayer) -{ - // Nothing to do here. -} - template< typename OutputLayerType, typename InputDataType, diff --git a/src/mlpack/methods/ann/layer/concatenate.hpp b/src/mlpack/methods/ann/layer/concatenate.hpp index fed0226209..ba8d6139ed 100644 --- a/src/mlpack/methods/ann/layer/concatenate.hpp +++ b/src/mlpack/methods/ann/layer/concatenate.hpp @@ -41,9 +41,6 @@ class Concatenate */ Concatenate(); - //! Copy constructor. - Concatenate(const Concatenate&); - /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/concatenate_impl.hpp b/src/mlpack/methods/ann/layer/concatenate_impl.hpp index adb5c393fb..20c7ba6d15 100644 --- a/src/mlpack/methods/ann/layer/concatenate_impl.hpp +++ b/src/mlpack/methods/ann/layer/concatenate_impl.hpp @@ -25,15 +25,6 @@ Concatenate::Concatenate() // Nothing to do here. } -template -Concatenate::Concatenate( - const Concatenate& layer) : - inRows(layer.inRows), - concat(layer.concat) -{ - // Nothing to do here. -} - template template void Concatenate::Forward( diff --git a/src/mlpack/methods/ann/layer/constant.hpp b/src/mlpack/methods/ann/layer/constant.hpp index 25a22f0e50..6e198d02f8 100644 --- a/src/mlpack/methods/ann/layer/constant.hpp +++ b/src/mlpack/methods/ann/layer/constant.hpp @@ -43,9 +43,6 @@ class Constant */ Constant(const size_t outSize = 0, const double scalar = 0.0); - //! Copy constructor. - Constant(const Constant&); - /** * Ordinary feed forward pass of a neural network. The forward pass fills the * output with the specified constant parameter. diff --git a/src/mlpack/methods/ann/layer/constant_impl.hpp b/src/mlpack/methods/ann/layer/constant_impl.hpp index 6a1862a251..5b97f04ba6 100644 --- a/src/mlpack/methods/ann/layer/constant_impl.hpp +++ b/src/mlpack/methods/ann/layer/constant_impl.hpp @@ -30,16 +30,6 @@ Constant::Constant( constantOutput.fill(scalar); } -template -Constant::Constant( - const Constant& layer) : - inSize(layer.inSize), - outSize(layer.outSize), - constantOutput(layer.constantOutput) -{ - // Nothing to do here. -} - template template void Constant::Forward( diff --git a/src/mlpack/methods/ann/layer/convolution.hpp b/src/mlpack/methods/ann/layer/convolution.hpp index 8c8ea9dd6e..16053056e9 100644 --- a/src/mlpack/methods/ann/layer/convolution.hpp +++ b/src/mlpack/methods/ann/layer/convolution.hpp @@ -111,9 +111,6 @@ class Convolution const size_t inputHeight = 0, const std::string& paddingType = "None"); - //! Copy constructor. - Convolution(const Convolution&); - /* * Set the weight and bias term. */ diff --git a/src/mlpack/methods/ann/layer/convolution_impl.hpp b/src/mlpack/methods/ann/layer/convolution_impl.hpp index d3bcadd24a..671670dc12 100644 --- a/src/mlpack/methods/ann/layer/convolution_impl.hpp +++ b/src/mlpack/methods/ann/layer/convolution_impl.hpp @@ -139,41 +139,6 @@ Convolution< padding = ann::Padding<>(padWLeft, padWRight, padHTop, padHBottom); } -template< - typename ForwardConvolutionRule, - typename BackwardConvolutionRule, - typename GradientConvolutionRule, - typename InputDataType, - typename OutputDataType -> -Convolution< - ForwardConvolutionRule, - BackwardConvolutionRule, - GradientConvolutionRule, - InputDataType, - OutputDataType ->::Convolution( - const Convolution& layer) : - inSize(layer.inSize), - outSize(layer.outSize), - kernelWidth(layer.kernelWidth), - kernelHeight(layer.kernelHeight), - strideWidth(layer.strideWidth), - strideHeight(layer.strideHeight), - padWLeft(layer.padWLeft), - padWRight(layer.padWRight), - padHBottom(layer.padHBottom), - padHTop(layer.padHTop), - weights(layer.weights), - inputWidth(layer.inputWidth), - inputHeight(layer.inputHeight), - outputWidth(layer.outputWidth), - outputHeight(layer.outputHeight), - padding(layer.padding) -{ - Reset(); -} - template< typename ForwardConvolutionRule, typename BackwardConvolutionRule, diff --git a/src/mlpack/methods/ann/layer/dropconnect.hpp b/src/mlpack/methods/ann/layer/dropconnect.hpp index 14216c65c2..a1411845a4 100644 --- a/src/mlpack/methods/ann/layer/dropconnect.hpp +++ b/src/mlpack/methods/ann/layer/dropconnect.hpp @@ -14,7 +14,6 @@ #ifndef MLPACK_METHODS_ANN_LAYER_DROPCONNECT_HPP #define MLPACK_METHODS_ANN_LAYER_DROPCONNECT_HPP -#include "../visitor/copy_visitor.hpp" #include #include "layer_types.hpp" @@ -59,8 +58,7 @@ namespace ann /** Artificial Neural Network. */ { */ template< typename InputDataType = arma::mat, - typename OutputDataType = arma::mat, - typename... CustomLayers + typename OutputDataType = arma::mat > class DropConnect { @@ -68,9 +66,6 @@ class DropConnect //! Create the DropConnect object. DropConnect(); - //! Copy constructor. - DropConnect(const DropConnect&); - /** * Creates the DropConnect Layer as a Linear Object that takes input size, * output size and ratio as parameter. diff --git a/src/mlpack/methods/ann/layer/dropconnect_impl.hpp b/src/mlpack/methods/ann/layer/dropconnect_impl.hpp index 1da420b263..22d40fcbf0 100644 --- a/src/mlpack/methods/ann/layer/dropconnect_impl.hpp +++ b/src/mlpack/methods/ann/layer/dropconnect_impl.hpp @@ -18,7 +18,6 @@ #include "dropconnect.hpp" #include "../visitor/delete_visitor.hpp" -#include "../visitor/copy_visitor.hpp" #include "../visitor/forward_visitor.hpp" #include "../visitor/backward_visitor.hpp" #include "../visitor/gradient_visitor.hpp" @@ -28,9 +27,8 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { -template -DropConnect::DropConnect() : +template +DropConnect::DropConnect() : ratio(0.5), scale(2.0), deterministic(true) @@ -38,9 +36,8 @@ DropConnect::DropConnect() : // Nothing to do here. } -template -DropConnect::DropConnect( +template +DropConnect::DropConnect( const size_t inSize, const size_t outSize, const double ratio) : @@ -51,24 +48,9 @@ DropConnect::DropConnect( network.push_back(baseLayer); } -template -DropConnect::DropConnect( - const DropConnect& layer) : - ratio(layer.ratio), - scale(layer.scale), - deterministic(layer.deterministic) -{ - CopyVisitor copyVisitor; - - baseLayer = boost::apply_visitor(copyVisitor, layer.baseLayer); - this->network.push_back(baseLayer); -} - -template +template template -void DropConnect::Forward( +void DropConnect::Forward( const arma::Mat& input, arma::Mat& output) { @@ -97,10 +79,9 @@ void DropConnect::Forward( } } -template +template template -void DropConnect::Backward( +void DropConnect::Backward( const arma::Mat& input, const arma::Mat& gy, arma::Mat& g) @@ -108,10 +89,9 @@ void DropConnect::Backward( boost::apply_visitor(BackwardVisitor(input, gy, g), baseLayer); } -template +template template -void DropConnect::Gradient( +void DropConnect::Gradient( const arma::Mat& input, const arma::Mat& error, arma::Mat& /* gradient */) @@ -123,10 +103,9 @@ void DropConnect::Gradient( boost::apply_visitor(ParametersSetVisitor(denoise), baseLayer); } -template +template template -void DropConnect::serialize( +void DropConnect::serialize( Archive& ar, const unsigned int /* version */) { diff --git a/src/mlpack/methods/ann/layer/dropout.hpp b/src/mlpack/methods/ann/layer/dropout.hpp index 3774a6b65e..ad7b68c6ce 100644 --- a/src/mlpack/methods/ann/layer/dropout.hpp +++ b/src/mlpack/methods/ann/layer/dropout.hpp @@ -60,9 +60,6 @@ class Dropout */ Dropout(const double ratio = 0.5); - //! Copy constructor. - Dropout(const Dropout&); - /** * Ordinary feed forward pass of the dropout layer. * diff --git a/src/mlpack/methods/ann/layer/dropout_impl.hpp b/src/mlpack/methods/ann/layer/dropout_impl.hpp index 081e2e474f..6e63a68448 100644 --- a/src/mlpack/methods/ann/layer/dropout_impl.hpp +++ b/src/mlpack/methods/ann/layer/dropout_impl.hpp @@ -29,16 +29,6 @@ Dropout::Dropout( // Nothing to do here. } -template -Dropout::Dropout( - const Dropout& layer) : - ratio(layer.ratio), - scale(layer.scale), - deterministic(layer.deterministic) -{ - // Nothing to do here. -} - template template void Dropout::Forward( diff --git a/src/mlpack/methods/ann/layer/fast_lstm.hpp b/src/mlpack/methods/ann/layer/fast_lstm.hpp index 8daeb0a4aa..b934c0c5ea 100644 --- a/src/mlpack/methods/ann/layer/fast_lstm.hpp +++ b/src/mlpack/methods/ann/layer/fast_lstm.hpp @@ -73,9 +73,6 @@ class FastLSTM //! Create the Fast LSTM object. FastLSTM(); - //! Copy constructor. - FastLSTM(const FastLSTM&); - /** * Create the Fast LSTM layer object using the specified parameters. * @@ -290,7 +287,7 @@ class FastLSTM //! Locally-stored cell activation error. OutputDataType cellActivation; - //! Locally-stored forget gate error. + //! Locally-stored foget gate error. OutputDataType forgetGateError; //! Locally-stored previous error. diff --git a/src/mlpack/methods/ann/layer/fast_lstm_impl.hpp b/src/mlpack/methods/ann/layer/fast_lstm_impl.hpp index 92e1f126e5..24b3544fd1 100644 --- a/src/mlpack/methods/ann/layer/fast_lstm_impl.hpp +++ b/src/mlpack/methods/ann/layer/fast_lstm_impl.hpp @@ -46,26 +46,6 @@ FastLSTM::FastLSTM( 4 * outSize * inSize + 4 * outSize + 4 * outSize * outSize, 1); } -template -FastLSTM::FastLSTM( - const FastLSTM& layer) : - inSize(layer.inSize), - outSize(layer.outSize), - rho(layer.rho), - weights(layer.weights), - forwardStep(layer.forwardStep), - backwardStep(layer.backwardStep), - gradientStep(layer.gradientStep), - grad(layer.grad), - batchSize(layer.batchSize), - batchStep(layer.batchStep), - gradientStepIdx(layer.gradientStepIdx), - rhoSize(layer.rho), - bpttSteps(layer.bpttSteps) -{ - Reset(); -} - template void FastLSTM::Reset() { diff --git a/src/mlpack/methods/ann/layer/flexible_relu.hpp b/src/mlpack/methods/ann/layer/flexible_relu.hpp index 72c5d3a821..c6ad4273ca 100644 --- a/src/mlpack/methods/ann/layer/flexible_relu.hpp +++ b/src/mlpack/methods/ann/layer/flexible_relu.hpp @@ -71,9 +71,6 @@ class FlexibleReLU */ FlexibleReLU(const double alpha = 0); - //! Copy constructor. - FlexibleReLU(const FlexibleReLU&); - /** * Reset the layer parameter. */ diff --git a/src/mlpack/methods/ann/layer/flexible_relu_impl.hpp b/src/mlpack/methods/ann/layer/flexible_relu_impl.hpp index a631e41c8f..8c5064864f 100644 --- a/src/mlpack/methods/ann/layer/flexible_relu_impl.hpp +++ b/src/mlpack/methods/ann/layer/flexible_relu_impl.hpp @@ -31,15 +31,6 @@ FlexibleReLU::FlexibleReLU( this->alpha(0) = userAlpha; } -template -FlexibleReLU::FlexibleReLU( - const FlexibleReLU& layer) : - userAlpha(layer.userAlpha) -{ - this->alpha.set_size(1, 1); - this->alpha(0) = userAlpha; -} - template void FlexibleReLU::Reset() { diff --git a/src/mlpack/methods/ann/layer/glimpse.hpp b/src/mlpack/methods/ann/layer/glimpse.hpp index f42eec6e31..b77c8f42de 100644 --- a/src/mlpack/methods/ann/layer/glimpse.hpp +++ b/src/mlpack/methods/ann/layer/glimpse.hpp @@ -88,9 +88,6 @@ template < class Glimpse { public: - //! Copy constructor. - Glimpse(const Glimpse&); - /** * Create the GlimpseLayer object using the specified ratio and rescale * parameter. diff --git a/src/mlpack/methods/ann/layer/glimpse_impl.hpp b/src/mlpack/methods/ann/layer/glimpse_impl.hpp index 3ed2ec79de..187f3c0d37 100644 --- a/src/mlpack/methods/ann/layer/glimpse_impl.hpp +++ b/src/mlpack/methods/ann/layer/glimpse_impl.hpp @@ -20,23 +20,6 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { -template -Glimpse::Glimpse( - const Glimpse& layer) : - inSize(layer.inSize), - size(layer.size), - depth(layer.depth), - scale(layer.scale), - inputWidth(layer.inputWidth), - inputHeight(layer.inputHeight), - outputWidth(layer.outputWidth), - outputHeight(layer.outputHeight), - inputDepth(layer.inputDepth), - deterministic(layer.deterministic) -{ - // Nothing to do here. -} - template Glimpse::Glimpse( const size_t inSize, diff --git a/src/mlpack/methods/ann/layer/gru.hpp b/src/mlpack/methods/ann/layer/gru.hpp index d0ff41d97d..9a77be98d7 100644 --- a/src/mlpack/methods/ann/layer/gru.hpp +++ b/src/mlpack/methods/ann/layer/gru.hpp @@ -53,8 +53,7 @@ namespace ann /** Artificial Neural Network. */ { */ template < typename InputDataType = arma::mat, - typename OutputDataType = arma::mat, - typename... CustomLayers + typename OutputDataType = arma::mat > class GRU { @@ -73,9 +72,6 @@ class GRU const size_t outSize, const size_t rho = std::numeric_limits::max()); - //! Copy constructor. - GRU(const GRU&); - /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/gru_impl.hpp b/src/mlpack/methods/ann/layer/gru_impl.hpp index f097dae756..6d6043e9d3 100644 --- a/src/mlpack/methods/ann/layer/gru_impl.hpp +++ b/src/mlpack/methods/ann/layer/gru_impl.hpp @@ -23,62 +23,14 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { -template -GRU::GRU() +template +GRU::GRU() { // Nothing to do here. } -template -GRU::GRU( - const GRU& layer) : - inSize(layer.inSize), - outSize(layer.outSize), - rho(layer.rho), - batchSize(layer.batchSize), - forwardStep(layer.forwardStep), - backwardStep(layer.backwardStep), - gradientStep(layer.gradientStep), - outParameter(layer.outParameter), - allZeros(layer.allZeros), - prevOutput(layer.prevOutput), - backIterator(layer.backIterator), - gradIterator(layer.gradIterator), - prevError(layer.prevError), - deterministic(layer.deterministic) -{ - CopyVisitor copyVisitor; - - // Input specific linear layers(for zt, rt, ot). - input2GateModule = boost::apply_visitor(copyVisitor, - layer.input2GateModule); - - // Previous output gates (for zt and rt). - output2GateModule = boost::apply_visitor(copyVisitor, - layer.output2GateModule); - - // Previous output gate for ot. - outputHidden2GateModule = boost::apply_visitor(copyVisitor, - layer.outputHidden2GateModule); - - this->network.push_back(input2GateModule); - this->network.push_back(output2GateModule); - this->network.push_back(outputHidden2GateModule); - - inputGateModule = new SigmoidLayer<>(); - forgetGateModule = new SigmoidLayer<>(); - hiddenStateModule = new TanHLayer<>(); - - this->network.push_back(inputGateModule); - this->network.push_back(hiddenStateModule); - this->network.push_back(forgetGateModule); -} - -template -GRU::GRU( +template +GRU::GRU( const size_t inSize, const size_t outSize, const size_t rho) : @@ -124,10 +76,9 @@ GRU::GRU( gradIterator = outParameter.end(); } -template +template template -void GRU::Forward( +void GRU::Forward( const arma::Mat& input, arma::Mat& output) { if (input.n_cols != batchSize) @@ -240,10 +191,9 @@ void GRU::Forward( } } -template +template template -void GRU::Backward( +void GRU::Backward( const arma::Mat& input, const arma::Mat& gy, arma::Mat& g) { if (input.n_cols != batchSize) @@ -363,10 +313,9 @@ void GRU::Backward( g = boost::apply_visitor(deltaVisitor, input2GateModule); } -template +template template -void GRU::Gradient( +void GRU::Gradient( const arma::Mat& input, const arma::Mat& /* error */, arma::Mat& /* gradient */) @@ -413,10 +362,8 @@ void GRU::Gradient( gradIterator--; } -template -void GRU:: -ResetCell(const size_t /* size */) +template +void GRU::ResetCell(const size_t /* size */) { outParameter.clear(); outParameter.push_back(std::move(arma::mat(allZeros.memptr(), @@ -430,10 +377,9 @@ ResetCell(const size_t /* size */) backwardStep = 0; } -template +template template -void GRU::serialize( +void GRU::serialize( Archive& ar, const unsigned int /* version */) { // If necessary, clean memory from the old model. diff --git a/src/mlpack/methods/ann/layer/highway.hpp b/src/mlpack/methods/ann/layer/highway.hpp index 76e6426ff7..8b15ff66b8 100644 --- a/src/mlpack/methods/ann/layer/highway.hpp +++ b/src/mlpack/methods/ann/layer/highway.hpp @@ -74,9 +74,6 @@ class Highway //! Destroy the Highway object. ~Highway(); - //! Copy constructor. - Highway(const Highway&); - /** * Reset the layer parameter. */ @@ -258,9 +255,6 @@ class Highway //! Locally-stored output height visitor. OutputHeightVisitor outputHeightVisitor; - - //! Locally-stored copy visitor - CopyVisitor copyVisitor; }; // class Highway } // namespace ann diff --git a/src/mlpack/methods/ann/layer/highway_impl.hpp b/src/mlpack/methods/ann/layer/highway_impl.hpp index eacc41ed4d..625aa21a7b 100644 --- a/src/mlpack/methods/ann/layer/highway_impl.hpp +++ b/src/mlpack/methods/ann/layer/highway_impl.hpp @@ -37,30 +37,6 @@ Highway::Highway() : // Nothing to do here. } -template -Highway::Highway( - const Highway& layer) : - inSize(layer.inSize), - networkOwnerships(layer.networkOwnerships), - model(layer.model), - weights(layer.weights), - reset(layer.reset), - width(layer.width), - height(layer.height), - networkOutput(layer.networkOutput) -{ - for (size_t i = 0; i < layer.network.size(); ++i) - { - if (layer.networkOwnerships[i]) - { - this->network.push_back(boost::apply_visitor(copyVisitor, - layer.network[i])); - } - } - Reset(); -} - template< typename InputDataType, typename OutputDataType, typename... CustomLayers> Highway::Highway( diff --git a/src/mlpack/methods/ann/layer/layer_norm.hpp b/src/mlpack/methods/ann/layer/layer_norm.hpp index cd6cf82ceb..fb883116ca 100644 --- a/src/mlpack/methods/ann/layer/layer_norm.hpp +++ b/src/mlpack/methods/ann/layer/layer_norm.hpp @@ -76,9 +76,6 @@ class LayerNorm */ LayerNorm(const size_t size, const double eps = 1e-8); - //! Copy constructor. - LayerNorm(const LayerNorm&); - /** * Reset the layer parameters. */ diff --git a/src/mlpack/methods/ann/layer/layer_norm_impl.hpp b/src/mlpack/methods/ann/layer/layer_norm_impl.hpp index c0f5d1bc1c..c2399c751c 100644 --- a/src/mlpack/methods/ann/layer/layer_norm_impl.hpp +++ b/src/mlpack/methods/ann/layer/layer_norm_impl.hpp @@ -29,16 +29,6 @@ LayerNorm::LayerNorm() : // Nothing to do here. } -template -LayerNorm::LayerNorm(const LayerNorm& layer) : - size(layer.size), - eps(layer.eps), - loading(layer.loading), - weights(layer.weights) -{ - Reset(); -} - template LayerNorm::LayerNorm( const size_t size, const double eps) : diff --git a/src/mlpack/methods/ann/layer/layer_types.hpp b/src/mlpack/methods/ann/layer/layer_types.hpp index c7f673ca44..9532e48e88 100644 --- a/src/mlpack/methods/ann/layer/layer_types.hpp +++ b/src/mlpack/methods/ann/layer/layer_types.hpp @@ -65,9 +65,11 @@ namespace mlpack { namespace ann { template class BatchNorm; +template class DropConnect; template class Glimpse; template class LayerNorm; template class LSTM; +template class GRU; template class FastLSTM; template class VRClassReward; template class Concatenate; @@ -149,18 +151,6 @@ template< > class Convolution; -template -class DropConnect; - -template -class GRU; - template< typename ForwardConvolutionRule, typename BackwardConvolutionRule, @@ -181,21 +171,10 @@ class AtrousConvolution; template< typename InputDataType, - typename OutputDataType, - typename... CustomLayers + typename OutputDataType > class RecurrentAttention; -template -class AdaptiveMaxPooling; - -template -class AdaptiveMeanPooling; - template class WeightNorm; +template +class AdaptiveMaxPooling; + +template +class AdaptiveMeanPooling; + using MoreTypes = boost::variant< Recurrent*, RecurrentAttention*, @@ -223,6 +212,8 @@ using MoreTypes = boost::variant< template using LayerTypes = boost::variant< + AdaptiveMaxPooling*, + AdaptiveMeanPooling*, Add*, AddMerge*, AlphaDropout*, diff --git a/src/mlpack/methods/ann/layer/linear.hpp b/src/mlpack/methods/ann/layer/linear.hpp index 8e9be7f4ce..5914ac605a 100644 --- a/src/mlpack/methods/ann/layer/linear.hpp +++ b/src/mlpack/methods/ann/layer/linear.hpp @@ -52,9 +52,6 @@ class Linear const size_t outSize, RegularizerType regularizer = RegularizerType()); - //! Copy constructor. - Linear(const Linear&); - /* * Reset the layer parameter. */ diff --git a/src/mlpack/methods/ann/layer/linear_impl.hpp b/src/mlpack/methods/ann/layer/linear_impl.hpp index 108c4e0bf3..22caf180f9 100644 --- a/src/mlpack/methods/ann/layer/linear_impl.hpp +++ b/src/mlpack/methods/ann/layer/linear_impl.hpp @@ -28,18 +28,6 @@ Linear::Linear() : // Nothing to do here. } -template -Linear::Linear( - const Linear& layer) : - inSize(layer.inSize), - outSize(layer.outSize), - weights(layer.weights), - regularizer(layer.regularizer) -{ - Reset(); -} - template Linear::Linear( diff --git a/src/mlpack/methods/ann/layer/linear_no_bias.hpp b/src/mlpack/methods/ann/layer/linear_no_bias.hpp index e2486cd8f6..5e38d90e16 100644 --- a/src/mlpack/methods/ann/layer/linear_no_bias.hpp +++ b/src/mlpack/methods/ann/layer/linear_no_bias.hpp @@ -51,9 +51,6 @@ class LinearNoBias const size_t outSize, RegularizerType regularizer = RegularizerType()); - //! Copy constructor. - LinearNoBias(const LinearNoBias&); - /* * Reset the layer parameter. */ diff --git a/src/mlpack/methods/ann/layer/linear_no_bias_impl.hpp b/src/mlpack/methods/ann/layer/linear_no_bias_impl.hpp index d5cc9c1e3f..a1d2070e9c 100644 --- a/src/mlpack/methods/ann/layer/linear_no_bias_impl.hpp +++ b/src/mlpack/methods/ann/layer/linear_no_bias_impl.hpp @@ -28,18 +28,6 @@ LinearNoBias::LinearNoBias() : // Nothing to do here. } -template -LinearNoBias::LinearNoBias( - const LinearNoBias& layer) : - inSize(layer.inSize), - outSize(layer.outSize), - weights(layer.weights), - regularizer(layer.regularizer) -{ - Reset(); -} - template LinearNoBias::LinearNoBias( diff --git a/src/mlpack/methods/ann/layer/lookup.hpp b/src/mlpack/methods/ann/layer/lookup.hpp index 7a5f681fed..93e70712ae 100644 --- a/src/mlpack/methods/ann/layer/lookup.hpp +++ b/src/mlpack/methods/ann/layer/lookup.hpp @@ -44,9 +44,6 @@ class Lookup */ Lookup(const size_t inSize = 0, const size_t outSize = 0); - //! Copy constructor. - Lookup(const Lookup&); - /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/lookup_impl.hpp b/src/mlpack/methods/ann/layer/lookup_impl.hpp index 8f4e034c45..2e94496d82 100644 --- a/src/mlpack/methods/ann/layer/lookup_impl.hpp +++ b/src/mlpack/methods/ann/layer/lookup_impl.hpp @@ -29,17 +29,6 @@ Lookup::Lookup( weights.set_size(outSize, inSize); } -template -Lookup::Lookup( - const Lookup& layer) : - inSize(layer.inSize), - outSize(layer.outSize), - weights(layer.weights) -{ - // Nothing to do here. -} - - template template void Lookup::Forward( diff --git a/src/mlpack/methods/ann/layer/lstm.hpp b/src/mlpack/methods/ann/layer/lstm.hpp index 442839f4f6..78c79096a0 100644 --- a/src/mlpack/methods/ann/layer/lstm.hpp +++ b/src/mlpack/methods/ann/layer/lstm.hpp @@ -65,9 +65,6 @@ class LSTM //! Create the LSTM object. LSTM(); - //! Copy constructor. - LSTM(const LSTM&); - /** * Create the LSTM layer object using the specified parameters. * diff --git a/src/mlpack/methods/ann/layer/lstm_impl.hpp b/src/mlpack/methods/ann/layer/lstm_impl.hpp index 1123a988b1..185a12cace 100644 --- a/src/mlpack/methods/ann/layer/lstm_impl.hpp +++ b/src/mlpack/methods/ann/layer/lstm_impl.hpp @@ -24,24 +24,6 @@ LSTM::LSTM() // Nothing to do here. } -template -LSTM::LSTM( - const LSTM& layer) : - inSize(layer.inSize), - outSize(layer.outSize), - rho(layer.rho), - weights(layer.weights), - forwardStep(layer.forwardStep), - backwardStep(layer.backwardStep), - gradientStep(layer.gradientStep), - batchSize(layer.batchSize), - batchStep(layer.batchStep), - rhoSize(layer.rhoSize), - bpttSteps(layer.bpttSteps) -{ - Reset(); -} - template LSTM::LSTM( const size_t inSize, const size_t outSize, const size_t rho) : diff --git a/src/mlpack/methods/ann/layer/max_pooling.hpp b/src/mlpack/methods/ann/layer/max_pooling.hpp index 9725197178..ba2df3fa79 100644 --- a/src/mlpack/methods/ann/layer/max_pooling.hpp +++ b/src/mlpack/methods/ann/layer/max_pooling.hpp @@ -70,9 +70,6 @@ class MaxPooling const size_t strideHeight = 1, const bool floor = true); - //! Copy constructor. - MaxPooling(const MaxPooling&); - /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/max_pooling_impl.hpp b/src/mlpack/methods/ann/layer/max_pooling_impl.hpp index 69d6a18ceb..e2954cafc2 100644 --- a/src/mlpack/methods/ann/layer/max_pooling_impl.hpp +++ b/src/mlpack/methods/ann/layer/max_pooling_impl.hpp @@ -51,28 +51,6 @@ MaxPooling::MaxPooling( // Nothing to do here. } -template -MaxPooling::MaxPooling( - const MaxPooling& layer) : - kernelWidth(layer.kernelWidth), - kernelHeight(layer.kernelHeight), - strideWidth(layer.strideWidth), - strideHeight(layer.strideHeight), - floor(layer.floor), - inSize(layer.inSize), - outSize(layer.outSize), - reset(layer.reset), - inputWidth(layer.inputWidth), - inputHeight(layer.inputHeight), - outputWidth(layer.outputWidth), - outputHeight(layer.outputHeight), - deterministic(layer.deterministic), - offset(layer.offset), - batchSize(layer.batchSize) -{ - // Nothing to do here. -} - template template void MaxPooling::Forward( diff --git a/src/mlpack/methods/ann/layer/mean_pooling.hpp b/src/mlpack/methods/ann/layer/mean_pooling.hpp index cd821b52d5..e8575752db 100644 --- a/src/mlpack/methods/ann/layer/mean_pooling.hpp +++ b/src/mlpack/methods/ann/layer/mean_pooling.hpp @@ -51,9 +51,6 @@ class MeanPooling const size_t strideHeight = 1, const bool floor = true); - //! Copy constructor. - MeanPooling(const MeanPooling&); - /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/mean_pooling_impl.hpp b/src/mlpack/methods/ann/layer/mean_pooling_impl.hpp index 2b580bb52b..4f0bf84792 100644 --- a/src/mlpack/methods/ann/layer/mean_pooling_impl.hpp +++ b/src/mlpack/methods/ann/layer/mean_pooling_impl.hpp @@ -51,28 +51,6 @@ MeanPooling::MeanPooling( // Nothing to do here. } -template -MeanPooling::MeanPooling( - const MeanPooling& layer) : - kernelWidth(layer.kernelWidth), - kernelHeight(layer.kernelHeight), - strideWidth(layer.strideWidth), - strideHeight(layer.strideHeight), - floor(layer.floor), - inSize(layer.inSize), - outSize(layer.outSize), - inputWidth(layer.inputWidth), - inputHeight(layer.inputHeight), - outputWidth(layer.outputWidth), - reset(layer.reset), - outputHeight(layer.outputHeight), - deterministic(layer.deterministic), - offset(layer.offset), - batchSize(layer.batchSize) -{ - // Nothing to do here. -} - template template void MeanPooling::Forward( diff --git a/src/mlpack/methods/ann/layer/minibatch_discrimination.hpp b/src/mlpack/methods/ann/layer/minibatch_discrimination.hpp index 7c70f86da5..2c8866c80b 100644 --- a/src/mlpack/methods/ann/layer/minibatch_discrimination.hpp +++ b/src/mlpack/methods/ann/layer/minibatch_discrimination.hpp @@ -56,9 +56,6 @@ class MiniBatchDiscrimination //! Create the MiniBatchDiscrimination object. MiniBatchDiscrimination(); - //! Copy constructor. - MiniBatchDiscrimination(const MiniBatchDiscrimination&); - /** * Create the MiniBatchDiscrimination layer object using the specified * number of units. diff --git a/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp b/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp index 57ac7c7d93..aa337afbb5 100644 --- a/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp +++ b/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp @@ -43,19 +43,6 @@ MiniBatchDiscrimination -MiniBatchDiscrimination::MiniBatchDiscrimination( - const MiniBatchDiscrimination& layer) : - A(layer.A), - B(layer.B), - C(layer.C), - batchSize(layer.batchSize), - weights(layer.weights) -{ - Reset(); -} - template void MiniBatchDiscrimination::Reset() { diff --git a/src/mlpack/methods/ann/layer/multiply_constant.hpp b/src/mlpack/methods/ann/layer/multiply_constant.hpp index d5f795581f..fc76b4e0dc 100644 --- a/src/mlpack/methods/ann/layer/multiply_constant.hpp +++ b/src/mlpack/methods/ann/layer/multiply_constant.hpp @@ -39,9 +39,6 @@ class MultiplyConstant */ MultiplyConstant(const double scalar = 1.0); - //! Copy constructor. - MultiplyConstant(const MultiplyConstant&); - /** * Ordinary feed forward pass of a neural network. Multiply the input with the * specified constant scalar value. diff --git a/src/mlpack/methods/ann/layer/multiply_constant_impl.hpp b/src/mlpack/methods/ann/layer/multiply_constant_impl.hpp index d183c8e7f0..8df557806a 100644 --- a/src/mlpack/methods/ann/layer/multiply_constant_impl.hpp +++ b/src/mlpack/methods/ann/layer/multiply_constant_impl.hpp @@ -26,14 +26,6 @@ MultiplyConstant::MultiplyConstant( // Nothing to do here. } -template -MultiplyConstant::MultiplyConstant( - const MultiplyConstant& layer) : - scalar(layer.scalar) -{ - // Nothing to do here. -} - template template void MultiplyConstant::Forward( diff --git a/src/mlpack/methods/ann/layer/multiply_merge.hpp b/src/mlpack/methods/ann/layer/multiply_merge.hpp index 8f8d5e81b0..e4fa21babb 100644 --- a/src/mlpack/methods/ann/layer/multiply_merge.hpp +++ b/src/mlpack/methods/ann/layer/multiply_merge.hpp @@ -50,9 +50,6 @@ class MultiplyMerge */ MultiplyMerge(const bool model = false, const bool run = true); - //! Copy constructor. - MultiplyMerge(const MultiplyMerge&); - //! Destructor to release allocated memory. ~MultiplyMerge(); diff --git a/src/mlpack/methods/ann/layer/multiply_merge_impl.hpp b/src/mlpack/methods/ann/layer/multiply_merge_impl.hpp index 5729667e08..d0a36e1dae 100644 --- a/src/mlpack/methods/ann/layer/multiply_merge_impl.hpp +++ b/src/mlpack/methods/ann/layer/multiply_merge_impl.hpp @@ -32,17 +32,6 @@ MultiplyMerge::MultiplyMerge( // Nothing to do here. } -template -MultiplyMerge::MultiplyMerge( - const MultiplyMerge& layer) : - model(layer.model), - run(layer.run), - ownsLayer(layer.ownsLayer) -{ - // Nothing to do here. -} - template MultiplyMerge::~MultiplyMerge() diff --git a/src/mlpack/methods/ann/layer/recurrent_attention.hpp b/src/mlpack/methods/ann/layer/recurrent_attention.hpp index 72ff4a88a8..ad640df6f3 100644 --- a/src/mlpack/methods/ann/layer/recurrent_attention.hpp +++ b/src/mlpack/methods/ann/layer/recurrent_attention.hpp @@ -16,7 +16,6 @@ #include #include "../visitor/delta_visitor.hpp" -#include "../visitor/copy_visitor.hpp" #include "../visitor/output_parameter_visitor.hpp" #include "../visitor/reset_visitor.hpp" #include "../visitor/weight_size_visitor.hpp" @@ -52,8 +51,7 @@ namespace ann /** Artificial Neural Network. */ { */ template < typename InputDataType = arma::mat, - typename OutputDataType = arma::mat, - typename... CustomLayers + typename OutputDataType = arma::mat > class RecurrentAttention { @@ -64,9 +62,6 @@ class RecurrentAttention */ RecurrentAttention(); - //! Copy constructor. - RecurrentAttention(const RecurrentAttention&); - /** * Create the RecurrentAttention object using the specified modules. * @@ -214,9 +209,6 @@ class RecurrentAttention //! Locally-stored weight size visitor. WeightSizeVisitor weightSizeVisitor; - //! Locally-stored copy visitor - CopyVisitor copyVisitor; - //! Locally-stored delta visitor. DeltaVisitor deltaVisitor; diff --git a/src/mlpack/methods/ann/layer/recurrent_attention_impl.hpp b/src/mlpack/methods/ann/layer/recurrent_attention_impl.hpp index d5616f54ac..25b9b32349 100644 --- a/src/mlpack/methods/ann/layer/recurrent_attention_impl.hpp +++ b/src/mlpack/methods/ann/layer/recurrent_attention_impl.hpp @@ -26,10 +26,8 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { -template -RecurrentAttention:: -RecurrentAttention() : +template +RecurrentAttention::RecurrentAttention() : rho(0), forwardStep(0), backwardStep(0), @@ -38,29 +36,9 @@ RecurrentAttention() : // Nothing to do. } -template -RecurrentAttention:: -RecurrentAttention( - const RecurrentAttention& layer) : - outSize(layer.outSize), - rho(layer.rho), - forwardStep(layer.forwardStep), - backwardStep(layer.backwardStep), - deterministic(layer.deterministic) -{ - rnnModule = boost::apply_visitor(copyVisitor, layer.rnnModule); - actionModule = boost::apply_visitor(copyVisitor, layer.actionModule); - - this->network.push_back(rnnModule); - this->network.push_back(actionModule); -} - -template +template template -RecurrentAttention:: -RecurrentAttention( +RecurrentAttention::RecurrentAttention( const size_t outSize, const RNNModuleType& rnn, const ActionModuleType& action, @@ -77,11 +55,9 @@ RecurrentAttention( network.push_back(actionModule); } -template +template template -void RecurrentAttention:: -Forward( +void RecurrentAttention::Forward( const arma::Mat& input, arma::Mat& output) { // Initialize the action input. @@ -134,11 +110,9 @@ Forward( backwardStep = 0; } -template +template template -void RecurrentAttention:: -Backward( +void RecurrentAttention::Backward( const arma::Mat& /* input */, const arma::Mat& gy, arma::Mat& g) @@ -216,11 +190,10 @@ Backward( IntermediateGradient(); } } -template + +template template -void RecurrentAttention:: -Gradient( +void RecurrentAttention::Gradient( const arma::Mat& /* input */, const arma::Mat& /* error */, arma::Mat& /* gradient */) @@ -232,11 +205,9 @@ Gradient( attentionGradient, offset), actionModule); } -template +template template -void RecurrentAttention:: -serialize( +void RecurrentAttention::serialize( Archive& ar, const unsigned int /* version */) { ar & BOOST_SERIALIZATION_NVP(rho); diff --git a/src/mlpack/methods/ann/layer/reparametrization.hpp b/src/mlpack/methods/ann/layer/reparametrization.hpp index 717bb3fffc..785ad113e3 100644 --- a/src/mlpack/methods/ann/layer/reparametrization.hpp +++ b/src/mlpack/methods/ann/layer/reparametrization.hpp @@ -59,9 +59,6 @@ class Reparametrization //! Create the Reparametrization object. Reparametrization(); - //! Copy constructor. - Reparametrization(const Reparametrization&); - /** * Create the Reparametrization layer object using the specified sample vector size. * diff --git a/src/mlpack/methods/ann/layer/reparametrization_impl.hpp b/src/mlpack/methods/ann/layer/reparametrization_impl.hpp index b108336941..6e21dea57c 100644 --- a/src/mlpack/methods/ann/layer/reparametrization_impl.hpp +++ b/src/mlpack/methods/ann/layer/reparametrization_impl.hpp @@ -29,17 +29,6 @@ Reparametrization::Reparametrization() : // Nothing to do here. } -template -Reparametrization::Reparametrization( - const Reparametrization& layer) : - latentSize(layer.latentSize), - stochastic(layer.stochastic), - includeKl(layer.includeKl), - beta(layer.beta) -{ - // Nothing to do here. -} - template Reparametrization::Reparametrization( const size_t latentSize, diff --git a/src/mlpack/methods/ann/layer/sequential_impl.hpp b/src/mlpack/methods/ann/layer/sequential_impl.hpp index 3288a8137c..8d433b3af7 100644 --- a/src/mlpack/methods/ann/layer/sequential_impl.hpp +++ b/src/mlpack/methods/ann/layer/sequential_impl.hpp @@ -34,19 +34,6 @@ Sequential(const bool model) : // Nothing to do here. } -template -Sequential:: -Sequential(const Sequential& layer) : - model(layer.model), - reset(layer.reset), - width(layer.width), - height(layer.height), - ownsLayers(layer.ownsLayers) -{ - // Nothing to do here. -} - template Sequential:: diff --git a/src/mlpack/methods/ann/layer/transposed_convolution.hpp b/src/mlpack/methods/ann/layer/transposed_convolution.hpp index 1f577c54e4..15597fd4a7 100644 --- a/src/mlpack/methods/ann/layer/transposed_convolution.hpp +++ b/src/mlpack/methods/ann/layer/transposed_convolution.hpp @@ -52,9 +52,6 @@ class TransposedConvolution //! Create the Transposed Convolution object. TransposedConvolution(); - //! Copy constructor. - TransposedConvolution(const TransposedConvolution&); - /** * Create the Transposed Convolution object using the specified number of * input maps, output maps, filter size, stride and padding parameter. diff --git a/src/mlpack/methods/ann/layer/transposed_convolution_impl.hpp b/src/mlpack/methods/ann/layer/transposed_convolution_impl.hpp index 3133aebc38..d49cac273a 100644 --- a/src/mlpack/methods/ann/layer/transposed_convolution_impl.hpp +++ b/src/mlpack/methods/ann/layer/transposed_convolution_impl.hpp @@ -171,42 +171,6 @@ TransposedConvolution< } } -template< - typename ForwardConvolutionRule, - typename BackwardConvolutionRule, - typename GradientConvolutionRule, - typename InputDataType, - typename OutputDataType -> -TransposedConvolution< - ForwardConvolutionRule, - BackwardConvolutionRule, - GradientConvolutionRule, - InputDataType, - OutputDataType ->::TransposedConvolution( - const TransposedConvolution& layer) : - inSize(layer.inSize), - outSize(layer.outSize), - weights(layer.weights), - kernelWidth(layer.kernelWidth), - kernelHeight(layer.kernelHeight), - strideWidth(layer.strideWidth), - strideHeight(layer.strideHeight), - padWLeft(layer.padWLeft), - padWRight(layer.padWRight), - padHBottom(layer.padHBottom), - padHTop(layer.padHTop), - inputWidth(layer.inputWidth), - inputHeight(layer.inputHeight), - paddingForward(layer.paddingForward), - paddingBackward(layer.paddingBackward), - outputWidth(layer.outputWidth), - outputHeight(layer.outputHeight) -{ - Reset(); -} - template< typename ForwardConvolutionRule, typename BackwardConvolutionRule, diff --git a/src/mlpack/methods/ann/layer/virtual_batch_norm.hpp b/src/mlpack/methods/ann/layer/virtual_batch_norm.hpp index a12bec8d3e..a21e44613e 100644 --- a/src/mlpack/methods/ann/layer/virtual_batch_norm.hpp +++ b/src/mlpack/methods/ann/layer/virtual_batch_norm.hpp @@ -49,9 +49,6 @@ class VirtualBatchNorm //! Create the VirtualBatchNorm object. VirtualBatchNorm(); - //! Copy constructor. - VirtualBatchNorm(const VirtualBatchNorm&); - /** * Create the VirtualBatchNorm layer object for a specified number of input units. * diff --git a/src/mlpack/methods/ann/layer/virtual_batch_norm_impl.hpp b/src/mlpack/methods/ann/layer/virtual_batch_norm_impl.hpp index 9d5f37ce50..d712f6cec2 100644 --- a/src/mlpack/methods/ann/layer/virtual_batch_norm_impl.hpp +++ b/src/mlpack/methods/ann/layer/virtual_batch_norm_impl.hpp @@ -29,22 +29,6 @@ VirtualBatchNorm::VirtualBatchNorm() : { // Nothing to do here. } - -template -VirtualBatchNorm::VirtualBatchNorm( - const VirtualBatchNorm& layer) : - size(layer.size), - eps(layer.eps), - loading(layer.loading), - weights(layer.weights), - referenceBatchMean(layer.referenceBatchMean), - referenceBatchMeanSquared(layer.referenceBatchMeanSquared), - oldCoefficient(layer.oldCoefficient), - newCoefficient(layer.newCoefficient) -{ - Reset(); -} - template template VirtualBatchNorm::VirtualBatchNorm( diff --git a/src/mlpack/methods/ann/layer/weight_norm.hpp b/src/mlpack/methods/ann/layer/weight_norm.hpp index 9458ba91eb..64a4df176e 100644 --- a/src/mlpack/methods/ann/layer/weight_norm.hpp +++ b/src/mlpack/methods/ann/layer/weight_norm.hpp @@ -68,9 +68,6 @@ class WeightNorm */ WeightNorm(LayerTypes layer = LayerTypes()); - //! Copy constructor. - WeightNorm(const WeightNorm&); - //! Destructor to release allocated memory. ~WeightNorm(); @@ -162,9 +159,6 @@ class WeightNorm //! Locally-stored gradient object. OutputDataType gradient; - //! Locally-stored copy visitor - CopyVisitor copyVisitor; - //! Locally-stored wrapped layer. LayerTypes wrappedLayer; diff --git a/src/mlpack/methods/ann/layer/weight_norm_impl.hpp b/src/mlpack/methods/ann/layer/weight_norm_impl.hpp index 6c3caaee90..8289733697 100644 --- a/src/mlpack/methods/ann/layer/weight_norm_impl.hpp +++ b/src/mlpack/methods/ann/layer/weight_norm_impl.hpp @@ -37,18 +37,6 @@ WeightNorm::WeightNorm( layerGradients.set_size(layerWeightSize, 1); } -template -WeightNorm::WeightNorm( - const WeightNorm& layer) : - layerWeightSize(layer.layerWeightSize), - layerGradients(layer.layerGradients), - weights(layer.weights), - layerWeights(layer.layerWeights) -{ - Reset(); -} - template WeightNorm::~WeightNorm() diff --git a/src/mlpack/methods/ann/rnn.hpp b/src/mlpack/methods/ann/rnn.hpp index 84301222d3..26533ad50a 100644 --- a/src/mlpack/methods/ann/rnn.hpp +++ b/src/mlpack/methods/ann/rnn.hpp @@ -70,14 +70,6 @@ class RNN OutputLayerType outputLayer = OutputLayerType(), InitializationRuleType initializeRule = InitializationRuleType()); - /** - * Copy the RNN object. - * - * Warning: Copying RNN is a memory-intensive task multiple layers as well - * as parameters needed to be copied. - */ - RNN(const RNN&); - //! Destructor to release allocated memory. ~RNN(); @@ -414,9 +406,6 @@ class RNN //! Locally-stored output parameter visitor. OutputParameterVisitor outputParameterVisitor; - //! Locally-stored copy visitor - CopyVisitor copyVisitor; - //! List of all module parameters for the backward pass (BBTT). std::vector moduleOutputParameter; diff --git a/src/mlpack/methods/ann/rnn_impl.hpp b/src/mlpack/methods/ann/rnn_impl.hpp index c3a0d79e46..21bf798494 100644 --- a/src/mlpack/methods/ann/rnn_impl.hpp +++ b/src/mlpack/methods/ann/rnn_impl.hpp @@ -51,37 +51,6 @@ RNN::RNN( /* Nothing to do here */ } - -template -RNN::RNN( - const RNN& network) : - rho(network.rho), - initializeRule(network.initializeRule), - inputSize(network.inputSize), - outputLayer(network.outputLayer), - outputSize(network.outputSize), - targetSize(network.targetSize), - reset(network.reset), - single(network.single), - numFunctions(network.numFunctions), - deterministic(network.deterministic), - parameter(network.parameter) -{ - for (size_t i = 0; i < network.network.size(); ++i) - { - this->network.push_back(boost::apply_visitor(copyVisitor, - network.network[i])); - } - - ResetCells(); - - if (parameter.is_empty()) - { - ResetParameters(); - } -} - template RNN::~RNN() diff --git a/src/mlpack/tests/convolutional_network_test.cpp b/src/mlpack/tests/convolutional_network_test.cpp index 324134e015..1f2634d9e4 100644 --- a/src/mlpack/tests/convolutional_network_test.cpp +++ b/src/mlpack/tests/convolutional_network_test.cpp @@ -81,33 +81,31 @@ BOOST_AUTO_TEST_CASE(VanillaNetworkTest) bool success = false; for (size_t trial = 0; trial < 5; ++trial) { - FFN, RandomInitialization> *model = new FFN< - NegativeLogLikelihood<>, - RandomInitialization>(); + FFN, RandomInitialization> model; - model->Add >(1, 8, 5, 5, 1, 1, 0, 0, 28, 28); - model->Add >(); - model->Add >(8, 8, 2, 2); - model->Add >(8, 12, 2, 2); - model->Add >(); - model->Add >(2, 2, 2, 2); - model->Add >(192, 20); - model->Add >(); - model->Add >(20, 10); - model->Add >(); - model->Add >(10, 2); - model->Add >(); + model.Add >(1, 8, 5, 5, 1, 1, 0, 0, 28, 28); + model.Add >(); + model.Add >(8, 8, 2, 2); + model.Add >(8, 12, 2, 2); + model.Add >(); + model.Add >(2, 2, 2, 2); + model.Add >(192, 20); + model.Add >(); + model.Add >(20, 10); + model.Add >(); + model.Add >(10, 2); + model.Add >(); // Train for only 8 epochs. ens::RMSProp opt(0.001, 1, 0.88, 1e-8, 8 * nPoints, -1); - double objVal = model->Train(X, Y, opt); + double objVal = model.Train(X, Y, opt); // Test that objective value returned by FFN::Train() is finite. BOOST_REQUIRE_EQUAL(std::isfinite(objVal), true); arma::mat predictionTemp; - model->Predict(X, predictionTemp); + model.Predict(X, predictionTemp); arma::mat prediction = arma::zeros(1, predictionTemp.n_cols); for (size_t i = 0; i < predictionTemp.n_cols; ++i) @@ -123,12 +121,6 @@ BOOST_AUTO_TEST_CASE(VanillaNetworkTest) success = true; break; } - // Test for copy constructor. - FFN, RandomInitialization> model1(*model); - arma::mat prediction1; - delete model; - model1.Predict(X, prediction1); - CheckMatrices(prediction1, predictionTemp); } BOOST_REQUIRE_EQUAL(success, true); diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index 556e9ee04c..31fe165247 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -32,7 +32,7 @@ BOOST_AUTO_TEST_SUITE(FeedForwardNetworkTest); * Train and evaluate a model with the specified structure. */ template -void TestNetwork(ModelType* model, +void TestNetwork(ModelType& model, MatType& trainData, MatType& trainLabels, MatType& testData, @@ -41,10 +41,10 @@ void TestNetwork(ModelType* model, const double classificationErrorThreshold) { ens::RMSProp opt(0.01, 32, 0.88, 1e-8, maxEpochs * trainData.n_cols, -1); - model->Train(trainData, trainLabels, opt); + model.Train(trainData, trainLabels, opt); MatType predictionTemp; - model->Predict(testData, predictionTemp); + model.Predict(testData, predictionTemp); MatType prediction = arma::zeros(1, predictionTemp.n_cols); for (size_t i = 0; i < predictionTemp.n_cols; ++i) @@ -58,22 +58,6 @@ void TestNetwork(ModelType* model, BOOST_REQUIRE_LE(classificationError, classificationErrorThreshold); } -// network1 should be allocated with `new`, and trained on some data. -template -void CheckCopyFunction(ModelType* network1, MatType& inputs) -{ - FFN<> network2(*network1); - arma::mat predictions1; - network1->Predict(inputs, predictions1); - delete network1; - - // Deallocating all of network1's memory, so that - // if network2 is trying to use any of that memory. - arma::mat predictions2; - network2.Predict(inputs, predictions2); - CheckMatrices(predictions1, predictions2); -} - /** * Train the vanilla network on a larger dataset. */ @@ -114,17 +98,16 @@ BOOST_AUTO_TEST_CASE(VanillaNetworkTest) * +-----+ +-----+ */ - FFN > *model = new FFN >(); - model->Add >(trainData.n_rows, 8); - model->Add >(); - model->Add >(8, 3); - model->Add >(); + FFN > model; + model.Add >(trainData.n_rows, 8); + model.Add >(); + model.Add >(8, 3); + model.Add >(); // Vanilla neural net with logistic activation function. // Because 92% of the patients are not hyperthyroid the neural // network must be significant better than 92%. TestNetwork<>(model, trainData, trainLabels, testData, testLabels, 10, 0.1); - CheckCopyFunction(model, testData); arma::mat dataset; dataset.load("mnist_first250_training_4s_and_9s.arm"); @@ -137,14 +120,13 @@ BOOST_AUTO_TEST_CASE(VanillaNetworkTest) labels.submat(0, labels.n_cols / 2, 0, labels.n_cols - 1).fill(1); labels += 1; - FFN > *model1 = new FFN >(); - model1->Add >(dataset.n_rows, 10); - model1->Add >(); - model1->Add >(10, 2); - model1->Add >(); + FFN > model1; + model1.Add >(dataset.n_rows, 10); + model1.Add >(); + model1.Add >(10, 2); + model1.Add >(); // Vanilla neural net with logistic activation function. TestNetwork<>(model1, dataset, labels, dataset, labels, 10, 0.2); - CheckCopyFunction(model1, dataset); } BOOST_AUTO_TEST_CASE(ForwardBackwardTest) @@ -263,19 +245,17 @@ BOOST_AUTO_TEST_CASE(DropoutNetworkTest) * +-----+ */ - FFN > *model = new FFN >(); - model->Add >(trainData.n_rows, 8); - model->Add >(); - model->Add >(); - model->Add >(8, 3); - model->Add >(); + FFN > model; + model.Add >(trainData.n_rows, 8); + model.Add >(); + model.Add >(); + model.Add >(8, 3); + model.Add >(); // Vanilla neural net with logistic activation function. // Because 92% of the patients are not hyperthyroid the neural // network must be significant better than 92%. TestNetwork<>(model, trainData, trainLabels, testData, testLabels, 10, 0.1); - CheckCopyFunction(model, testData); - arma::mat dataset; dataset.load("mnist_first250_training_4s_and_9s.arm"); @@ -289,20 +269,18 @@ BOOST_AUTO_TEST_CASE(DropoutNetworkTest) labels.submat(0, labels.n_cols / 2, 0, labels.n_cols - 1).fill(1); labels += 1; - FFN > *model1 = new FFN >(); - model1->Add >(dataset.n_rows, 10); - model1->Add >(); - model1->Add >(); - model1->Add >(10, 2); - model1->Add >(); + FFN > model1; + model1.Add >(dataset.n_rows, 10); + model1.Add >(); + model.Add >(); + model1.Add >(10, 2); + model1.Add >(); // Vanilla neural net with logistic activation function. TestNetwork<>(model1, dataset, labels, dataset, labels, 10, 0.2); - CheckCopyFunction(model1, dataset); } /** * Train the highway network on a larger dataset. - * */ BOOST_AUTO_TEST_CASE(HighwayNetworkTest) { @@ -317,16 +295,15 @@ BOOST_AUTO_TEST_CASE(HighwayNetworkTest) labels.submat(0, labels.n_cols / 2, 0, labels.n_cols - 1).fill(1); labels += 1; - FFN > *model = new FFN >(); - model->Add >(dataset.n_rows, 10); + FFN > model; + model.Add >(dataset.n_rows, 10); Highway<>* highway = new Highway<>(10, true); highway->Add >(10, 10); highway->Add >(); - model->Add(highway); // This takes ownership of the memory. - model->Add >(10, 2); - model->Add >(); + model.Add(highway); // This takes ownership of the memory. + model.Add >(10, 2); + model.Add >(); TestNetwork<>(model, dataset, labels, dataset, labels, 10, 0.2); - CheckCopyFunction(model, dataset); } /** @@ -371,17 +348,16 @@ BOOST_AUTO_TEST_CASE(DropConnectNetworkTest) * */ - FFN > *model = new FFN >(); - model->Add >(trainData.n_rows, 8); - model->Add >(); - model->Add >(8, 3); - model->Add >(); + FFN > model; + model.Add >(trainData.n_rows, 8); + model.Add >(); + model.Add >(8, 3); + model.Add >(); // Vanilla neural net with logistic activation function. // Because 92% of the patients are not hyperthyroid the neural // network must be significant better than 92%. TestNetwork<>(model, trainData, trainLabels, testData, testLabels, 10, 0.1); - CheckCopyFunction(model, testData); arma::mat dataset; dataset.load("mnist_first250_training_4s_and_9s.arm"); @@ -394,14 +370,13 @@ BOOST_AUTO_TEST_CASE(DropConnectNetworkTest) labels.submat(0, labels.n_cols / 2, 0, labels.n_cols - 1).fill(1); labels += 1; - FFN > *model1 = new FFN >(); - model1->Add >(dataset.n_rows, 10); - model1->Add >(); - model1->Add >(10, 2); - model1->Add >(); + FFN > model1; + model1.Add >(dataset.n_rows, 10); + model1.Add >(); + model1.Add >(10, 2); + model1.Add >(); // Vanilla neural net with logistic activation function. TestNetwork<>(model1, dataset, labels, dataset, labels, 10, 0.2); - CheckCopyFunction(model1, dataset); } /** diff --git a/src/mlpack/tests/gan_test.cpp b/src/mlpack/tests/gan_test.cpp index 7c70c62b73..3705e11570 100644 --- a/src/mlpack/tests/gan_test.cpp +++ b/src/mlpack/tests/gan_test.cpp @@ -348,75 +348,4 @@ BOOST_AUTO_TEST_CASE(GANMemorySharingTest) trainData); } -/* - * Create GAN network and copy of that GAN and - * check whether predictions are same or not. - */ -BOOST_AUTO_TEST_CASE(GANCopyTest) -{ - size_t generatorHiddenLayerSize = 8; - size_t discriminatorHiddenLayerSize = 8; - size_t generatorOutputSize = 1; - size_t discriminatorOutputSize = 1; - size_t discriminatorPreTrain = 0; - size_t batchSize = 8; - size_t noiseDim = 1; - size_t generatorUpdateStep = 1; - double multiplier = 1; - double eps = 1e-8; - double stepSize = 0.0003; - size_t numIterations = 8; - double tolerance = 1e-5; - bool shuffle = true; - - arma::mat trainData(1, 10000); - trainData.imbue( [&]() { return arma::as_scalar(RandNormal(4, 0.5));}); - trainData = arma::sort(trainData); - - // Create the Discriminator network. - FFN > discriminator; - discriminator.Add > ( - generatorOutputSize, discriminatorHiddenLayerSize * 2); - discriminator.Add >(); - discriminator.Add > ( - discriminatorHiddenLayerSize * 2, discriminatorHiddenLayerSize * 2); - discriminator.Add >(); - discriminator.Add > ( - discriminatorHiddenLayerSize * 2, discriminatorHiddenLayerSize * 2); - discriminator.Add >(); - discriminator.Add > ( - discriminatorHiddenLayerSize * 2, discriminatorOutputSize); - - // Create the Generator network. - FFN > generator; - generator.Add >(noiseDim, generatorHiddenLayerSize); - generator.Add >(); - generator.Add >(generatorHiddenLayerSize, generatorOutputSize); - - // Create GAN. - GaussianInitialization gaussian(0, 0.1); - ens::Adam optimizer(stepSize, batchSize, 0.9, 0.999, eps, numIterations, - tolerance, shuffle); - std::function noiseFunction = [](){ return math::Random(-8, 8) + - math::RandNormal(0, 1) * 0.01;}; - GAN >, - GaussianInitialization, - std::function >* gan = new GAN >, - GaussianInitialization, std::function >(generator, - discriminator, gaussian, noiseFunction, noiseDim, batchSize, - generatorUpdateStep, discriminatorPreTrain, multiplier); - - gan->Train(trainData, optimizer); - arma::mat predictions; - gan->Predict(trainData, predictions); - - GAN >, - GaussianInitialization, - std::function >gan2(*gan); - - delete gan; - arma::mat predictions1; - gan2.Predict(trainData, predictions1); - CheckMatrices(predictions, predictions1); -} BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/recurrent_network_test.cpp b/src/mlpack/tests/recurrent_network_test.cpp index 355a47b0ec..00195514f9 100644 --- a/src/mlpack/tests/recurrent_network_test.cpp +++ b/src/mlpack/tests/recurrent_network_test.cpp @@ -516,27 +516,11 @@ arma::Mat GenerateReberGrammarData( return transitions; } -// network1 should be allocated with `new`, and trained on some data. -template -void CheckCopyFunction(ModelType* network1, MatType& inputs) -{ - ModelType network2(*network1); - arma::cube predictions1; - network1->Predict(inputs, predictions1); - delete network1; - - // Deallocating all of network1's memory, so that - // network2 is not trying to use any of that memory. - arma::cube predictions2; - network2.Predict(inputs, predictions2); - CheckMatrices(predictions1, predictions2); -} - /** * Train the specified network and the construct a Reber grammar dataset. */ template -void ReberGrammarTestNetwork(ModelType* model, +void ReberGrammarTestNetwork(ModelType& model, const bool recursive = false, const size_t averageRecursion = 3, const size_t maxRecursion = 5, @@ -583,11 +567,10 @@ void ReberGrammarTestNetwork(ModelType* model, size_t successes = 0; size_t offset = 0; const size_t inputSize = 7; - arma::cube input1; for (size_t trial = 0; trial < trials; ++trial) { // Reset model before using for next trial. - model->Reset(); + model.Reset(); MomentumSGD opt(0.06, 50, 2, -50000); arma::cube inputTemp, labelsTemp; @@ -603,8 +586,8 @@ void ReberGrammarTestNetwork(ModelType* model, labelsTemp = arma::cube(trainLabels.at(0, j).memptr(), inputSize, 1, trainInput.at(0, j).n_elem / inputSize, false, true); - model->Rho() = inputTemp.n_elem / inputSize; - model->Train(inputTemp, labelsTemp, opt); + model.Rho() = inputTemp.n_elem / inputSize; + model.Train(inputTemp, labelsTemp, opt); opt.ResetPolicy() = false; } } @@ -617,10 +600,9 @@ void ReberGrammarTestNetwork(ModelType* model, arma::cube prediction; arma::cube input(testInput.at(0, i).memptr(), inputSize, 1, testInput.at(0, i).n_elem / inputSize, false, true); - input1 = input; - model->Rho() = input.n_elem / inputSize; - model->Predict(input, prediction); + model.Rho() = input.n_elem / inputSize; + model.Predict(input, prediction); const size_t reberGrammerSize = 7; std::string inputReber = ""; @@ -662,7 +644,6 @@ void ReberGrammarTestNetwork(ModelType* model, offset += 3; } - CheckCopyFunction(model, input1); BOOST_REQUIRE_GE(successes, 1); } @@ -672,11 +653,11 @@ void ReberGrammarTestNetwork(ModelType* model, */ BOOST_AUTO_TEST_CASE(LSTMReberGrammarTest) { - RNN > *model = new RNN >(5); - model->Add >(7, 10); - model->Add >(10, 10); - model->Add >(10, 7); - model->Add >(); + RNN > model(5); + model.Add >(7, 10); + model.Add >(10, 10); + model.Add >(10, 7); + model.Add >(); ReberGrammarTestNetwork(model, false); } @@ -685,11 +666,11 @@ BOOST_AUTO_TEST_CASE(LSTMReberGrammarTest) */ BOOST_AUTO_TEST_CASE(FastLSTMReberGrammarTest) { - RNN > *model = new RNN >(5); - model->Add >(7, 8); - model->Add >(8, 8); - model->Add >(8, 7); - model->Add >(); + RNN > model(5); + model.Add >(7, 8); + model.Add >(8, 8); + model.Add >(8, 7); + model.Add >(); ReberGrammarTestNetwork(model, false); } @@ -698,11 +679,11 @@ BOOST_AUTO_TEST_CASE(FastLSTMReberGrammarTest) */ BOOST_AUTO_TEST_CASE(GRURecursiveReberGrammarTest) { - RNN > *model = new RNN >(5); - model->Add >(7, 16); - model->Add >(16, 16); - model->Add >(16, 7); - model->Add >(); + RNN > model(5); + model.Add >(7, 16); + model.Add >(16, 16); + model.Add >(16, 7); + model.Add >(); ReberGrammarTestNetwork(model, true, 3, 5, 10, 7); } @@ -711,12 +692,10 @@ BOOST_AUTO_TEST_CASE(GRURecursiveReberGrammarTest) */ BOOST_AUTO_TEST_CASE(BRNNReberGrammarTest) { - BRNN, - AddMerge<>, SigmoidLayer<> > *model = new - BRNN, AddMerge<>, SigmoidLayer<> >(5); - model->Add >(7, 10); - model->Add >(10, 10); - model->Add >(10, 7); + BRNN, AddMerge<>, SigmoidLayer<> > model(5); + model.Add >(7, 10); + model.Add >(10, 10); + model.Add >(10, 7); ReberGrammarTestNetwork(model, false, 3, 5, 1); }