diff --git a/src/mlpack/methods/ann/ffn.hpp b/src/mlpack/methods/ann/ffn.hpp index f48ebeab18..92581240a6 100644 --- a/src/mlpack/methods/ann/ffn.hpp +++ b/src/mlpack/methods/ann/ffn.hpp @@ -57,7 +57,7 @@ template< * layer. */ template< - typename OutputLayerType = NegativeLogLikelihood<>, + typename OutputLayerType = NegativeLogLikelihood, typename InitializationRuleType = RandomInitialization, typename MatType = arma::mat> class FFN diff --git a/src/mlpack/methods/ann/loss_functions/binary_cross_entropy_loss.hpp b/src/mlpack/methods/ann/loss_functions/binary_cross_entropy_loss.hpp index 16bf533761..510094ec0d 100644 --- a/src/mlpack/methods/ann/loss_functions/binary_cross_entropy_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/binary_cross_entropy_loss.hpp @@ -27,7 +27,7 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class BCELoss +class BCELossType { public: /** @@ -38,7 +38,7 @@ class BCELoss * @param reduction Reduction type. If true, it returns the mean of * the loss. Else, it returns the sum. */ - BCELoss(const double eps = 1e-10, const bool reduction = true); + BCELossType(const double eps = 1e-10, const bool reduction = true); /** * Computes the cross-entropy function. @@ -84,13 +84,17 @@ class BCELoss //! Reduction type. If true, performs mean of loss else sum. bool reduction; -}; // class BCELoss +}; // class BCELossType + +typedef BCELossType BCELoss; /** - * Adding alias of BCELoss. + * Alias of BCELossType. */ +typedef BCELossType CrossEntropyError; + template -using CrossEntropyError = BCELoss; +using CrossEntropyErrorType = BCELossType; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/binary_cross_entropy_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/binary_cross_entropy_loss_impl.hpp index 7d10225e32..bfd85a42ff 100644 --- a/src/mlpack/methods/ann/loss_functions/binary_cross_entropy_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/binary_cross_entropy_loss_impl.hpp @@ -19,14 +19,14 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -BCELoss::BCELoss( +BCELossType::BCELossType( const double eps, const bool reduction) : eps(eps), reduction(reduction) { // Nothing to do here. } template -typename MatType::elem_type BCELoss::Forward( +typename MatType::elem_type BCELossType::Forward( const MatType& prediction, const MatType& target) { @@ -40,7 +40,7 @@ typename MatType::elem_type BCELoss::Forward( } template -void BCELoss::Backward( +void BCELossType::Backward( const MatType& prediction, const MatType& target, MatType& loss) @@ -52,7 +52,7 @@ void BCELoss::Backward( template template -void BCELoss::serialize( +void BCELossType::serialize( Archive& ar, const uint32_t /* version */) { diff --git a/src/mlpack/methods/ann/loss_functions/cosine_embedding_loss.hpp b/src/mlpack/methods/ann/loss_functions/cosine_embedding_loss.hpp index 355a4f97c8..8ef6ab7092 100644 --- a/src/mlpack/methods/ann/loss_functions/cosine_embedding_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/cosine_embedding_loss.hpp @@ -33,11 +33,11 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class CosineEmbeddingLoss +class CosineEmbeddingLossType { public: /** - * Create the CosineEmbeddingLoss object. + * Create the CosineEmbeddingLossType object. * * @param margin Increases cosine distance in case of dissimilarity. * Refer definition of cosine-embedding-loss above. @@ -47,7 +47,7 @@ class CosineEmbeddingLoss * Specifies reduction method i.e. sum or mean corresponding * to 0 and 1 respectively. Default value = 0. */ - CosineEmbeddingLoss(const double margin = 0.0, + CosineEmbeddingLossType(const double margin = 0.0, const bool similarity = true, const bool takeMean = false); @@ -103,7 +103,9 @@ class CosineEmbeddingLoss //! Locally-stored value of takeMean hyper-parameter. bool takeMean; -}; // class CosineEmbeddingLoss +}; // class CosineEmbeddingLossType + +typedef CosineEmbeddingLossType CosineEmbeddingLoss; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/cosine_embedding_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/cosine_embedding_loss_impl.hpp index 96831bb349..0805dda07d 100644 --- a/src/mlpack/methods/ann/loss_functions/cosine_embedding_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/cosine_embedding_loss_impl.hpp @@ -19,7 +19,7 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -CosineEmbeddingLoss::CosineEmbeddingLoss( +CosineEmbeddingLossType::CosineEmbeddingLossType( const double margin, const bool similarity, const bool takeMean): margin(margin), similarity(similarity), takeMean(takeMean) { @@ -27,7 +27,7 @@ CosineEmbeddingLoss::CosineEmbeddingLoss( } template -typename MatType::elem_type CosineEmbeddingLoss::Forward( +typename MatType::elem_type CosineEmbeddingLossType::Forward( const MatType& prediction, const MatType& target) { @@ -63,7 +63,7 @@ typename MatType::elem_type CosineEmbeddingLoss::Forward( } template -void CosineEmbeddingLoss::Backward( +void CosineEmbeddingLossType::Backward( const MatType& prediction, const MatType& target, MatType& loss) @@ -101,7 +101,7 @@ void CosineEmbeddingLoss::Backward( template template -void CosineEmbeddingLoss::serialize( +void CosineEmbeddingLossType::serialize( Archive& ar, const uint32_t /* version */) { ar(CEREAL_NVP(margin)); diff --git a/src/mlpack/methods/ann/loss_functions/dice_loss.hpp b/src/mlpack/methods/ann/loss_functions/dice_loss.hpp index 09449001bb..b7fff35ae3 100644 --- a/src/mlpack/methods/ann/loss_functions/dice_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/dice_loss.hpp @@ -44,15 +44,15 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class DiceLoss +class DiceLossType { public: /** - * Create the DiceLoss object. + * Create the DiceLossType object. * * @param smooth The Laplace smoothing parameter. */ - DiceLoss(const double smooth = 1); + DiceLossType(const double smooth = 1); /** * Computes the dice loss function. @@ -90,7 +90,9 @@ class DiceLoss private: //! The parameter to avoid overfitting. double smooth; -}; // class DiceLoss +}; // class DiceLossType + +typedef DiceLossType DiceLoss; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/dice_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/dice_loss_impl.hpp index 7db4eecce3..a98534d086 100644 --- a/src/mlpack/methods/ann/loss_functions/dice_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/dice_loss_impl.hpp @@ -19,13 +19,13 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -DiceLoss::DiceLoss(const double smooth) : smooth(smooth) +DiceLossType::DiceLossType(const double smooth) : smooth(smooth) { // Nothing to do here. } template -typename MatType::elem_type DiceLoss::Forward( +typename MatType::elem_type DiceLossType::Forward( const MatType& prediction, const MatType& target) { @@ -35,7 +35,7 @@ typename MatType::elem_type DiceLoss::Forward( } template -void DiceLoss::Backward( +void DiceLossType::Backward( const MatType& prediction, const MatType& target, MatType& loss) @@ -49,7 +49,7 @@ void DiceLoss::Backward( template template -void DiceLoss::serialize( +void DiceLossType::serialize( Archive& ar, const uint32_t /* version */) { diff --git a/src/mlpack/methods/ann/loss_functions/earth_mover_distance.hpp b/src/mlpack/methods/ann/loss_functions/earth_mover_distance.hpp index fda2b6432c..341b346650 100644 --- a/src/mlpack/methods/ann/loss_functions/earth_mover_distance.hpp +++ b/src/mlpack/methods/ann/loss_functions/earth_mover_distance.hpp @@ -27,13 +27,13 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class EarthMoverDistance +class EarthMoverDistanceType { public: /** - * Create the EarthMoverDistance object. + * Create the EarthMoverDistanceType object. */ - EarthMoverDistance(); + EarthMoverDistanceType(); /** * Ordinary feed forward pass of a neural network. @@ -61,8 +61,10 @@ class EarthMoverDistance * Serialize the layer. */ template - void serialize(Archive& ar, const uint32_t /* version */); -}; // class EarthMoverDistance + void serialize(Archive& ar, const uint32_t /* version */) { } +}; // class EarthMoverDistanceType + +typedef EarthMoverDistanceType EarthMoverDistance; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/earth_mover_distance_impl.hpp b/src/mlpack/methods/ann/loss_functions/earth_mover_distance_impl.hpp index fbaacb71d5..ad09aff492 100644 --- a/src/mlpack/methods/ann/loss_functions/earth_mover_distance_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/earth_mover_distance_impl.hpp @@ -19,13 +19,13 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -EarthMoverDistance::EarthMoverDistance() +EarthMoverDistanceType::EarthMoverDistanceType() { // Nothing to do here. } template -typename MatType::elem_type EarthMoverDistance::Forward( +typename MatType::elem_type EarthMoverDistanceType::Forward( const MatType& prediction, const MatType& target) { @@ -33,7 +33,7 @@ typename MatType::elem_type EarthMoverDistance::Forward( } template -void EarthMoverDistance::Backward( +void EarthMoverDistanceType::Backward( const MatType& /* prediction */, const MatType& target, MatType& loss) @@ -41,15 +41,6 @@ void EarthMoverDistance::Backward( loss = -target; } -template -template -void EarthMoverDistance::serialize( - Archive& /* ar */, - const uint32_t /* version */) -{ - /* Nothing to do here */ -} - } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/empty_loss.hpp b/src/mlpack/methods/ann/loss_functions/empty_loss.hpp index 391510274a..2b63eaae77 100644 --- a/src/mlpack/methods/ann/loss_functions/empty_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/empty_loss.hpp @@ -29,13 +29,13 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class EmptyLoss +class EmptyLossType { public: /** - * Create the EmptyLoss object. + * Create the EmptyLossType object. */ - EmptyLoss(); + EmptyLossType(); /** * Computes the Empty loss function. @@ -58,10 +58,12 @@ class EmptyLoss const MatType& target, MatType& loss); - //! Serialize the EmptyLoss. + //! Serialize the EmptyLossType. template void serialize(Archive& ar, const uint32_t /* version */) { } -}; // class EmptyLoss +}; // class EmptyLossType + +typedef EmptyLossType EmptyLoss; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/empty_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/empty_loss_impl.hpp index b11f1112a0..1083fbcfea 100644 --- a/src/mlpack/methods/ann/loss_functions/empty_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/empty_loss_impl.hpp @@ -21,20 +21,20 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -EmptyLoss::EmptyLoss() +EmptyLossType::EmptyLossType() { // Nothing to do here. } template -double EmptyLoss::Forward( +double EmptyLossType::Forward( const MatType& /* prediction */, const MatType& /* target */) { return 0; } template -void EmptyLoss::Backward( +void EmptyLossType::Backward( const MatType& /* prediction */, const MatType& target, MatType& loss) diff --git a/src/mlpack/methods/ann/loss_functions/hinge_embedding_loss.hpp b/src/mlpack/methods/ann/loss_functions/hinge_embedding_loss.hpp index 420c336642..3a8c941143 100644 --- a/src/mlpack/methods/ann/loss_functions/hinge_embedding_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/hinge_embedding_loss.hpp @@ -30,13 +30,13 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class HingeEmbeddingLoss +class HingeEmbeddingLossType { public: /** * Create the Hinge Embedding object. */ - HingeEmbeddingLoss(); + HingeEmbeddingLossType(); /** * Computes the Hinge Embedding loss function. @@ -65,7 +65,9 @@ class HingeEmbeddingLoss */ template void serialize(Archive& ar, const uint32_t /* version */) { } -}; // class HingeEmbeddingLoss +}; // class HingeEmbeddingLossType + +typedef HingeEmbeddingLossType HingeEmbeddingLoss; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/hinge_embedding_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/hinge_embedding_loss_impl.hpp index 8053c61129..634302a2b5 100644 --- a/src/mlpack/methods/ann/loss_functions/hinge_embedding_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/hinge_embedding_loss_impl.hpp @@ -20,13 +20,13 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -HingeEmbeddingLoss::HingeEmbeddingLoss() +HingeEmbeddingLossType::HingeEmbeddingLossType() { // Nothing to do here. } template -typename MatType::elem_type HingeEmbeddingLoss::Forward( +typename MatType::elem_type HingeEmbeddingLossType::Forward( const MatType& prediction, const MatType& target) { @@ -35,7 +35,7 @@ typename MatType::elem_type HingeEmbeddingLoss::Forward( } template -void HingeEmbeddingLoss::Backward( +void HingeEmbeddingLossType::Backward( const MatType& prediction, const MatType& target, MatType& loss) diff --git a/src/mlpack/methods/ann/loss_functions/hinge_loss.hpp b/src/mlpack/methods/ann/loss_functions/hinge_loss.hpp index 35afee9d88..53a67710f0 100644 --- a/src/mlpack/methods/ann/loss_functions/hinge_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/hinge_loss.hpp @@ -31,11 +31,11 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class HingeLoss +class HingeLossType { public: /** - * Create HingeLoss object. + * Create HingeLossType object. * * @param reduction Specifies the reduction to apply to the output. If false, * 'mean' reduction is used, where sum of the output will be @@ -43,7 +43,7 @@ class HingeLoss * true, 'sum' reduction is used and the output will be * summed. It is set to true by default. */ - HingeLoss(const bool reduction = true); + HingeLossType(const bool reduction = true); /** * Computes the Hinge loss function. @@ -81,7 +81,9 @@ class HingeLoss private: //! The boolean value that tells if reduction is sum or mean. bool reduction; -}; // class HingeLoss +}; // class HingeLossType + +typedef HingeLossType HingeLoss; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/hinge_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/hinge_loss_impl.hpp index b26f188766..05403e32e8 100644 --- a/src/mlpack/methods/ann/loss_functions/hinge_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/hinge_loss_impl.hpp @@ -20,14 +20,14 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -HingeLoss::HingeLoss(const bool reduction): +HingeLossType::HingeLossType(const bool reduction): reduction(reduction) { // Nothing to do here. } template -typename MatType::elem_type HingeLoss::Forward( +typename MatType::elem_type HingeLossType::Forward( const MatType& prediction, const MatType& target) { @@ -45,7 +45,7 @@ typename MatType::elem_type HingeLoss::Forward( } template -void HingeLoss::Backward( +void HingeLossType::Backward( const MatType& prediction, const MatType& target, MatType& loss) @@ -59,7 +59,7 @@ void HingeLoss::Backward( template template -void HingeLoss::serialize( +void HingeLossType::serialize( Archive& ar, const uint32_t /* version */) { diff --git a/src/mlpack/methods/ann/loss_functions/huber_loss.hpp b/src/mlpack/methods/ann/loss_functions/huber_loss.hpp index 3c001951b8..22f71f0d25 100644 --- a/src/mlpack/methods/ann/loss_functions/huber_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/huber_loss.hpp @@ -30,17 +30,17 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class HuberLoss +class HuberLossType { public: /** - * Create the HuberLoss object. + * Create the HuberLossType object. * * @param delta The threshold value upto which squared error is followed and * after which absolute error is considered. * @param mean If true then mean loss is computed otherwise sum. */ - HuberLoss(const double delta = 1.0, const bool mean = true); + HuberLossType(const double delta = 1.0, const bool mean = true); /** * Computes the Huber Loss function. @@ -86,7 +86,9 @@ class HuberLoss //! Reduction type. If true, performs mean of loss else sum. bool mean; -}; // class HuberLoss +}; // class HuberLossType + +typedef HuberLossType HuberLoss; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/huber_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/huber_loss_impl.hpp index 9e008a656b..3d71f9b4ae 100644 --- a/src/mlpack/methods/ann/loss_functions/huber_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/huber_loss_impl.hpp @@ -19,7 +19,7 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -HuberLoss::HuberLoss( +HuberLossType::HuberLossType( const double delta, const bool mean): delta(delta), @@ -29,7 +29,7 @@ HuberLoss::HuberLoss( } template -typename MatType::elem_type HuberLoss::Forward( +typename MatType::elem_type HuberLossType::Forward( const MatType& prediction, const MatType& target) { @@ -45,7 +45,7 @@ typename MatType::elem_type HuberLoss::Forward( } template -void HuberLoss::Backward( +void HuberLossType::Backward( const MatType& prediction, const MatType& target, MatType& loss) @@ -66,7 +66,7 @@ void HuberLoss::Backward( template template -void HuberLoss::serialize( +void HuberLossType::serialize( Archive& ar, const uint32_t /* version */) { diff --git a/src/mlpack/methods/ann/loss_functions/kl_divergence.hpp b/src/mlpack/methods/ann/loss_functions/kl_divergence.hpp index 8fe6e3a08e..a96f58e6ca 100644 --- a/src/mlpack/methods/ann/loss_functions/kl_divergence.hpp +++ b/src/mlpack/methods/ann/loss_functions/kl_divergence.hpp @@ -39,7 +39,7 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class KLDivergence +class KLDivergenceType { public: /** @@ -48,7 +48,7 @@ class KLDivergence * * @param takeMean Boolean variable to specify whether to take mean or not. */ - KLDivergence(const bool takeMean = false); + KLDivergenceType(const bool takeMean = false); /** * Computes the Kullback–Leibler divergence error function. @@ -86,7 +86,9 @@ class KLDivergence private: //! Boolean variable for taking mean or not. bool takeMean; -}; // class KLDivergence +}; // class KLDivergenceType + +typedef KLDivergenceType KLDivergence; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/kl_divergence_impl.hpp b/src/mlpack/methods/ann/loss_functions/kl_divergence_impl.hpp index 1811cd9fef..0962f337ec 100644 --- a/src/mlpack/methods/ann/loss_functions/kl_divergence_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/kl_divergence_impl.hpp @@ -20,14 +20,14 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -KLDivergence::KLDivergence(const bool takeMean) : +KLDivergenceType::KLDivergenceType(const bool takeMean) : takeMean(takeMean) { // Nothing to do here. } template -typename MatType::elem_type KLDivergence::Forward( +typename MatType::elem_type KLDivergenceType::Forward( const MatType& prediction, const MatType& target) { @@ -43,7 +43,7 @@ typename MatType::elem_type KLDivergence::Forward( } template -void KLDivergence::Backward( +void KLDivergenceType::Backward( const MatType& prediction, const MatType& target, MatType& loss) @@ -61,7 +61,7 @@ void KLDivergence::Backward( template template -void KLDivergence::serialize( +void KLDivergenceType::serialize( Archive& ar, const uint32_t /* version */) { diff --git a/src/mlpack/methods/ann/loss_functions/l1_loss.hpp b/src/mlpack/methods/ann/loss_functions/l1_loss.hpp index 4b5edcd787..f094e70048 100644 --- a/src/mlpack/methods/ann/loss_functions/l1_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/l1_loss.hpp @@ -27,16 +27,16 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class L1Loss +class L1LossType { public: /** - * Create the L1Loss object. + * Create the L1LossType object. * * @param mean Reduction type. If true, it returns the mean of * the loss. Else, it returns the sum. */ - L1Loss(const bool mean = true); + L1LossType(const bool mean = true); /** * Computes the L1 Loss function. @@ -74,7 +74,9 @@ class L1Loss private: //! Reduction type. If true, performs mean of loss else sum. bool mean; -}; // class L1Loss +}; // class L1LossType + +typedef L1LossType L1Loss; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/l1_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/l1_loss_impl.hpp index 6f823e3bd5..98cdcd5753 100644 --- a/src/mlpack/methods/ann/loss_functions/l1_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/l1_loss_impl.hpp @@ -19,14 +19,14 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -L1Loss::L1Loss(const bool mean): +L1LossType::L1LossType(const bool mean): mean(mean) { // Nothing to do here. } template -typename MatType::elem_type L1Loss::Forward( +typename MatType::elem_type L1LossType::Forward( const MatType& prediction, const MatType& target) { @@ -37,7 +37,7 @@ typename MatType::elem_type L1Loss::Forward( } template -void L1Loss::Backward( +void L1LossType::Backward( const MatType& prediction, const MatType& target, MatType& loss) @@ -47,7 +47,7 @@ void L1Loss::Backward( template template -void L1Loss::serialize( +void L1LossType::serialize( Archive& ar, const uint32_t /* version */) { diff --git a/src/mlpack/methods/ann/loss_functions/log_cosh_loss.hpp b/src/mlpack/methods/ann/loss_functions/log_cosh_loss.hpp index ed533cd06f..462b362da5 100644 --- a/src/mlpack/methods/ann/loss_functions/log_cosh_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/log_cosh_loss.hpp @@ -29,7 +29,7 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class LogCoshLoss +class LogCoshLossType { public: /** @@ -43,7 +43,7 @@ class LogCoshLoss * function more sensitive to small losses around the * origin. Default value = 1.0. */ - LogCoshLoss(const double a = 1.0); + LogCoshLossType(const double a = 1.0); /** * Computes the Log-Hyperbolic-Cosine loss function. @@ -81,7 +81,9 @@ class LogCoshLoss private: //! Hyperparameter a for smoothening function curve. double a; -}; // class LogCoshLoss +}; // class LogCoshLossType + +typedef LogCoshLossType LogCoshLoss; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/log_cosh_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/log_cosh_loss_impl.hpp index b448427f32..0e50f56896 100644 --- a/src/mlpack/methods/ann/loss_functions/log_cosh_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/log_cosh_loss_impl.hpp @@ -20,14 +20,14 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -LogCoshLoss::LogCoshLoss(const double a) : +LogCoshLossType::LogCoshLossType(const double a) : a(a) { Log::Assert(a > 0, "Hyper-Parameter \'a\' must be positive"); } template -typename MatType::elem_type LogCoshLoss::Forward( +typename MatType::elem_type LogCoshLossType::Forward( const MatType& prediction, const MatType& target) { @@ -35,7 +35,7 @@ typename MatType::elem_type LogCoshLoss::Forward( } template -void LogCoshLoss::Backward( +void LogCoshLossType::Backward( const MatType& prediction, const MatType& target, MatType& loss) @@ -45,7 +45,7 @@ void LogCoshLoss::Backward( template template -void LogCoshLoss::serialize( +void LogCoshLossType::serialize( Archive& ar, const uint32_t /* version */) { diff --git a/src/mlpack/methods/ann/loss_functions/margin_ranking_loss.hpp b/src/mlpack/methods/ann/loss_functions/margin_ranking_loss.hpp index bd82960d60..4617fcafbd 100644 --- a/src/mlpack/methods/ann/loss_functions/margin_ranking_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/margin_ranking_loss.hpp @@ -29,15 +29,15 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class MarginRankingLoss +class MarginRankingLossType { public: /** - * Create the MarginRankingLoss object with Hyperparameter margin. + * Create the MarginRankingLossType object with Hyperparameter margin. * Hyperparameter margin defines a minimum distance between correctly ranked * samples. */ - MarginRankingLoss(const double margin = 1.0); + MarginRankingLossType(const double margin = 1.0); /** * Computes the Margin Ranking Loss function. @@ -75,7 +75,9 @@ class MarginRankingLoss private: //! The margin value used in calculating Margin Ranking Loss. double margin; -}; // class MarginRankingLoss +}; // class MarginRankingLossType + +typedef MarginRankingLossType MarginRankingLoss; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/margin_ranking_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/margin_ranking_loss_impl.hpp index 79a932e0f3..72c7aa67c8 100644 --- a/src/mlpack/methods/ann/loss_functions/margin_ranking_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/margin_ranking_loss_impl.hpp @@ -19,14 +19,14 @@ namespace mlpack { namespace ann /** Artifical Neural Network. */ { template -MarginRankingLoss::MarginRankingLoss( +MarginRankingLossType::MarginRankingLossType( const double margin) : margin(margin) { // Nothing to do here. } template -typename MatType::elem_type MarginRankingLoss::Forward( +typename MatType::elem_type MarginRankingLossType::Forward( const MatType& prediction, const MatType& target) { @@ -40,7 +40,7 @@ typename MatType::elem_type MarginRankingLoss::Forward( } template -void MarginRankingLoss::Backward( +void MarginRankingLossType::Backward( const MatType& prediction, const MatType& target, MatType& loss) @@ -58,7 +58,7 @@ void MarginRankingLoss::Backward( template template -void MarginRankingLoss::serialize( +void MarginRankingLossType::serialize( Archive& ar, const uint32_t /* version */) { diff --git a/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error.hpp b/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error.hpp index 0edc341125..23ab49bf57 100644 --- a/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error.hpp +++ b/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error.hpp @@ -43,13 +43,13 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class MeanAbsolutePercentageError +class MeanAbsolutePercentageErrorType { public: /** - * Create the MeanAbsolutePercentageError object. + * Create the MeanAbsolutePercentageErrorType object. */ - MeanAbsolutePercentageError(); + MeanAbsolutePercentageErrorType(); /** * Computes the mean absolute percentage error function. @@ -78,7 +78,9 @@ class MeanAbsolutePercentageError */ template void serialize(Archive& ar, const unsigned int /* version */) { } -}; // class MeanAbsolutePercentageError +}; // class MeanAbsolutePercentageErrorType + +typedef MeanAbsolutePercentageErrorType MeanAbsolutePercentageError; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp b/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp index 6e6eb4e1d1..8185de852d 100644 --- a/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp @@ -19,13 +19,13 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -MeanAbsolutePercentageError::MeanAbsolutePercentageError() +MeanAbsolutePercentageErrorType::MeanAbsolutePercentageErrorType() { // Nothing to do here. } template -typename MatType::elem_type MeanAbsolutePercentageError::Forward( +typename MatType::elem_type MeanAbsolutePercentageErrorType::Forward( const MatType& prediction, const MatType& target) { @@ -34,7 +34,7 @@ typename MatType::elem_type MeanAbsolutePercentageError::Forward( } template -void MeanAbsolutePercentageError::Backward( +void MeanAbsolutePercentageErrorType::Backward( const MatType& prediction, const MatType& target, MatType& loss) diff --git a/src/mlpack/methods/ann/loss_functions/mean_bias_error.hpp b/src/mlpack/methods/ann/loss_functions/mean_bias_error.hpp index ac38a41f64..9bc1008240 100644 --- a/src/mlpack/methods/ann/loss_functions/mean_bias_error.hpp +++ b/src/mlpack/methods/ann/loss_functions/mean_bias_error.hpp @@ -27,13 +27,13 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class MeanBiasError +class MeanBiasErrorType { public: /** - * Create the MeanBiasError object. + * Create the MeanBiasErrorType object. */ - MeanBiasError(); + MeanBiasErrorType(); /** * Computes the mean bias error function. @@ -62,7 +62,9 @@ class MeanBiasError */ template void serialize(Archive& ar, const uint32_t /* version */); -}; // class MeanBiasError +}; // class MeanBiasErrorType + +typedef MeanBiasErrorType MeanBiasError; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/mean_bias_error_impl.hpp b/src/mlpack/methods/ann/loss_functions/mean_bias_error_impl.hpp index 4fae518ecf..cd1a0c5d97 100644 --- a/src/mlpack/methods/ann/loss_functions/mean_bias_error_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/mean_bias_error_impl.hpp @@ -20,13 +20,13 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -MeanBiasError::MeanBiasError() +MeanBiasErrorType::MeanBiasErrorType() { // Nothing to do here. } template -typename MatType::elem_type MeanBiasError::Forward( +typename MatType::elem_type MeanBiasErrorType::Forward( const MatType& prediction, const MatType& target) { @@ -34,7 +34,7 @@ typename MatType::elem_type MeanBiasError::Forward( } template -void MeanBiasError::Backward( +void MeanBiasErrorType::Backward( const MatType& prediction, const MatType& /* target */, MatType& loss) diff --git a/src/mlpack/methods/ann/loss_functions/mean_squared_error.hpp b/src/mlpack/methods/ann/loss_functions/mean_squared_error.hpp index 780d1e9c0f..1097333022 100644 --- a/src/mlpack/methods/ann/loss_functions/mean_squared_error.hpp +++ b/src/mlpack/methods/ann/loss_functions/mean_squared_error.hpp @@ -28,13 +28,13 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class MeanSquaredError +class MeanSquaredErrorType { public: /** - * Create the MeanSquaredError object. + * Create the MeanSquaredErrorType object. */ - MeanSquaredError(); + MeanSquaredErrorType(); /** * Computes the mean squared error function. @@ -63,7 +63,9 @@ class MeanSquaredError */ template void serialize(Archive& ar, const uint32_t /* version */) { } -}; // class MeanSquaredError +}; // class MeanSquaredErrorType + +typedef MeanSquaredErrorType MeanSquaredError; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/mean_squared_error_impl.hpp b/src/mlpack/methods/ann/loss_functions/mean_squared_error_impl.hpp index 663891e55b..0c5e91e361 100644 --- a/src/mlpack/methods/ann/loss_functions/mean_squared_error_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/mean_squared_error_impl.hpp @@ -19,13 +19,13 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -MeanSquaredError::MeanSquaredError() +MeanSquaredErrorType::MeanSquaredErrorType() { // Nothing to do here. } template -typename MatType::elem_type MeanSquaredError::Forward( +typename MatType::elem_type MeanSquaredErrorType::Forward( const MatType& prediction, const MatType& target) { @@ -33,7 +33,7 @@ typename MatType::elem_type MeanSquaredError::Forward( } template -void MeanSquaredError::Backward( +void MeanSquaredErrorType::Backward( const MatType& prediction, const MatType& target, MatType& loss) diff --git a/src/mlpack/methods/ann/loss_functions/mean_squared_logarithmic_error.hpp b/src/mlpack/methods/ann/loss_functions/mean_squared_logarithmic_error.hpp index aa0ef4f7d5..cb00e6a3ee 100644 --- a/src/mlpack/methods/ann/loss_functions/mean_squared_logarithmic_error.hpp +++ b/src/mlpack/methods/ann/loss_functions/mean_squared_logarithmic_error.hpp @@ -27,13 +27,13 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class MeanSquaredLogarithmicError +class MeanSquaredLogarithmicErrorType { public: /** - * Create the MeanSquaredLogarithmicError object. + * Create the MeanSquaredLogarithmicErrorType object. */ - MeanSquaredLogarithmicError(); + MeanSquaredLogarithmicErrorType(); /** * Computes the mean squared logarithmic error function. @@ -62,7 +62,9 @@ class MeanSquaredLogarithmicError */ template void serialize(Archive& ar, const uint32_t /* version */) { } -}; // class MeanSquaredLogarithmicError +}; // class MeanSquaredLogarithmicErrorType + +typedef MeanSquaredLogarithmicErrorType MeanSquaredLogarithmicError; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/mean_squared_logarithmic_error_impl.hpp b/src/mlpack/methods/ann/loss_functions/mean_squared_logarithmic_error_impl.hpp index ddc19c75b4..2feedfe139 100644 --- a/src/mlpack/methods/ann/loss_functions/mean_squared_logarithmic_error_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/mean_squared_logarithmic_error_impl.hpp @@ -19,14 +19,13 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -MeanSquaredLogarithmicError -::MeanSquaredLogarithmicError() +MeanSquaredLogarithmicErrorType::MeanSquaredLogarithmicErrorType() { // Nothing to do here. } template -typename MatType::elem_type MeanSquaredLogarithmicError::Forward( +typename MatType::elem_type MeanSquaredLogarithmicErrorType::Forward( const MatType& prediction, const MatType& target) { @@ -35,7 +34,7 @@ typename MatType::elem_type MeanSquaredLogarithmicError::Forward( } template -void MeanSquaredLogarithmicError::Backward( +void MeanSquaredLogarithmicErrorType::Backward( const MatType& prediction, const MatType& target, MatType& loss) diff --git a/src/mlpack/methods/ann/loss_functions/multilabel_softmargin_loss.hpp b/src/mlpack/methods/ann/loss_functions/multilabel_softmargin_loss.hpp index 0631c4ed31..97aa19ae71 100644 --- a/src/mlpack/methods/ann/loss_functions/multilabel_softmargin_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/multilabel_softmargin_loss.hpp @@ -28,11 +28,11 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class MultiLabelSoftMarginLoss +class MultiLabelSoftMarginLossType { public: /** - * Create the MultiLabelSoftMarginLoss object. + * Create the MultiLabelSoftMarginLossType object. * * @param reduction Specifies the reduction to apply to the output. If false, * 'mean' reduction is used, where sum of the output will be @@ -42,7 +42,7 @@ class MultiLabelSoftMarginLoss * @param weights A manual rescaling weight given to each class. It is a * (1, numClasses) row vector. */ - MultiLabelSoftMarginLoss( + MultiLabelSoftMarginLossType( const bool reduction = true, const arma::Row& weights = arma::Row()); @@ -98,7 +98,9 @@ class MultiLabelSoftMarginLoss // An internal parameter used during initialisation of class weights. bool weighted; -}; // class MultiLabelSoftMarginLoss +}; // class MultiLabelSoftMarginLossType + +typedef MultiLabelSoftMarginLossType MultiLabelSoftMarginLoss; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/multilabel_softmargin_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/multilabel_softmargin_loss_impl.hpp index 2b9c073273..453254f100 100644 --- a/src/mlpack/methods/ann/loss_functions/multilabel_softmargin_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/multilabel_softmargin_loss_impl.hpp @@ -19,7 +19,7 @@ namespace mlpack { namespace ann /** Artifical Neural Network. */ { template -MultiLabelSoftMarginLoss::MultiLabelSoftMarginLoss( +MultiLabelSoftMarginLossType::MultiLabelSoftMarginLossType( const bool reduction, const arma::Row& weights) : reduction(reduction), @@ -33,7 +33,7 @@ MultiLabelSoftMarginLoss::MultiLabelSoftMarginLoss( } template -typename MatType::elem_type MultiLabelSoftMarginLoss::Forward( +typename MatType::elem_type MultiLabelSoftMarginLossType::Forward( const MatType& input, const MatType& target) { if (!weighted) @@ -54,7 +54,7 @@ typename MatType::elem_type MultiLabelSoftMarginLoss::Forward( } template -void MultiLabelSoftMarginLoss::Backward( +void MultiLabelSoftMarginLossType::Backward( const MatType& input, const MatType& target, MatType& output) @@ -70,7 +70,7 @@ void MultiLabelSoftMarginLoss::Backward( template template -void MultiLabelSoftMarginLoss::serialize( +void MultiLabelSoftMarginLossType::serialize( Archive& ar, const unsigned int /* version */) { diff --git a/src/mlpack/methods/ann/loss_functions/negative_log_likelihood.hpp b/src/mlpack/methods/ann/loss_functions/negative_log_likelihood.hpp index 530c42308b..314794d58c 100644 --- a/src/mlpack/methods/ann/loss_functions/negative_log_likelihood.hpp +++ b/src/mlpack/methods/ann/loss_functions/negative_log_likelihood.hpp @@ -2,7 +2,7 @@ * @file methods/ann/loss_functions/negative_log_likelihood.hpp * @author Marcus Edel * - * Definition of the NegativeLogLikelihood class. + * Definition of the NegativeLogLikelihoodType class. * * mlpack is free software; you may redistribute it and/or modify it under the * terms of the 3-clause BSD license. You should have received a copy of the @@ -29,13 +29,13 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class NegativeLogLikelihood +class NegativeLogLikelihoodType { public: /** - * Create the NegativeLogLikelihoodLayer object. + * Create the NegativeLogLikelihoodTypeLayer object. */ - NegativeLogLikelihood(); + NegativeLogLikelihoodType(); /** * Computes the Negative log likelihood. @@ -69,7 +69,9 @@ class NegativeLogLikelihood */ template void serialize(Archive& /* ar */, const uint32_t /* version */) { } -}; // class NegativeLogLikelihood +}; // class NegativeLogLikelihoodType + +typedef NegativeLogLikelihoodType NegativeLogLikelihood; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/negative_log_likelihood_impl.hpp b/src/mlpack/methods/ann/loss_functions/negative_log_likelihood_impl.hpp index c85f806893..3159aa629a 100644 --- a/src/mlpack/methods/ann/loss_functions/negative_log_likelihood_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/negative_log_likelihood_impl.hpp @@ -2,7 +2,7 @@ * @file methods/ann/loss_functions/negative_log_likelihood_impl.hpp * @author Marcus Edel * - * Implementation of the NegativeLogLikelihood class. + * Implementation of the NegativeLogLikelihoodType class. * * mlpack is free software; you may redistribute it and/or modify it under the * terms of the 3-clause BSD license. You should have received a copy of the @@ -19,13 +19,13 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -NegativeLogLikelihood::NegativeLogLikelihood() +NegativeLogLikelihoodType::NegativeLogLikelihoodType() { // Nothing to do here. } template -double NegativeLogLikelihood::Forward( +double NegativeLogLikelihoodType::Forward( const MatType& prediction, const MatType& target) { @@ -42,7 +42,7 @@ double NegativeLogLikelihood::Forward( } template -void NegativeLogLikelihood::Backward( +void NegativeLogLikelihoodType::Backward( const MatType& prediction, const MatType& target, MatType& loss) diff --git a/src/mlpack/methods/ann/loss_functions/poisson_nll_loss.hpp b/src/mlpack/methods/ann/loss_functions/poisson_nll_loss.hpp index 6f6bcaea6e..c1d03568a6 100644 --- a/src/mlpack/methods/ann/loss_functions/poisson_nll_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/poisson_nll_loss.hpp @@ -2,7 +2,7 @@ * @file methods/ann/loss_functions/poisson_nll_loss.hpp * @author Mrityunjay Tripathi * - * Definition of the PoissonNLLLoss class. It is the negative log likelihood of + * Definition of the PoissonNLLLossType class. It is the negative log likelihood of * the Poisson distribution. * * mlpack is free software; you may redistribute it and/or modify it under the @@ -30,11 +30,11 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class PoissonNLLLoss +class PoissonNLLLossType { public: /** - * Create the PoissonNLLLoss object. + * Create the PoissonNLLLossType object. * * @param logInput If true the loss is computed as * \f$ \exp(input) - target \cdot input \f$, if false then the loss is @@ -44,7 +44,7 @@ class PoissonNLLLoss * @param eps A small value to prevent 0 in denominators and logarithms. * @param mean When true, mean loss is computed otherwise total loss. */ - PoissonNLLLoss(const bool logInput = true, + PoissonNLLLossType(const bool logInput = true, const bool full = false, const typename MatType::elem_type eps = 1e-08, const bool mean = true); @@ -135,7 +135,9 @@ class PoissonNLLLoss //! Boolean value that tells if mean of the total loss has to be taken. bool mean; -}; // class PoissonNLLLoss +}; // class PoissonNLLLossType + +typedef PoissonNLLLossType PoissonNLLLoss; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/poisson_nll_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/poisson_nll_loss_impl.hpp index c1b9ef54c8..aaf1951117 100644 --- a/src/mlpack/methods/ann/loss_functions/poisson_nll_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/poisson_nll_loss_impl.hpp @@ -2,7 +2,7 @@ * @file methods/ann/loss_functions/poisson_nll_loss_impl.hpp * @author Mrityunjay Tripathi * - * Implementation of the PoissonNLLLoss class. + * Implementation of the PoissonNLLLossType class. * * mlpack is free software; you may redistribute it and/or modify it under the * terms of the 3-clause BSD license. You should have received a copy of the @@ -20,7 +20,7 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -PoissonNLLLoss::PoissonNLLLoss( +PoissonNLLLossType::PoissonNLLLossType( const bool logInput, const bool full, const typename MatType::elem_type eps, @@ -34,7 +34,7 @@ PoissonNLLLoss::PoissonNLLLoss( } template -typename MatType::elem_type PoissonNLLLoss::Forward( +typename MatType::elem_type PoissonNLLLossType::Forward( const MatType& prediction, const MatType& target) { @@ -60,7 +60,7 @@ typename MatType::elem_type PoissonNLLLoss::Forward( } template -void PoissonNLLLoss::Backward( +void PoissonNLLLossType::Backward( const MatType& prediction, const MatType& target, MatType& loss) @@ -78,7 +78,7 @@ void PoissonNLLLoss::Backward( template template -void PoissonNLLLoss::serialize( +void PoissonNLLLossType::serialize( Archive& ar, const uint32_t /* version */) { diff --git a/src/mlpack/methods/ann/loss_functions/reconstruction_loss.hpp b/src/mlpack/methods/ann/loss_functions/reconstruction_loss.hpp index 5490be5567..b9c2abce90 100644 --- a/src/mlpack/methods/ann/loss_functions/reconstruction_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/reconstruction_loss.hpp @@ -33,13 +33,13 @@ template< typename MatType = arma::mat, typename DistType = BernoulliDistribution > -class ReconstructionLoss +class ReconstructionLossType { public: /** - * Create the ReconstructionLoss object. + * Create the ReconstructionLossType object. */ - ReconstructionLoss(); + ReconstructionLossType(); /** * Computes the reconstruction loss. @@ -72,7 +72,9 @@ class ReconstructionLoss private: //! Locally-stored distribution object. DistType dist; -}; // class ReconstructionLoss +}; // class ReconstructionLossType + +typedef ReconstructionLossType ReconstructionLoss; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/reconstruction_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/reconstruction_loss_impl.hpp index e7b760a157..2c361029e6 100644 --- a/src/mlpack/methods/ann/loss_functions/reconstruction_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/reconstruction_loss_impl.hpp @@ -19,13 +19,13 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -ReconstructionLoss::ReconstructionLoss() +ReconstructionLossType::ReconstructionLossType() { // Nothing to do here. } template -typename MatType::elem_type ReconstructionLoss::Forward( +typename MatType::elem_type ReconstructionLossType::Forward( const MatType& prediction, const MatType& target) { dist = DistType(prediction); @@ -33,7 +33,7 @@ typename MatType::elem_type ReconstructionLoss::Forward( } template -void ReconstructionLoss::Backward( +void ReconstructionLossType::Backward( const MatType& /* prediction */, const MatType& target, MatType& loss) @@ -44,7 +44,7 @@ void ReconstructionLoss::Backward( template template -void ReconstructionLoss::serialize( +void ReconstructionLossType::serialize( Archive& ar, const uint32_t /* version */) { diff --git a/src/mlpack/methods/ann/loss_functions/sigmoid_cross_entropy_error.hpp b/src/mlpack/methods/ann/loss_functions/sigmoid_cross_entropy_error.hpp index 2d6a6917e0..0ea11fb331 100644 --- a/src/mlpack/methods/ann/loss_functions/sigmoid_cross_entropy_error.hpp +++ b/src/mlpack/methods/ann/loss_functions/sigmoid_cross_entropy_error.hpp @@ -19,7 +19,7 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { /** - * The SigmoidCrossEntropyError performance function measures the network's + * The SigmoidCrossEntropyErrorType performance function measures the network's * performance according to the cross-entropy function between the input and * target distributions. This function calculates the cross entropy * given the real values instead of providing the sigmoid activations. @@ -46,13 +46,13 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class SigmoidCrossEntropyError +class SigmoidCrossEntropyErrorType { public: /** - * Create the SigmoidCrossEntropyError object. + * Create the SigmoidCrossEntropyErrorType object. */ - SigmoidCrossEntropyError(); + SigmoidCrossEntropyErrorType(); /** * Computes the Sigmoid CrossEntropy Error functions. @@ -82,7 +82,9 @@ class SigmoidCrossEntropyError */ template void serialize(Archive& ar, const uint32_t /* version */) { } -}; // class SigmoidCrossEntropy +}; // class SigmoidCrossEntropyErrorType + +typedef SigmoidCrossEntropyErrorType SigmoidCrossEntropyError; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/sigmoid_cross_entropy_error_impl.hpp b/src/mlpack/methods/ann/loss_functions/sigmoid_cross_entropy_error_impl.hpp index 39bc3babbf..aac692528d 100644 --- a/src/mlpack/methods/ann/loss_functions/sigmoid_cross_entropy_error_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/sigmoid_cross_entropy_error_impl.hpp @@ -21,13 +21,14 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -SigmoidCrossEntropyError::SigmoidCrossEntropyError() +SigmoidCrossEntropyErrorType::SigmoidCrossEntropyErrorType() { // Nothing to do here. } template -inline typename MatType::elem_type SigmoidCrossEntropyError::Forward( +inline typename MatType::elem_type +SigmoidCrossEntropyErrorType::Forward( const MatType& prediction, const MatType& target) { @@ -43,7 +44,7 @@ inline typename MatType::elem_type SigmoidCrossEntropyError::Forward( } template -inline void SigmoidCrossEntropyError::Backward( +inline void SigmoidCrossEntropyErrorType::Backward( const MatType& prediction, const MatType& target, MatType& loss) diff --git a/src/mlpack/methods/ann/loss_functions/soft_margin_loss.hpp b/src/mlpack/methods/ann/loss_functions/soft_margin_loss.hpp index 17fdd0b70a..85d273e602 100644 --- a/src/mlpack/methods/ann/loss_functions/soft_margin_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/soft_margin_loss.hpp @@ -28,11 +28,11 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class SoftMarginLoss +class SoftMarginLossType { public: /** - * Create the SoftMarginLoss object. + * Create the SoftMarginLossType object. * * @param reduction Specifies the reduction to apply to the output. If false, * 'mean' reduction is used, where sum of the output will be @@ -40,7 +40,7 @@ class SoftMarginLoss * true, 'sum' reduction is used and the output will be * summed. It is set to true by default. */ - SoftMarginLoss(const bool reduction = true); + SoftMarginLossType(const bool reduction = true); /** * Computes the Soft Margin Loss function. @@ -78,7 +78,9 @@ class SoftMarginLoss private: //! The boolean value that tells if reduction is sum or mean. bool reduction; -}; // class SoftMarginLoss +}; // class SoftMarginLossType + +typedef SoftMarginLossType SoftMarginLoss; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/soft_margin_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/soft_margin_loss_impl.hpp index aeef70998a..36908ac99e 100644 --- a/src/mlpack/methods/ann/loss_functions/soft_margin_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/soft_margin_loss_impl.hpp @@ -19,14 +19,14 @@ namespace mlpack { namespace ann /** Artifical Neural Network. */ { template -SoftMarginLoss:: -SoftMarginLoss(const bool reduction) : reduction(reduction) +SoftMarginLossType:: +SoftMarginLossType(const bool reduction) : reduction(reduction) { // Nothing to do here. } template -typename MatType::elem_type SoftMarginLoss::Forward( +typename MatType::elem_type SoftMarginLossType::Forward( const MatType& prediction, const MatType& target) { MatType loss = arma::log(1 + arma::exp(-target % prediction)); @@ -39,7 +39,7 @@ typename MatType::elem_type SoftMarginLoss::Forward( } template -void SoftMarginLoss::Backward( +void SoftMarginLossType::Backward( const MatType& prediction, const MatType& target, MatType& loss) @@ -56,7 +56,7 @@ void SoftMarginLoss::Backward( template template -void SoftMarginLoss::serialize( +void SoftMarginLossType::serialize( Archive& ar, const uint32_t /* version */) { ar(CEREAL_NVP(reduction)); diff --git a/src/mlpack/methods/ann/loss_functions/triplet_margin_loss.hpp b/src/mlpack/methods/ann/loss_functions/triplet_margin_loss.hpp index bc4034858d..923e1becc6 100644 --- a/src/mlpack/methods/ann/loss_functions/triplet_margin_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/triplet_margin_loss.hpp @@ -42,17 +42,17 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class TripletMarginLoss +class TripletMarginLossType { public: /** - * Create the TripletMarginLoss object. + * Create the TripletMarginLossType object. * * @param margin The minimum value by which the distance between * Anchor and Negative sample exceeds the distance * between Anchor and Positive sample. */ - TripletMarginLoss(const double margin = 1.0); + TripletMarginLossType(const double margin = 1.0); /** * Computes the Triplet Margin Loss function. @@ -88,7 +88,9 @@ class TripletMarginLoss private: //! The margin value used in calculating Triplet Margin Loss. double margin; -}; // class TripletLossMargin +}; // class TripletMarginLoss + +typedef TripletMarginLossType TripletMarginLoss; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/triplet_margin_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/triplet_margin_loss_impl.hpp index 258018beb9..3ad7083726 100644 --- a/src/mlpack/methods/ann/loss_functions/triplet_margin_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/triplet_margin_loss_impl.hpp @@ -20,14 +20,14 @@ namespace mlpack { namespace ann /** Artifical Neural Network. */ { template -TripletMarginLoss::TripletMarginLoss(const double margin) : +TripletMarginLossType::TripletMarginLossType(const double margin) : margin(margin) { // Nothing to do here. } template -typename MatType::elem_type TripletMarginLoss::Forward( +typename MatType::elem_type TripletMarginLossType::Forward( const MatType& prediction, const MatType& target) { @@ -41,7 +41,7 @@ typename MatType::elem_type TripletMarginLoss::Forward( } template -void TripletMarginLoss::Backward( +void TripletMarginLossType::Backward( const MatType& prediction, const MatType& target, MatType& loss) @@ -54,7 +54,7 @@ void TripletMarginLoss::Backward( template template -void TripletMarginLoss::serialize( +void TripletMarginLossType::serialize( Archive& ar, const unsigned int /* version */) { diff --git a/src/mlpack/methods/ann/loss_functions/vr_class_reward.hpp b/src/mlpack/methods/ann/loss_functions/vr_class_reward.hpp index aff1dae16f..d6f0242713 100644 --- a/src/mlpack/methods/ann/loss_functions/vr_class_reward.hpp +++ b/src/mlpack/methods/ann/loss_functions/vr_class_reward.hpp @@ -2,7 +2,7 @@ * @file methods/ann/loss_functions/vr_class_reward.hpp * @author Marcus Edel * - * Definition of the VRClassReward class, which implements the variance + * Definition of the VRClassRewardType class, which implements the variance * reduced classification reinforcement layer. * * mlpack is free software; you may redistribute it and/or modify it under the @@ -30,16 +30,16 @@ namespace ann /** Artificial Neural Network. */ { * arma::sp_mat or arma::cube). */ template -class VRClassReward +class VRClassRewardType { public: /** - * Create the VRClassReward object. + * Create the VRClassRewardType object. * * @param scale Parameter used to scale the reward. * @param sizeAverage Take the average over all batches. */ - VRClassReward(const double scale = 1, const bool sizeAverage = true); + VRClassRewardType(const double scale = 1, const bool sizeAverage = true); /** * Ordinary feed forward pass of a neural network, evaluating the function @@ -112,7 +112,9 @@ class VRClassReward //! Locally-stored network modules. std::vector*> network; -}; // class VRClassReward +}; // class VRClassRewardType + +typedef VRClassRewardType VRClassReward; } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/vr_class_reward_impl.hpp b/src/mlpack/methods/ann/loss_functions/vr_class_reward_impl.hpp index 34383ae3f7..b1779c9487 100644 --- a/src/mlpack/methods/ann/loss_functions/vr_class_reward_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/vr_class_reward_impl.hpp @@ -2,7 +2,7 @@ * @file methods/ann/loss_functions/vr_class_reward_impl.hpp * @author Marcus Edel * - * Implementation of the VRClassReward class, which implements the variance + * Implementation of the VRClassRewardType class, which implements the variance * reduced classification reinforcement layer. * * mlpack is free software; you may redistribute it and/or modify it under the @@ -20,7 +20,7 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { template -VRClassReward::VRClassReward( +VRClassRewardType::VRClassRewardType( const double scale, const bool sizeAverage) : scale(scale), @@ -31,7 +31,7 @@ VRClassReward::VRClassReward( } template -typename MatType::elem_type VRClassReward::Forward( +typename MatType::elem_type VRClassRewardType::Forward( const MatType& input, const MatType& target) { double output = 0; @@ -61,7 +61,7 @@ typename MatType::elem_type VRClassReward::Forward( } template -void VRClassReward::Backward( +void VRClassRewardType::Backward( const MatType& input, const MatType& target, MatType& output) @@ -89,7 +89,7 @@ void VRClassReward::Backward( template template -void VRClassReward::serialize( +void VRClassRewardType::serialize( Archive& ar, const uint32_t /* version */) { ar(scale); diff --git a/src/mlpack/methods/ann/rnn.hpp b/src/mlpack/methods/ann/rnn.hpp index 233000e649..8cf1b67647 100644 --- a/src/mlpack/methods/ann/rnn.hpp +++ b/src/mlpack/methods/ann/rnn.hpp @@ -27,7 +27,7 @@ namespace ann /** Artificial Neural Network. */ { * @tparam InitializationRuleType Rule used to initialize the weight matrix. */ template< - typename OutputLayerType = NegativeLogLikelihood<>, + typename OutputLayerType = NegativeLogLikelihood, typename InitializationRuleType = RandomInitialization, typename MatType = arma::mat> class RNN diff --git a/src/mlpack/tests/ann_layer_test.cpp b/src/mlpack/tests/ann_layer_test.cpp index 1ffbe3dfd4..b7e0ff4e0e 100644 --- a/src/mlpack/tests/ann_layer_test.cpp +++ b/src/mlpack/tests/ann_layer_test.cpp @@ -139,7 +139,7 @@ TEST_CASE("GradientAddLayerTest", "[ANNLayerTest]") input(arma::randu(10, 1)), target(arma::mat("0")) { - model = new FFN, NguyenWidrowInitialization>(); + model = new FFN(); model->ResetData(input, target); model->Add(); model->Add(10, 10); @@ -161,7 +161,7 @@ TEST_CASE("GradientAddLayerTest", "[ANNLayerTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN, NguyenWidrowInitialization>* model; + FFN* model; arma::mat input, target; } function; @@ -466,7 +466,7 @@ TEST_CASE("NoAlphaDropoutTest", "[ANNLayerTest]") // input(arma::randu(10, 1)), // target(arma::mat("1")) // { -// model = new FFN, NguyenWidrowInitialization>(); +// model = new FFN(); // model->ResetData(input, target); // model->Add >(); // model->Add >(10, 10); @@ -488,7 +488,7 @@ TEST_CASE("NoAlphaDropoutTest", "[ANNLayerTest]") // arma::mat& Parameters() { return model->Parameters(); } -// FFN, NguyenWidrowInitialization>* model; +// FFN* model; // arma::mat input, target; // } function; @@ -579,7 +579,7 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]") target(1, 1) = 1; target(1, 2) = 1; - model = new FFN, RandomInitialization>(); + model = new FFN(); model->ResetData(input, target); model->Add(outSize); model->InputDimensions() = std::vector{ 4, 2 }; @@ -599,7 +599,7 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN, RandomInitialization>* model; + FFN* model; arma::mat input, target; const size_t inSize; const size_t outSize; @@ -655,7 +655,7 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]") // input(arma::randu(10, 1)), // target(arma::mat("1")) // { -// model = new FFN, NguyenWidrowInitialization>(); +// model = new FFN(); // model->ResetData(input, target); // model->Add >(); // model->Add >(10, 10); @@ -677,7 +677,7 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]") // arma::mat& Parameters() { return model->Parameters(); } -// FFN, NguyenWidrowInitialization>* model; +// FFN* model; // arma::mat input, target; // } function; @@ -808,7 +808,7 @@ TEST_CASE("GradientLinearNoBiasLayerTest", "[ANNLayerTest]") input(arma::randu(10, 1)), target(arma::mat("0")) { - model = new FFN, NguyenWidrowInitialization>(); + model = new FFN(); model->ResetData(input, target); model->Add(10); model->Add(2); @@ -829,7 +829,7 @@ TEST_CASE("GradientLinearNoBiasLayerTest", "[ANNLayerTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN, NguyenWidrowInitialization>* model; + FFN* model; arma::mat input, target; } function; @@ -843,7 +843,7 @@ TEST_CASE("GradientLinearNoBiasLayerTest", "[ANNLayerTest]") // { // for (size_t i = 0; i < 5; ++i) // { -// NegativeLogLikelihood<> module; +// NegativeLogLikelihood module; // const size_t inputElements = math::RandInt(5, 100); // arma::mat input; // RandomInitialization init(0, 1); @@ -909,8 +909,8 @@ TEST_CASE("GradientFlexibleReLULayerTest", "[ANNLayerTest]") input(arma::randu(2, 1)), target(arma::mat("0")) { - model = new FFN, RandomInitialization>( - NegativeLogLikelihood<>(), RandomInitialization(0.1, 0.5)); + model = new FFN( + NegativeLogLikelihood(), RandomInitialization(0.1, 0.5)); model->ResetData(input, target); model->Add(2, 2); @@ -933,7 +933,7 @@ TEST_CASE("GradientFlexibleReLULayerTest", "[ANNLayerTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN, RandomInitialization>* model; + FFN* model; arma::mat input, target; } function; @@ -1129,8 +1129,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // RandomInitialization init(0.5, 0.5); // // Create model with user defined rho parameter. -// RNN, RandomInitialization> modelA( -// rho, false, NegativeLogLikelihood<>(), init); +// RNN modelA( +// rho, false, NegativeLogLikelihood(), init); // modelA.Add >(); // modelA.Add >(1, 10); @@ -1139,8 +1139,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // modelA.Add >(); // // Create model without user defined rho parameter. -// RNN > modelB( -// rho, false, NegativeLogLikelihood<>(), init); +// RNN modelB( +// rho, false, NegativeLogLikelihood(), init); // modelB.Add >(); // modelB.Add >(1, 10); @@ -1169,7 +1169,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // { // const size_t rho = 5; -// model = new RNN >(rho); +// model = new RNN(rho); // model->ResetData(input, target); // model->Add >(); // model->Add >(1, 10); @@ -1191,7 +1191,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // arma::mat& Parameters() { return model->Parameters(); } -// RNN >* model; +// RNN* model; // arma::cube input, target; // } function; @@ -1233,8 +1233,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // RandomInitialization init(0.5, 0.5); // // Create model with user defined rho parameter. -// RNN, RandomInitialization> modelA( -// rho, false, NegativeLogLikelihood<>(), init); +// RNN modelA( +// rho, false, NegativeLogLikelihood(), init); // modelA.Add >(); // modelA.Add >(1, 10); @@ -1243,8 +1243,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // modelA.Add >(); // // Create model without user defined rho parameter. -// RNN > modelB( -// rho, false, NegativeLogLikelihood<>(), init); +// RNN modelB( +// rho, false, NegativeLogLikelihood(), init); // modelB.Add >(); // modelB.Add >(1, 10); @@ -1273,7 +1273,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // { // const size_t rho = 5; -// model = new RNN >(rho); +// model = new RNN(rho); // model->ResetData(input, target); // model->Add >(); // model->Add >(1, 10); @@ -1295,7 +1295,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // arma::mat& Parameters() { return model->Parameters(); } -// RNN >* model; +// RNN* model; // arma::cube input, target; // } function; @@ -1338,16 +1338,16 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // arma::cube target = arma::ones(1, 1, 5); // const size_t rho = 5; -// RNN > *model1 = -// new RNN >(rho); +// RNN *model1 = +// new RNN(rho); // model1->ResetData(input, target); // model1->Add >(); // model1->Add >(1, 10); // model1->Add >(10, 3, rho); // model1->Add >(); -// RNN > *model2 = -// new RNN >(rho); +// RNN *model2 = +// new RNN(rho); // model2->ResetData(input, target); // model2->Add >(); // model2->Add >(1, 10); @@ -1370,16 +1370,16 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // arma::cube target = arma::ones(1, 1, 5); // const size_t rho = 5; -// RNN > *model1 = -// new RNN >(rho); +// RNN *model1 = +// new RNN(rho); // model1->ResetData(input, target); // model1->Add >(); // model1->Add >(1, 10); // model1->Add >(10, 3, rho); // model1->Add >(); -// RNN > *model2 = -// new RNN >(rho); +// RNN *model2 = +// new RNN(rho); // model2->ResetData(input, target); // model2->Add >(); // model2->Add >(1, 10); @@ -1605,7 +1605,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // { // const size_t rho = 5; -// model = new RNN >(rho); +// model = new RNN(rho); // model->ResetData(input, target); // model->Add >(); // model->Add >(1, 10); @@ -1628,7 +1628,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // arma::mat& Parameters() { return model->Parameters(); } -// RNN >* model; +// RNN* model; // arma::cube input, target; // } function; @@ -1734,8 +1734,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // RandomInitialization init(0.5, 0.5); // // // Create model with user defined rho parameter. -// RNN, RandomInitialization> modelA( -// rho, false, NegativeLogLikelihood<>(), init); +// RNN modelA( +// rho, false, NegativeLogLikelihood(), init); // modelA.Add >(); // modelA.Add >(1, 10); // @@ -1744,8 +1744,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // modelA.Add >(); // // // Create model without user defined rho parameter. -// RNN > modelB( -// rho, false, NegativeLogLikelihood<>(), init); +// RNN modelB( +// rho, false, NegativeLogLikelihood(), init); // modelB.Add >(); // modelB.Add >(1, 10); // @@ -1774,7 +1774,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // { // const size_t rho = 5; // -// model = new RNN >(rho); +// model = new RNN(rho); // model->ResetData(input, target); // model->Add >(); // model->Add >(1, 10); @@ -1796,7 +1796,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // // arma::mat& Parameters() { return model->Parameters(); } // -// RNN >* model; +// RNN* model; // arma::cube input, target; // } function; // @@ -1838,8 +1838,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // RandomInitialization init(0.5, 0.5); // // // Create model with user defined rho parameter. -// RNN, RandomInitialization> modelA( -// rho, false, NegativeLogLikelihood<>(), init); +// RNN modelA( +// rho, false, NegativeLogLikelihood(), init); // modelA.Add >(); // modelA.Add >(1, 10); // @@ -1848,8 +1848,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // modelA.Add >(); // // // Create model without user defined rho parameter. -// RNN > modelB( -// rho, false, NegativeLogLikelihood<>(), init); +// RNN modelB( +// rho, false, NegativeLogLikelihood(), init); // modelB.Add >(); // modelB.Add >(1, 10); // @@ -1878,7 +1878,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // { // const size_t rho = 5; // -// model = new RNN >(rho); +// model = new RNN(rho); // model->ResetData(input, target); // model->Add >(); // model->Add >(1, 10); @@ -1900,7 +1900,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // // arma::mat& Parameters() { return model->Parameters(); } // -// RNN >* model; +// RNN* model; // arma::cube input, target; // } function; // @@ -1943,16 +1943,16 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // arma::cube target = arma::ones(1, 1, 5); // const size_t rho = 5; // -// RNN > *model1 = -// new RNN >(rho); +// RNN *model1 = +// new RNN(rho); // model1->ResetData(input, target); // model1->Add >(); // model1->Add >(1, 10); // model1->Add >(10, 3, rho); // model1->Add >(); // -// RNN > *model2 = -// new RNN >(rho); +// RNN *model2 = +// new RNN(rho); // model2->ResetData(input, target); // model2->Add >(); // model2->Add >(1, 10); @@ -1975,16 +1975,16 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // arma::cube target = arma::ones(1, 1, 5); // const size_t rho = 5; // -// RNN > *model1 = -// new RNN >(rho); +// RNN *model1 = +// new RNN(rho); // model1->ResetData(input, target); // model1->Add >(); // model1->Add >(1, 10); // model1->Add >(10, 3, rho); // model1->Add >(); // -// RNN > *model2 = -// new RNN >(rho); +// RNN *model2 = +// new RNN(rho); // model2->ResetData(input, target); // model2->Add >(); // model2->Add >(1, 10); @@ -2210,7 +2210,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // { // const size_t rho = 5; // -// model = new RNN >(rho); +// model = new RNN(rho); // model->ResetData(input, target); // model->Add >(); // model->Add >(1, 10); @@ -2233,7 +2233,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]") // // arma::mat& Parameters() { return model->Parameters(); } // -// RNN >* model; +// RNN* model; // arma::cube input, target; // } function; // @@ -2449,7 +2449,7 @@ TEST_CASE("ConcatLayerParametersTest", "[ANNLayerTest]") // input(arma::randu(10, 1)), // target(arma::mat("0")) // { -// model = new FFN, NguyenWidrowInitialization>(); +// model = new FFN(); // model->ResetData(input, target); // model->Add(); // model->Add(10, 10); @@ -2475,7 +2475,7 @@ TEST_CASE("ConcatLayerParametersTest", "[ANNLayerTest]") // arma::mat& Parameters() { return model->Parameters(); } -// FFN, NguyenWidrowInitialization>* model; +// FFN* model; // Concat* concat; // arma::mat input, target; // } function; @@ -2517,7 +2517,7 @@ TEST_CASE("GradientConcatenateLayerTest", "[ANNLayerTest]") input(arma::randu(10, 1)), target(arma::mat("0")) { - model = new FFN, NguyenWidrowInitialization>(); + model = new FFN(); model->ResetData(input, target); model->Add(); model->Add(10, 5); @@ -2546,7 +2546,7 @@ TEST_CASE("GradientConcatenateLayerTest", "[ANNLayerTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN, NguyenWidrowInitialization>* model; + FFN* model; Concatenate* concatenate; arma::mat input, target; } function; @@ -2725,7 +2725,7 @@ TEST_CASE("GradientSoftmaxTest", "[ANNLayerTest]") input(arma::randu(10, 1)), target(arma::mat("1; 0")) { - model = new FFN, RandomInitialization>; + model = new FFN; model->ResetData(input, target); model->Add(10, 10); model->Add(); @@ -2747,7 +2747,7 @@ TEST_CASE("GradientSoftmaxTest", "[ANNLayerTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN >* model; + FFN* model; arma::mat input, target; } function; @@ -3086,7 +3086,7 @@ TEST_CASE("SimpleBicubicInterpolationLayerTest", "[ANNLayerTest]") // input(arma::randn(32, 2048)), // target(arma::zeros(1, 2048)) // { -// model = new FFN, NguyenWidrowInitialization>(); +// model = new FFN(); // model->ResetData(input, target); // model->Add >(); // model->Add >(32, 4); @@ -3109,7 +3109,7 @@ TEST_CASE("SimpleBicubicInterpolationLayerTest", "[ANNLayerTest]") // arma::mat& Parameters() { return model->Parameters(); } -// FFN, NguyenWidrowInitialization>* model; +// FFN* model; // arma::mat input, target; // } function; @@ -3160,7 +3160,7 @@ TEST_CASE("GradientVirtualBatchNormTest", "[ANNLayerTest]") { arma::mat referenceBatch = arma::mat(input.memptr(), input.n_rows, 4); - model = new FFN, NguyenWidrowInitialization>(); + model = new FFN(); model->ResetData(input, target); model->Add(); model->Add(5, 5); @@ -3183,7 +3183,7 @@ TEST_CASE("GradientVirtualBatchNormTest", "[ANNLayerTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN, NguyenWidrowInitialization>* model; + FFN* model; arma::mat input, target; } function; @@ -3221,7 +3221,7 @@ TEST_CASE("VirtualBatchNormLayerParametersTest", "[ANNLayerTest]") // input(arma::randn(5, 4)), // target(arma::zeros(1, 4)) // { -// model = new FFN, NguyenWidrowInitialization>(); +// model = new FFN(); // model->ResetData(input, target); // model->Add >(); // model->Add >(5, 5); @@ -3242,7 +3242,7 @@ TEST_CASE("VirtualBatchNormLayerParametersTest", "[ANNLayerTest]") // arma::mat& Parameters() { return model->Parameters(); } -// FFN, NguyenWidrowInitialization>* model; +// FFN* model; // arma::mat input, target; // } function; @@ -3399,7 +3399,7 @@ TEST_CASE("GradientTransposedConvolutionLayerTest", "[ANNLayerTest]") input(arma::linspace(0, 35, 36)), target(arma::mat("0")) { - model = new FFN, RandomInitialization>(); + model = new FFN(); model->ResetData(input, target); model->Add(1, 1, 3, 3, 2, 2, 1, 1, 6, 6, 12, 12); model->Add(); @@ -3419,7 +3419,7 @@ TEST_CASE("GradientTransposedConvolutionLayerTest", "[ANNLayerTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN, RandomInitialization>* model; + FFN* model; arma::mat input, target; } function; @@ -3565,7 +3565,7 @@ TEST_CASE("SimpleMultiplyMergeLayerTest", "[ANNLayerTest]") // input(arma::linspace(0, 35, 36)), // target(arma::mat("0")) // { -// model = new FFN, RandomInitialization>(); +// model = new FFN(); // model->ResetData(input, target); // model->Add >(); // model->Add >(1, 1, 3, 3, 1, 1, 0, 0, 6, 6, 2, 2); @@ -3586,7 +3586,7 @@ TEST_CASE("SimpleMultiplyMergeLayerTest", "[ANNLayerTest]") // arma::mat& Parameters() { return model->Parameters(); } -// FFN, RandomInitialization>* model; +// FFN* model; // arma::mat input, target; // } function; @@ -3747,7 +3747,7 @@ TEST_CASE("SimpleMultiplyMergeLayerTest", "[ANNLayerTest]") // input(arma::randn(10, 256)), // target(arma::zeros(1, 256)) // { -// model = new FFN, NguyenWidrowInitialization>(); +// model = new FFN(); // model->ResetData(input, target); // model->Add >(); // model->Add >(10, 10); @@ -3770,7 +3770,7 @@ TEST_CASE("SimpleMultiplyMergeLayerTest", "[ANNLayerTest]") // // arma::mat& Parameters() { return model->Parameters(); } // -// FFN, NguyenWidrowInitialization>* model; +// FFN* model; // arma::mat input, target; // } function; // @@ -3824,7 +3824,7 @@ TEST_CASE("GradientLayerNormTest", "[ANNLayerTest]") input(arma::randn(10, 256)), target(arma::zeros(1, 256)) { - model = new FFN, NguyenWidrowInitialization>(); + model = new FFN(); model->ResetData(input, target); model->Add(); model->Add(10, 10); @@ -3847,7 +3847,7 @@ TEST_CASE("GradientLayerNormTest", "[ANNLayerTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN, NguyenWidrowInitialization>* model; + FFN* model; arma::mat input, target; } function; @@ -4154,7 +4154,7 @@ TEST_CASE("GradientReparametrizationLayerTest", "[ANNLayerTest]") input(arma::randu(10, 1)), target(arma::mat("0")) { - model = new FFN, NguyenWidrowInitialization>(); + model = new FFN(); model->ResetData(input, target); model->Add(); model->Add(10, 6); @@ -4177,7 +4177,7 @@ TEST_CASE("GradientReparametrizationLayerTest", "[ANNLayerTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN, NguyenWidrowInitialization>* model; + FFN* model; arma::mat input, target; } function; @@ -4197,7 +4197,7 @@ TEST_CASE("GradientReparametrizationLayerBetaTest", "[ANNLayerTest]") input(arma::randu(10, 2)), target(arma::mat("0 0")) { - model = new FFN, NguyenWidrowInitialization>(); + model = new FFN(); model->ResetData(input, target); model->Add(); model->Add(10, 6); @@ -4221,7 +4221,7 @@ TEST_CASE("GradientReparametrizationLayerBetaTest", "[ANNLayerTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN, NguyenWidrowInitialization>* model; + FFN* model; arma::mat input, target; } function; @@ -4356,7 +4356,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]") // input(arma::randu(5, 1)), // target(arma::mat("0")) // { -// model = new FFN, NguyenWidrowInitialization>(); +// model = new FFN(); // model->ResetData(input, target); // model->Add(); // model->Add(5, 10); @@ -4386,7 +4386,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]") // arma::mat& Parameters() { return model->Parameters(); } -// FFN, NguyenWidrowInitialization>* model; +// FFN* model; // Highway* highway; // arma::mat input, target; // } function; @@ -4406,7 +4406,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]") // input(arma::randu(10, 1)), // target(arma::mat("0")) // { -// model = new FFN, NguyenWidrowInitialization>(); +// model = new FFN(); // model->ResetData(input, target); // model->Add(); // model->Add(10, 10); @@ -4435,7 +4435,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]") // arma::mat& Parameters() { return model->Parameters(); } -// FFN, NguyenWidrowInitialization>* model; +// FFN* model; // Sequential* sequential; // arma::mat input, target; // } function; @@ -4455,7 +4455,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]") // input(arma::randu(10, 1)), // target(arma::mat("0")) // { -// model = new FFN, NguyenWidrowInitialization>(); +// model = new FFN(); // model->ResetData(input, target); // model->Add(10, 10); @@ -4480,7 +4480,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]") // arma::mat& Parameters() { return model->Parameters(); } -// FFN, NguyenWidrowInitialization>* model; +// FFN* model; // WeightNorm* weightNorm; // arma::mat input, target; // } function; @@ -4521,7 +4521,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]") // arma::mat input(5, 100, arma::fill::randu); // arma::mat output(5, 100, arma::fill::randu); -// FFN, ann::RandomInitialization> model; +// FFN model; // model.Add>(input.n_rows, 10); // model.Add(layer); // model.Add>(); @@ -4535,7 +4535,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]") // model.Predict(input, originalOutput); // // Now serialize the model. -// FFN, ann::RandomInitialization> xmlModel, jsonModel, +// FFN xmlModel, jsonModel, // binaryModel; // SerializeObjectAll(model, xmlModel, jsonModel, binaryModel); @@ -4678,7 +4678,7 @@ TEST_CASE("GradientConvolutionLayerTest", "[ANNLayerTest]") input(arma::linspace(0, 35, 36)), target(arma::mat("1")) { - model = new FFN, RandomInitialization>(); + model = new FFN(); model->ResetData(input, target); model->Add(1, 3, 3, 1, 1, std::tuple(0, 0), std::tuple(0, 0), "same"); @@ -4701,7 +4701,7 @@ TEST_CASE("GradientConvolutionLayerTest", "[ANNLayerTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN, RandomInitialization>* model; + FFN* model; arma::mat input, target; } function; @@ -5425,7 +5425,7 @@ TEST_CASE("TransposedConvolutionalLayerOptionalParameterTest", "[ANNLayerTest]") // input(arma::randn(16, 1024)), // target(arma::zeros(1, 1024)) // { -// model = new FFN, NguyenWidrowInitialization>(); +// model = new FFN(); // model->ResetData(input, target); // model->Add>(); // model->Add>(1, 2, 3, 3, 1, 1, 0, 0, 4, 4); @@ -5448,7 +5448,7 @@ TEST_CASE("TransposedConvolutionalLayerOptionalParameterTest", "[ANNLayerTest]") // arma::mat& Parameters() { return model->Parameters(); } -// FFN, NguyenWidrowInitialization>* model; +// FFN* model; // arma::mat input, target; // } function; @@ -6091,7 +6091,7 @@ TEST_CASE("GradientMultiheadAttentionTest", "[ANNLayerTest]") keyPaddingMask = arma::zeros(1, srcSeqLen); keyPaddingMask(srcSeqLen - 1) = std::numeric_limits::lowest(); - model = new FFN, XavierInitialization>(); + model = new FFN(); model->ResetData(input, target); // attnModule = new MultiheadAttention(tgtSeqLen, srcSeqLen, embedDim, // nHeads); @@ -6118,7 +6118,7 @@ TEST_CASE("GradientMultiheadAttentionTest", "[ANNLayerTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN, XavierInitialization>* model; + FFN* model; // MultiheadAttention* attnModule; arma::mat input, target, attnMask, keyPaddingMask; @@ -6294,7 +6294,7 @@ TEST_CASE("GradientInstanceNormLayerTest", "[ANNLayerTest]") arma::mat target; target.ones(1, 1024); - model = new FFN, NguyenWidrowInitialization>(); + model = new FFN(); model->ResetData(input, target); model->Add >(); model->Add >(1, 2, 3, 3, 1, 1, 0, 0, 4, 4); @@ -6317,7 +6317,7 @@ TEST_CASE("GradientInstanceNormLayerTest", "[ANNLayerTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN, NguyenWidrowInitialization>* model; + FFN* model; arma::mat input, target; } function; diff --git a/src/mlpack/tests/callback_test.cpp b/src/mlpack/tests/callback_test.cpp index 2a498c9f78..203ce3d9a5 100644 --- a/src/mlpack/tests/callback_test.cpp +++ b/src/mlpack/tests/callback_test.cpp @@ -48,7 +48,7 @@ TEST_CASE("FFNCallbackTest", "[CallbackTest]") if (!data::Load("lab3.csv", labels)) FAIL("Cannot load test dataset lab3.csv!"); - FFN, RandomInitialization> model; + FFN model; model.Add(2); model.Add(); @@ -74,7 +74,7 @@ TEST_CASE("FFNWithOptimizerCallbackTest", "[CallbackTest]") if (!data::Load("lab3.csv", labels)) FAIL("Cannot load test dataset lab3.csv!"); - FFN, RandomInitialization> model; + FFN model; model.Add(2); model.Add(); @@ -99,8 +99,8 @@ TEST_CASE("RNNCallbackTest", "[CallbackTest]") RandomInitialization init(0.5, 0.5); // Create model with user defined rho parameter. - RNN, RandomInitialization> model( - rho, false, NegativeLogLikelihood<>(), init); + RNN model( + rho, false, NegativeLogLikelihood(), init); model.Add(10); // Use LSTM layer with 3 units. @@ -124,8 +124,8 @@ TEST_CASE("RNNWithOptimizerCallbackTest", "[CallbackTest]") RandomInitialization init(0.5, 0.5); // Create model with user defined rho parameter. - RNN, RandomInitialization> model( - rho, false, NegativeLogLikelihood<>(), init); + RNN model( + rho, false, NegativeLogLikelihood(), init); model.Add(10); // Use LSTM layer with 3 units. diff --git a/src/mlpack/tests/convolutional_network_test.cpp b/src/mlpack/tests/convolutional_network_test.cpp index 9dd8238603..4acaf5aff3 100644 --- a/src/mlpack/tests/convolutional_network_test.cpp +++ b/src/mlpack/tests/convolutional_network_test.cpp @@ -81,7 +81,7 @@ TEST_CASE("PaddingTest", "[ConvolutionalNetworktest]") X.load("mnist_first250_training_4s_and_9s.arm"); // Create the network. - FFN, RandomInitialization> model; + FFN model; model.Add(1, 2, 3, 4); @@ -129,7 +129,7 @@ TEST_CASE("MaxPoolingTest", "[ConvolutionalNetworkTest]") X.col(2) = arma::vec("3, 4, 1, -1, 5, 5, 5, 5"); // Create the network. - FFN, RandomInitialization> model; + FFN model; model.Add(2, 2); arma::mat results; @@ -204,7 +204,7 @@ TEST_CASE("VanillaNetworkTest", "[ConvolutionalNetworkTest]") bool success = false; for (size_t trial = 0; trial < 5; ++trial) { - FFN, RandomInitialization> model; + FFN model; model.Add(8, 5, 5, 1, 1, 0, 0); model.Add(); @@ -253,7 +253,7 @@ TEST_CASE("VanillaNetworkTest", "[ConvolutionalNetworkTest]") TEST_CASE("VanillaNetworkBatchSizeTest", "[ConvolutionalNetworkTest]") { - FFN, RandomInitialization> model; + FFN model; model.Add(8, 5, 5, 1, 1, 0, 0); model.Add(); @@ -400,8 +400,8 @@ TEST_CASE("CheckCopyVanillaNetworkTest", "[ConvolutionalNetworkTest]") // of iterations using random weights. If this works 1 of 5 times, I'm fine // with that. All I want to know is that the network is able to escape from // local minima and to solve the task. - FFN, RandomInitialization> *model = - new FFN, RandomInitialization>; + FFN *model = + new FFN; model->Add(8, 5, 5, 1, 1, 0, 0); model->Add(); @@ -417,8 +417,8 @@ TEST_CASE("CheckCopyVanillaNetworkTest", "[ConvolutionalNetworkTest]") model->Add(); model->InputDimensions() = std::vector({ 28, 28 }); - FFN, RandomInitialization> *model1 = - new FFN, RandomInitialization>; + FFN *model1 = + new FFN; model1->Add(8, 5, 5, 1, 1, 0, 0); model1->Add(); diff --git a/src/mlpack/tests/cv_test.cpp b/src/mlpack/tests/cv_test.cpp index c714dfb1ab..27349bb92c 100644 --- a/src/mlpack/tests/cv_test.cpp +++ b/src/mlpack/tests/cv_test.cpp @@ -220,7 +220,7 @@ TEST_CASE("MSEMatResponsesTest", "[CVTest]") arma::mat data("1 2"); arma::mat trainingResponses("1 2; 3 4"); - FFN, ConstInitialization> ffn(MeanSquaredError<>(), + FFN ffn(MeanSquaredError(), ConstInitialization(0)); ffn.Add(2); diff --git a/src/mlpack/tests/feedforward_network_2_test.cpp b/src/mlpack/tests/feedforward_network_2_test.cpp index 12b9a43a0f..a115468305 100644 --- a/src/mlpack/tests/feedforward_network_2_test.cpp +++ b/src/mlpack/tests/feedforward_network_2_test.cpp @@ -102,7 +102,7 @@ TEST_CASE("RBFNetworkTest", "[FeedForwardNetworkTest]") KMeans<> kmeans; kmeans.Cluster(trainData, 8, centroids); - FFN > model; + FFN model; model.Add(8, centroids); model.Add(3); @@ -134,7 +134,7 @@ TEST_CASE("RBFNetworkTest", "[FeedForwardNetworkTest]") KMeans<> kmeans1; kmeans1.Cluster(dataset, 140, centroids1); - FFN > model1; + FFN model1; model1.Add(140, centroids1, 4.1); model1.Add(2); diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index 6ab5ed3b57..613d0e56e8 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -137,13 +137,13 @@ TEST_CASE("CheckCopyMovingVanillaNetworkTest", "[FeedForwardNetworkTest]") * +-----+ +-----+ */ - FFN > *model = new FFN >; + FFN *model = new FFN; model->Add(8); model->Add(); model->Add(3); model->Add(); - FFN > *model1 = new FFN >; + FFN *model1 = new FFN; model1->Add(8); model1->Add(); model1->Add(3); @@ -171,12 +171,12 @@ TEST_CASE("CheckCopyMovingReparametrizationNetworkTest", // Construct a feed forward network with trainData.n_rows input nodes, // followed by a linear layer and then a reparametrization layer. - FFN > *model = new FFN >; + FFN *model = new FFN; model->Add(8); model->Add(false, true, 1); model->Add(); - FFN > *model1 = new FFN >; + FFN *model1 = new FFN; model1->Add(8); model1->Add(false, true, 1); model1->Add(); @@ -208,12 +208,12 @@ TEST_CASE("CheckCopyMovingReparametrizationNetworkTest", // * followed by a linear layer and then a reparametrization layer. // */ // -// FFN > *model = new FFN >; +// FFN *model = new FFN; // model->Add >(trainData.n_rows, 8); // model->Add >(4, false, true, 1); // model->Add >(); // -// FFN > *model1 = new FFN >; +// FFN *model1 = new FFN; // model1->Add >(trainData.n_rows, 8); // model1->Add >(4, false, true, 1); // model1->Add >(); @@ -240,13 +240,13 @@ TEST_CASE("CheckCopyMovingLinear3DNetworkTest", "[FeedForwardNetworkTest]") // Construct a feed forward network with trainData.n_rows input nodes, // followed by a linear layer and then a Linear3D layer. - FFN > *model = new FFN >; + FFN *model = new FFN; model->Add(8); model->Add(); model->Add(3); model->Add(); - FFN > *model1 = new FFN >; + FFN *model1 = new FFN; model1->Add(8); model1->Add(); model1->Add(3); @@ -270,7 +270,7 @@ TEST_CASE("CheckCopyMovingNoisyLinearTest", "[FeedForwardNetworkTest]") arma::mat output = arma::mat("0"); // Check copying constructor. - FFN> *model1 = new FFN>(); + FFN *model1 = new FFN(); model1->ResetData(input, output); model1->Add(5); model1->Add(1); @@ -280,7 +280,7 @@ TEST_CASE("CheckCopyMovingNoisyLinearTest", "[FeedForwardNetworkTest]") CheckCopyFunction(model1, input, output); // Check moving constructor. - FFN> *model2 = new FFN>(); + FFN *model2 = new FFN(); model2->ResetData(input, output); model2->Add(5); model2->Add(1); @@ -301,7 +301,7 @@ TEST_CASE("CheckCopyMovingConcatenateTest", "[FeedForwardNetworkTest]") arma::mat output = arma::mat("1"); // Check copying constructor. - FFN> *model1 = new FFN>(); + FFN *model1 = new FFN(); model1->ResetData(input, output); model1->Add(5); @@ -319,7 +319,7 @@ TEST_CASE("CheckCopyMovingConcatenateTest", "[FeedForwardNetworkTest]") CheckCopyFunction(model1, input, output); // Check moving constructor. - FFN> *model2 = new FFN>(); + FFN *model2 = new FFN(); model2->ResetData(input, output); model2->Add(5); @@ -349,14 +349,14 @@ TEST_CASE("CheckCopyMovingDropoutNetworkTest", "[FeedForwardNetworkTest]") arma::mat trainLabels = trainData.row(trainData.n_rows - 1) - 1; trainData.shed_row(trainData.n_rows - 1); - FFN > *model = new FFN >; + FFN *model = new FFN; model->Add(8); model->Add(); model->Add(0.3); model->Add(3); model->Add(); - FFN > *model1 = new FFN >; + FFN *model1 = new FFN; model1->Add(8); model1->Add(); model1->Add(0.3); @@ -398,13 +398,13 @@ TEST_CASE("CheckCopyMovingVanillaNetworkTestNoBias", "[FeedForwardNetworkTest]") * +-----+ +--+--+ +-----+ */ - FFN > *model = new FFN >; + FFN *model = new FFN; model->Add(8); model->Add(); model->Add(3); model->Add(); - FFN > *model1 = new FFN >; + FFN *model1 = new FFN; model1->Add(8); model1->Add(); model1->Add(3); @@ -436,12 +436,12 @@ TEST_CASE("CheckCopyMovingVanillaNetworkTestNoBias", "[FeedForwardNetworkTest]") // * followed by a linear layer and then a reparametrization layer. // */ // -// FFN > *model = new FFN >; +// FFN *model = new FFN; // model->Add >(trainData.n_rows, 8); // model->Add >(4, false, true, 1); // model->Add >(); // -// FFN > *model1 = new FFN >; +// FFN *model1 = new FFN; // model1->Add >(trainData.n_rows, 8); // model1->Add >(4, false, true, 1); // model1->Add >(); @@ -497,7 +497,7 @@ TEST_CASE("FFVanillaNetworkTest", "[FeedForwardNetworkTest]") * +-----+ +-----+ */ - FFN > model; + FFN model; model.Add(8); model.Add(); model.Add(3); @@ -518,7 +518,7 @@ TEST_CASE("FFVanillaNetworkTest", "[FeedForwardNetworkTest]") arma::mat labels = arma::zeros(1, dataset.n_cols); labels.submat(0, labels.n_cols / 2, 0, labels.n_cols - 1).fill(1); - FFN > model1; + FFN model1; model1.Add(10); model1.Add(); model1.Add(2); @@ -539,7 +539,7 @@ TEST_CASE("ForwardBackwardTest", "[FeedForwardNetworkTest]") arma::mat labels = arma::zeros(1, dataset.n_cols); labels.submat(0, labels.n_cols / 2, 0, labels.n_cols - 1).fill(1); - FFN > model; + FFN model; model.Add(50); model.Add(); model.Add(10); @@ -645,7 +645,7 @@ TEST_CASE("DropoutNetworkTest", "[FeedForwardNetworkTest]") * +-----+ */ - FFN > model; + FFN model; model.Add(8); model.Add(); model.Add(); @@ -668,7 +668,7 @@ TEST_CASE("DropoutNetworkTest", "[FeedForwardNetworkTest]") arma::mat labels = arma::zeros(1, dataset.n_cols); labels.submat(0, labels.n_cols / 2, 0, labels.n_cols - 1).fill(1); - FFN > model1; + FFN model1; model1.Add(10); model1.Add(); model.Add(); @@ -693,7 +693,7 @@ TEST_CASE("HighwayNetworkTest", "[FeedForwardNetworkTest]") arma::mat labels = arma::zeros(1, dataset.n_cols); labels.submat(0, labels.n_cols / 2, 0, labels.n_cols - 1).fill(1); - FFN > model; + FFN model; model.Add(10); Highway* highway = new Highway(); highway->Add(10); @@ -750,7 +750,7 @@ TEST_CASE("DropConnectNetworkTest", "[FeedForwardNetworkTest]") * */ - FFN > model; + FFN model; model.Add(8); model.Add(); model.Add(3); @@ -771,7 +771,7 @@ TEST_CASE("DropConnectNetworkTest", "[FeedForwardNetworkTest]") arma::mat labels = arma::zeros(1, dataset.n_cols); labels.submat(0, labels.n_cols / 2, 0, labels.n_cols - 1).fill(1); - FFN > model1; + FFN model1; model1.Add(10); model1.Add(); model1.Add(2); @@ -787,7 +787,7 @@ TEST_CASE("DropConnectNetworkTest", "[FeedForwardNetworkTest]") */ TEST_CASE("FFNMiscTest", "[FeedForwardNetworkTest]") { - FFN> model; + FFN model; model.Add(3); model.Add(); @@ -822,7 +822,7 @@ TEST_CASE("FFSerializationTest", "[FeedForwardNetworkTest]") // Vanilla neural net with logistic activation function. // Because 92% of the patients are not hyperthyroid the neural // network must be significant better than 92%. - FFN > model; + FFN model; model.Add(8); model.Add(); model.Add(); @@ -833,7 +833,7 @@ TEST_CASE("FFSerializationTest", "[FeedForwardNetworkTest]") model.Train(trainData, trainLabels, opt); - FFN> xmlModel, jsonModel, binaryModel; + FFN xmlModel, jsonModel, binaryModel; xmlModel.Add(10); // Layer that will get removed. // Serialize into other models. @@ -874,7 +874,7 @@ TEST_CASE("FFSerializationTest", "[FeedForwardNetworkTest]") // // Vanilla neural net with logistic activation function. // // Because 92% of the patients are not hyperthyroid the neural // // network must be significant better than 92%. -// FFN > model; +// FFN model; // model.Add >(trainData.n_rows, 8); // model.Add >(); // model.Add >(); @@ -885,7 +885,7 @@ TEST_CASE("FFSerializationTest", "[FeedForwardNetworkTest]") // // model.Train(trainData, trainLabels, opt); // -// FFN> xmlModel, jsonModel, binaryModel; +// FFN xmlModel, jsonModel, binaryModel; // xmlModel.Add>(10, 10); // Layer that will get removed. // // // Serialize into other models. @@ -924,7 +924,7 @@ TEST_CASE("FFSerializationTest", "[FeedForwardNetworkTest]") // testData.shed_row(testData.n_rows - 1); // testLabels -= 1; // The labels should be between 0 and numClasses - 1. // -// FFN, RandomInitialization, CustomLayer<> > model; +// FFN > model; // model.Add >(trainData.n_rows, 8); // model.Add >(); // model.Add >(8, 3); @@ -943,7 +943,7 @@ TEST_CASE("FFSerializationTest", "[FeedForwardNetworkTest]") */ TEST_CASE("PartialForwardTest", "[FeedForwardNetworkTest]") { - FFN, RandomInitialization> model; + FFN model; model.Add(10); // Add a new Add<> module which adds a (learnable) constant term to the input. @@ -1012,7 +1012,7 @@ TEST_CASE("FFNTrainReturnObjective", "[FeedForwardNetworkTest]") // Vanilla neural net with logistic activation function. // Because 92% of the patients are not hyperthyroid the neural // network must be significantly better than 92%. - FFN > model; + FFN model; model.Add(8); model.Add(); model.Add(); @@ -1032,7 +1032,7 @@ TEST_CASE("FFNTrainReturnObjective", "[FeedForwardNetworkTest]") TEST_CASE("FFNReturnModel", "[FeedForwardNetworkTest]") { // Create dummy network. - FFN > model; + FFN model; Linear* linearA = new Linear(3); model.Add(linearA); Linear* linearB = new Linear(4); @@ -1082,7 +1082,7 @@ TEST_CASE("OptimizerTest", "[FeedForwardNetworkTest]") testData.shed_row(testData.n_rows - 1); testLabels -= 1; // The labels should be between 0 and numClasses. - FFN, RandomInitialization> model; + FFN model; model.Add(8); model.Add(3); model.Add(); @@ -1112,7 +1112,7 @@ TEST_CASE("FFNCheckInputShapeTest", "[FeedForwardNetworkTest]") arma::mat testLabels = testData.row(testData.n_rows - 1); testData.shed_row(testData.n_rows - 1); - FFN, RandomInitialization> model; + FFN model; model.Add(8); model.Add(3); model.Add(); diff --git a/src/mlpack/tests/init_rules_test.cpp b/src/mlpack/tests/init_rules_test.cpp index 06724a9921..5d56e904b8 100644 --- a/src/mlpack/tests/init_rules_test.cpp +++ b/src/mlpack/tests/init_rules_test.cpp @@ -214,13 +214,13 @@ TEST_CASE("NetworkInitTest", "[InitRulesTest]") { arma::mat input = arma::ones(5, 1); arma::mat response; - NegativeLogLikelihood<> outputLayer; + NegativeLogLikelihood outputLayer; // Create a simple network and use the RandomInitialization rule to // initialize the network parameters. RandomInitialization randomInit(0.5, 0.5); - FFN, RandomInitialization> randomModel( + FFN randomModel( std::move(outputLayer), randomInit); randomModel.Add(5); randomModel.Add(2); @@ -233,7 +233,7 @@ TEST_CASE("NetworkInitTest", "[InitRulesTest]") // Create a simple network and use the OrthogonalInitialization rule to // initialize the network parameters. - FFN, OrthogonalInitialization> orthogonalModel; + FFN orthogonalModel; orthogonalModel.Add(5); orthogonalModel.Add(2); orthogonalModel.Add(); @@ -243,8 +243,8 @@ TEST_CASE("NetworkInitTest", "[InitRulesTest]") // Create a simple network and use the ZeroInitialization rule to // initialize the network parameters. - FFN, ConstInitialization> - zeroModel(NegativeLogLikelihood<>(), ConstInitialization(0)); + FFN + zeroModel(NegativeLogLikelihood(), ConstInitialization(0)); zeroModel.Add(5); zeroModel.Add(2); zeroModel.Add(); @@ -258,7 +258,7 @@ TEST_CASE("NetworkInitTest", "[InitRulesTest]") // parameters. KathirvalavakumarSubavathiInitialization kathirvalavakumarSubavathiInit( input, 1.5); - FFN, KathirvalavakumarSubavathiInitialization> + FFN ksModel(std::move(outputLayer), kathirvalavakumarSubavathiInit); ksModel.Add(5); ksModel.Add(2); @@ -269,7 +269,7 @@ TEST_CASE("NetworkInitTest", "[InitRulesTest]") // Create a simple network and use the OivsInitialization rule to // initialize the network parameters. - FFN, OivsInitialization<> > oivsModel; + FFN > oivsModel; oivsModel.Add(5); oivsModel.Add(2); oivsModel.Add(); @@ -279,7 +279,7 @@ TEST_CASE("NetworkInitTest", "[InitRulesTest]") // Create a simple network and use the GaussianInitialization rule to // initialize the network parameters. - FFN, GaussianInitialization> gaussianModel; + FFN gaussianModel; gaussianModel.Add(5); gaussianModel.Add(2); gaussianModel.Add(); diff --git a/src/mlpack/tests/ksinit_test.cpp b/src/mlpack/tests/ksinit_test.cpp index d9cf464fd7..15a9dec67c 100644 --- a/src/mlpack/tests/ksinit_test.cpp +++ b/src/mlpack/tests/ksinit_test.cpp @@ -75,8 +75,8 @@ void BuildVanillaNetwork(MatType& trainData, // Cauchy’s Inequality Based on Sensitivity Analysis" paper. KathirvalavakumarSubavathiInitialization init(trainData, 4.59); - FFN, KathirvalavakumarSubavathiInitialization> - model(MeanSquaredError<>(), init); + FFN + model(MeanSquaredError(), init); model.Add(hiddenLayerSize); model.Add(); diff --git a/src/mlpack/tests/loss_functions_test.cpp b/src/mlpack/tests/loss_functions_test.cpp index 6aac81dd8a..71193d144b 100644 --- a/src/mlpack/tests/loss_functions_test.cpp +++ b/src/mlpack/tests/loss_functions_test.cpp @@ -53,7 +53,7 @@ using namespace mlpack::ann; TEST_CASE("HuberLossTest", "[LossFunctionsTest]") { arma::mat input, target, output; - HuberLoss<> module; + HuberLoss module; // Test the Forward function. input = arma::mat("17.45 12.91 13.63 29.01 7.12 15.47 31.52 31.97"); @@ -82,10 +82,10 @@ TEST_CASE("PoissonNLLLossTest", "[LossFunctionsTest]") arma::mat input, target, input4, target4; arma::mat output1, output2, output3, output4; arma::mat expOutput1, expOutput2, expOutput3, expOutput4; - PoissonNLLLoss<> module1; - PoissonNLLLoss<> module2(true, true, 1e-08, false); - PoissonNLLLoss<> module3(true, true, 1e-08, true); - PoissonNLLLoss<> module4(false, true, 1e-08, true); + PoissonNLLLoss module1; + PoissonNLLLoss module2(true, true, 1e-08, false); + PoissonNLLLoss module3(true, true, 1e-08, true); + PoissonNLLLoss module4(false, true, 1e-08, true); // Test the Forward function on a user generated input. input = arma::mat("1.0 1.0 1.9 1.6 -1.9 3.7 -1.0 0.5"); @@ -148,7 +148,7 @@ TEST_CASE("SimpleKLDivergenceTest", "[LossFunctionsTest]") { arma::mat input, target, output; double loss; - KLDivergence<> module(true); + KLDivergence module(true); // Test the Forward function. Loss should be 0 if input = target. input = arma::ones(10, 1); @@ -163,7 +163,7 @@ TEST_CASE("SimpleKLDivergenceTest", "[LossFunctionsTest]") TEST_CASE("SimpleMeanSquaredLogarithmicErrorTest", "[LossFunctionsTest]") { arma::mat input, output, target; - MeanSquaredLogarithmicError<> module; + MeanSquaredLogarithmicError module; // Test the Forward function on a user generator input and compare it against // the manually calculated result. @@ -198,7 +198,7 @@ TEST_CASE("KLDivergenceMeanTest", "[LossFunctionsTest]") { arma::mat input, target, output; double loss; - KLDivergence<> module(true); + KLDivergence module(true); // Test the Forward function. input = arma::mat("1 1 1 1 1 1 1 1 1 1"); @@ -219,7 +219,7 @@ TEST_CASE("KLDivergenceNoMeanTest", "[LossFunctionsTest]") { arma::mat input, target, output; double loss; - KLDivergence<> module(false); + KLDivergence module(false); // Test the Forward function. input = arma::mat("1 1 1 1 1 1 1 1 1 1"); @@ -239,7 +239,7 @@ TEST_CASE("KLDivergenceNoMeanTest", "[LossFunctionsTest]") TEST_CASE("SimpleMeanSquaredErrorTest", "[LossFunctionsTest]") { arma::mat input, output, target; - MeanSquaredError<> module; + MeanSquaredError module; // Test the Forward function on a user generator input and compare it against // the manually calculated result. @@ -276,8 +276,8 @@ TEST_CASE("SimpleMeanSquaredErrorTest", "[LossFunctionsTest]") TEST_CASE("SimpleBinaryCrossEntropyLossTest", "[LossFunctionsTest]") { arma::mat input1, input2, input3, output, target1, target2, target3; - BCELoss<> module1(1e-6, false); - BCELoss<> module2(1e-6, true); + BCELoss module1(1e-6, false); + BCELoss module2(1e-6, true); // Test the Forward function on a user generator input and compare it against // the manually calculated result. input1 = arma::mat("0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5"); @@ -329,7 +329,7 @@ TEST_CASE("SimpleSigmoidCrossEntropyErrorTest", "[LossFunctionsTest]") { arma::mat input1, input2, input3, output, target1, target2, target3, expectedOutput; - SigmoidCrossEntropyError<> module; + SigmoidCrossEntropyError module; // Test the Forward function on a user generator input and compare it against // the calculated result. @@ -388,7 +388,7 @@ TEST_CASE("SimpleSigmoidCrossEntropyErrorTest", "[LossFunctionsTest]") TEST_CASE("SimpleEarthMoverDistanceLayerTest", "[LossFunctionsTest]") { arma::mat input1, input2, output, target1, target2, expectedOutput; - EarthMoverDistance<> module; + EarthMoverDistance module; // Test the Forward function on a user generator input and compare it against // the manually calculated result. @@ -433,7 +433,7 @@ TEST_CASE("GradientMeanSquaredErrorTest", "[LossFunctionsTest]") input = arma::randu(10, 1); target = arma::randu(2, 1); - model = new FFN, NguyenWidrowInitialization>(); + model = new FFN(); model->ResetData(input, target); model->Add(2); model->Add(); @@ -454,7 +454,7 @@ TEST_CASE("GradientMeanSquaredErrorTest", "[LossFunctionsTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN, NguyenWidrowInitialization>* model; + FFN* model; arma::mat input, target; } function; @@ -474,7 +474,7 @@ TEST_CASE("GradientReconstructionLossTest", "[LossFunctionsTest]") input = arma::randu(10, 1); target = arma::randu(2, 1); - model = new FFN, NguyenWidrowInitialization>(); + model = new FFN(); model->ResetData(input, target); model->Add(2); model->Add(); @@ -495,7 +495,7 @@ TEST_CASE("GradientReconstructionLossTest", "[LossFunctionsTest]") arma::mat& Parameters() { return model->Parameters(); } - FFN, NguyenWidrowInitialization>* model; + FFN* model; arma::mat input, target; } function; @@ -509,7 +509,7 @@ TEST_CASE("DiceLossTest", "[LossFunctionsTest]") { arma::mat input1, input2, target, output; double loss; - DiceLoss<> module; + DiceLoss module; // Test the Forward function. Loss should be 0 if input = target. input1 = arma::ones(10, 1); @@ -549,7 +549,7 @@ TEST_CASE("DiceLossTest", "[LossFunctionsTest]") TEST_CASE("SimpleMeanBiasErrorTest", "[LossFunctionsTest]") { arma::mat input, output, target; - MeanBiasError<> module; + MeanBiasError module; // Test the Forward function on a user generator input and compare it against // the manually calculated result. @@ -588,7 +588,7 @@ TEST_CASE("LogCoshLossTest", "[LossFunctionsTest]") { arma::mat input, target, output; double loss; - LogCoshLoss<> module(2); + LogCoshLoss module(2); // Test the Forward function. Loss should be 0 if input = target. input = arma::ones(10, 1); @@ -627,7 +627,7 @@ TEST_CASE("HingeEmbeddingLossTest", "[LossFunctionsTest]") { arma::mat input, target, output; double loss; - HingeEmbeddingLoss<> module; + HingeEmbeddingLoss module; // Test the Forward function. Loss should be 0 if input = target. input = arma::ones(10, 1); @@ -665,7 +665,7 @@ TEST_CASE("HingeEmbeddingLossTest", "[LossFunctionsTest]") TEST_CASE("SimpleL1LossTest", "[LossFunctionsTest]") { arma::mat input1, input2, output, target1, target2; - L1Loss<> module(false); + L1Loss module(false); // Test the Forward function on a user generator input and compare it against // the manually calculated result. @@ -702,7 +702,7 @@ TEST_CASE("CosineEmbeddingLossTest", "[LossFunctionsTest]") { arma::mat input1, input2, y, output; double loss; - CosineEmbeddingLoss<> module; + CosineEmbeddingLoss module; // Test the Forward function. Loss should be 0 if input1 = input2 and y = 1. input1 = arma::mat(1, 10); @@ -750,7 +750,7 @@ TEST_CASE("CosineEmbeddingLossTest", "[LossFunctionsTest]") TEST_CASE("MarginRankingLossTest", "[LossFunctionsTest]") { arma::mat input, input1, input2, target, output; - MarginRankingLoss<> module; + MarginRankingLoss module; // Test the Forward function on a user generator input and compare it against // the manually calculated result. @@ -794,8 +794,8 @@ TEST_CASE("SoftMarginLossTest", "[LossFunctionsTest]") { arma::mat input, target, output, expectedOutput; double loss; - SoftMarginLoss<> module1; - SoftMarginLoss<> module2(false); + SoftMarginLoss module1; + SoftMarginLoss module2(false); input = arma::mat("0.1778 0.0957 0.1397 0.1203 0.2403 0.1925 -0.2264 -0.3400 " "-0.3336"); @@ -849,7 +849,7 @@ TEST_CASE("SoftMarginLossTest", "[LossFunctionsTest]") TEST_CASE("MeanAbsolutePercentageErrorTest", "[LossFunctionsTest]") { arma::mat input, target, output, expectedOutput; - MeanAbsolutePercentageError<> module; + MeanAbsolutePercentageError module; input = arma::mat("3 -0.5 2 7"); target = arma::mat("2.5 0.2 2 8"); @@ -876,7 +876,7 @@ TEST_CASE("MeanAbsolutePercentageErrorTest", "[LossFunctionsTest]") TEST_CASE("VRClassRewardLayerParametersTest", "[LossFunctionsTest]") { // Parameter order : scale, sizeAverage. - VRClassReward<> layer(2, false); + VRClassReward layer(2, false); // Make sure we can get the parameters successfully. REQUIRE(layer.Scale() == 2); @@ -890,7 +890,7 @@ TEST_CASE("TripletMarginLossTest") { arma::mat anchor, positive, negative; arma::mat input, target, output; - TripletMarginLoss<> module; + TripletMarginLoss module; // Test the Forward function on a user generated input and compare it against // the manually calculated result. @@ -938,8 +938,8 @@ TEST_CASE("HingeLossTest", "[LossFunctionsTest]") { arma::mat input, target, target_b, output; double loss, loss_b; - HingeLoss<> module1; - HingeLoss<> module2(false); + HingeLoss module1; + HingeLoss module2(false); // Test the Forward function. Loss should be 0 if input = target. input = arma::ones(10, 1); @@ -1015,8 +1015,8 @@ TEST_CASE("MultiLabelSoftMarginLossTest", "[LossFunctionsTest]") { arma::mat input, target, output, expectedOutput; double loss; - MultiLabelSoftMarginLoss<> module1; - MultiLabelSoftMarginLoss<> module2(false); + MultiLabelSoftMarginLoss module1; + MultiLabelSoftMarginLoss module2(false); input = arma::mat("0.1778 0.0957 0.1397 0.1203 0.2403 0.1925 -0.2264 -0.3400 " "-0.3336"); @@ -1074,8 +1074,8 @@ TEST_CASE("MultiLabelSoftMarginLossWeightedTest", "[LossFunctionsTest]") arma::rowvec weights; double loss; weights = arma::mat("1 2 3"); - MultiLabelSoftMarginLoss<> module1(true, weights); - MultiLabelSoftMarginLoss<> module2(false, weights); + MultiLabelSoftMarginLoss module1(true, weights); + MultiLabelSoftMarginLoss module2(false, weights); input = arma::mat("0.1778 0.0957 0.1397 0.2256 0.1203 0.2403 0.1925 0.3144 " "-0.2264 -0.3400 -0.3336 -0.8695"); diff --git a/src/mlpack/tests/recurrent_network_test.cpp b/src/mlpack/tests/recurrent_network_test.cpp index 5a3c360346..a7d3c459c3 100644 --- a/src/mlpack/tests/recurrent_network_test.cpp +++ b/src/mlpack/tests/recurrent_network_test.cpp @@ -571,7 +571,7 @@ void GenerateNoisySinRNN(arma::cube& data, */ double RNNSineTest(size_t hiddenUnits, size_t rho, size_t numEpochs = 100) { - RNN > net(rho, true); + RNN net(rho, true); net.Add(hiddenUnits); net.Add(hiddenUnits); net.Add(1); @@ -853,8 +853,8 @@ TEST_CASE("RNNFFNTest", "[RecurrentNetworkTest]") { // We'll create an RNN with *no* BPTT, just a simple single-layer linear // network. - RNN, ConstInitialization> rnn; - FFN, ConstInitialization> ffn; + RNN rnn; + FFN ffn; rnn.Add(10); rnn.Add();