From 2da71b1f36ecbbda72a9531607d0d2af76c62038 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Tue, 29 Mar 2022 21:22:46 -0400 Subject: [PATCH] Move some files that aren't yet adapted or are unneeded. --- .../core/cereal/pointer_variant_wrapper.hpp | 159 ------- .../cereal/pointer_vector_variant_wrapper.hpp | 97 ---- src/mlpack/methods/ann/layer_names.hpp | 443 ------------------ .../methods/ann/{ => not_adapted}/brnn.hpp | 0 .../ann/{ => not_adapted}/brnn_impl.hpp | 0 .../ann/{ => not_adapted}/gan/CMakeLists.txt | 0 .../methods/ann/{ => not_adapted}/gan/gan.hpp | 0 .../ann/{ => not_adapted}/gan/gan_impl.hpp | 0 .../{ => not_adapted}/gan/gan_policies.hpp | 0 .../gan/metrics/CMakeLists.txt | 0 .../gan/metrics/inception_score.hpp | 0 .../gan/metrics/inception_score_impl.hpp | 0 .../ann/{ => not_adapted}/gan/wgan_impl.hpp | 0 .../ann/{ => not_adapted}/gan/wgangp_impl.hpp | 0 .../ann/{ => not_adapted}/rbm/CMakeLists.txt | 0 .../methods/ann/{ => not_adapted}/rbm/rbm.hpp | 0 .../ann/{ => not_adapted}/rbm/rbm_impl.hpp | 0 .../{ => not_adapted}/rbm/rbm_policies.hpp | 0 .../rbm/spike_slab_rbm_impl.hpp | 0 src/mlpack/methods/ann/util/CMakeLists.txt | 14 - .../methods/ann/util/check_input_shape.hpp | 53 --- .../methods/ann/util/deterministic_update.hpp | 47 -- .../methods/ann/util/gradient_update.hpp | 55 --- src/mlpack/methods/ann/util/loss_update.hpp | 44 -- src/mlpack/methods/ann/util/reset_update.hpp | 40 -- src/mlpack/methods/ann/visitor/CMakeLists.txt | 71 --- .../methods/ann/visitor/add_visitor.hpp | 64 --- .../methods/ann/visitor/add_visitor_impl.hpp | 64 --- .../methods/ann/visitor/backward_visitor.hpp | 85 ---- .../ann/visitor/backward_visitor_impl.hpp | 84 ---- .../methods/ann/visitor/bias_set_visitor.hpp | 82 ---- .../ann/visitor/bias_set_visitor_impl.hpp | 101 ---- .../methods/ann/visitor/copy_visitor.hpp | 41 -- .../methods/ann/visitor/copy_visitor_impl.hpp | 39 -- .../methods/ann/visitor/delete_visitor.hpp | 51 -- .../ann/visitor/delete_visitor_impl.hpp | 53 --- .../methods/ann/visitor/delta_visitor.hpp | 43 -- .../ann/visitor/delta_visitor_impl.hpp | 36 -- .../ann/visitor/deterministic_set_visitor.hpp | 83 ---- .../deterministic_set_visitor_impl.hpp | 88 ---- .../methods/ann/visitor/forward_visitor.hpp | 54 --- .../ann/visitor/forward_visitor_impl.hpp | 43 -- .../ann/visitor/gradient_set_visitor.hpp | 82 ---- .../ann/visitor/gradient_set_visitor_impl.hpp | 100 ---- .../ann/visitor/gradient_update_visitor.hpp | 82 ---- .../visitor/gradient_update_visitor_impl.hpp | 106 ----- .../methods/ann/visitor/gradient_visitor.hpp | 89 ---- .../ann/visitor/gradient_visitor_impl.hpp | 90 ---- .../ann/visitor/gradient_zero_visitor.hpp | 60 --- .../visitor/gradient_zero_visitor_impl.hpp | 57 --- .../ann/visitor/input_shape_visitor.hpp | 58 --- .../ann/visitor/input_shape_visitor_impl.hpp | 53 --- .../visitor/load_output_parameter_visitor.hpp | 65 --- .../load_output_parameter_visitor_impl.hpp | 66 --- .../methods/ann/visitor/loss_visitor.hpp | 71 --- .../methods/ann/visitor/loss_visitor_impl.hpp | 99 ---- .../ann/visitor/output_height_visitor.hpp | 75 --- .../visitor/output_height_visitor_impl.hpp | 99 ---- .../ann/visitor/output_parameter_visitor.hpp | 43 -- .../visitor/output_parameter_visitor_impl.hpp | 36 -- .../ann/visitor/output_width_visitor.hpp | 75 --- .../ann/visitor/output_width_visitor_impl.hpp | 99 ---- .../ann/visitor/parameters_set_visitor.hpp | 64 --- .../visitor/parameters_set_visitor_impl.hpp | 58 --- .../ann/visitor/parameters_visitor.hpp | 64 --- .../ann/visitor/parameters_visitor_impl.hpp | 58 --- .../ann/visitor/reset_cell_visitor.hpp | 62 --- .../ann/visitor/reset_cell_visitor_impl.hpp | 58 --- .../methods/ann/visitor/reset_visitor.hpp | 75 --- .../ann/visitor/reset_visitor_impl.hpp | 80 ---- .../ann/visitor/reward_set_visitor.hpp | 81 ---- .../ann/visitor/reward_set_visitor_impl.hpp | 87 ---- .../methods/ann/visitor/run_set_visitor.hpp | 83 ---- .../ann/visitor/run_set_visitor_impl.hpp | 88 ---- .../visitor/save_output_parameter_visitor.hpp | 64 --- .../save_output_parameter_visitor_impl.hpp | 64 --- .../ann/visitor/set_input_height_visitor.hpp | 84 ---- .../visitor/set_input_height_visitor_impl.hpp | 102 ---- .../ann/visitor/set_input_width_visitor.hpp | 83 ---- .../visitor/set_input_width_visitor_impl.hpp | 102 ---- .../ann/visitor/weight_set_visitor.hpp | 82 ---- .../ann/visitor/weight_set_visitor_impl.hpp | 100 ---- .../ann/visitor/weight_size_visitor.hpp | 76 --- .../ann/visitor/weight_size_visitor_impl.hpp | 84 ---- src/mlpack/tests/CMakeLists.txt | 5 +- src/mlpack/tests/ann_visitor_test.cpp | 235 ---------- src/mlpack/tests/layer_names_test.cpp | 160 ------- .../tests/{ => not_adapted}/gan_test.cpp | 0 .../{ => not_adapted}/rbm_network_test.cpp | 0 .../tests/{ => not_adapted}/wgan_test.cpp | 0 90 files changed, 2 insertions(+), 5636 deletions(-) delete mode 100644 src/mlpack/core/cereal/pointer_variant_wrapper.hpp delete mode 100644 src/mlpack/core/cereal/pointer_vector_variant_wrapper.hpp delete mode 100644 src/mlpack/methods/ann/layer_names.hpp rename src/mlpack/methods/ann/{ => not_adapted}/brnn.hpp (100%) rename src/mlpack/methods/ann/{ => not_adapted}/brnn_impl.hpp (100%) rename src/mlpack/methods/ann/{ => not_adapted}/gan/CMakeLists.txt (100%) rename src/mlpack/methods/ann/{ => not_adapted}/gan/gan.hpp (100%) rename src/mlpack/methods/ann/{ => not_adapted}/gan/gan_impl.hpp (100%) rename src/mlpack/methods/ann/{ => not_adapted}/gan/gan_policies.hpp (100%) rename src/mlpack/methods/ann/{ => not_adapted}/gan/metrics/CMakeLists.txt (100%) rename src/mlpack/methods/ann/{ => not_adapted}/gan/metrics/inception_score.hpp (100%) rename src/mlpack/methods/ann/{ => not_adapted}/gan/metrics/inception_score_impl.hpp (100%) rename src/mlpack/methods/ann/{ => not_adapted}/gan/wgan_impl.hpp (100%) rename src/mlpack/methods/ann/{ => not_adapted}/gan/wgangp_impl.hpp (100%) rename src/mlpack/methods/ann/{ => not_adapted}/rbm/CMakeLists.txt (100%) rename src/mlpack/methods/ann/{ => not_adapted}/rbm/rbm.hpp (100%) rename src/mlpack/methods/ann/{ => not_adapted}/rbm/rbm_impl.hpp (100%) rename src/mlpack/methods/ann/{ => not_adapted}/rbm/rbm_policies.hpp (100%) rename src/mlpack/methods/ann/{ => not_adapted}/rbm/spike_slab_rbm_impl.hpp (100%) delete mode 100644 src/mlpack/methods/ann/util/CMakeLists.txt delete mode 100644 src/mlpack/methods/ann/util/check_input_shape.hpp delete mode 100644 src/mlpack/methods/ann/util/deterministic_update.hpp delete mode 100644 src/mlpack/methods/ann/util/gradient_update.hpp delete mode 100644 src/mlpack/methods/ann/util/loss_update.hpp delete mode 100644 src/mlpack/methods/ann/util/reset_update.hpp delete mode 100644 src/mlpack/methods/ann/visitor/CMakeLists.txt delete mode 100644 src/mlpack/methods/ann/visitor/add_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/add_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/backward_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/backward_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/bias_set_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/bias_set_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/copy_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/copy_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/delete_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/delete_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/delta_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/delta_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/deterministic_set_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/deterministic_set_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/forward_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/forward_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/gradient_set_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/gradient_set_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/gradient_update_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/gradient_update_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/gradient_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/gradient_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/gradient_zero_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/gradient_zero_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/input_shape_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/load_output_parameter_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/load_output_parameter_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/loss_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/loss_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/output_height_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/output_height_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/output_parameter_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/output_parameter_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/output_width_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/output_width_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/parameters_set_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/parameters_set_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/parameters_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/parameters_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/reset_cell_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/reset_cell_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/reset_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/reset_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/reward_set_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/reward_set_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/run_set_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/run_set_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/save_output_parameter_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/save_output_parameter_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/set_input_height_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/set_input_height_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/set_input_width_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/set_input_width_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/weight_set_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/weight_set_visitor_impl.hpp delete mode 100644 src/mlpack/methods/ann/visitor/weight_size_visitor.hpp delete mode 100644 src/mlpack/methods/ann/visitor/weight_size_visitor_impl.hpp delete mode 100644 src/mlpack/tests/ann_visitor_test.cpp delete mode 100644 src/mlpack/tests/layer_names_test.cpp rename src/mlpack/tests/{ => not_adapted}/gan_test.cpp (100%) rename src/mlpack/tests/{ => not_adapted}/rbm_network_test.cpp (100%) rename src/mlpack/tests/{ => not_adapted}/wgan_test.cpp (100%) diff --git a/src/mlpack/core/cereal/pointer_variant_wrapper.hpp b/src/mlpack/core/cereal/pointer_variant_wrapper.hpp deleted file mode 100644 index 92ac65f7fc..0000000000 --- a/src/mlpack/core/cereal/pointer_variant_wrapper.hpp +++ /dev/null @@ -1,159 +0,0 @@ -/** - * @file core/cereal/pointer_variant_wrapper.hpp - * @author Omar Shrit - * - * Implementation of a boost::variant wrapper to enable the serialization of - * the pointers inside boost variant in cereal - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_CORE_CEREAL_POINTER_VARIANT_WRAPPER_HPP -#define MLPACK_CORE_CEREAL_POINTER_VARIANT_WRAPPER_HPP - -#include -#include -#include -#include - -#include -#include -#include - -#include "pointer_wrapper.hpp" - -namespace cereal { - -// Forward declaration. -template -class PointerVariantWrapper; - -/** - * Serialize a boost variant in which the variant it self is a raw pointer. - * This wrapper will wrap each variant independently by encapsulating each variant - * into the PoninterWrapper we have created already. - * - * @param t A reference to boost variant that holds raw pointer. - */ -template -inline PointerVariantWrapper -make_pointer_variant(boost::variant& t) -{ - return PointerVariantWrapper(t); -} - -template -struct save_visitor : public boost::static_visitor -{ - save_visitor(Archive& ar) : ar(ar) {} - - template - void operator()(const T* value) const - { - ar(CEREAL_POINTER(value)); - } - - template - void operator()(boost::variant& value) const - { - ar(make_pointer_variant(value)); - } - - Archive& ar; -}; - -template -struct load_visitor : public boost::static_visitor -{ - template - static void load_impl(Archive& ar, VariantType& variant, std::true_type) - { - // Note that T will be a pointer type. - T loadVariant; - ar(CEREAL_POINTER(loadVariant)); - variant = loadVariant; - } - - template - static void load_impl(Archive& ar, VariantType& value, std::false_type) - { - // This must be a nested boost::variant. - T loadVariant; - ar(make_pointer_variant(loadVariant)); - value = loadVariant; - } - - template - static void load(Archive& ar, VariantType& variant) - { - // Delegate to the proper load_impl() overload depending on whether T is a - // pointer type. If T is not a pointer type, then we expect it to be a - // nested boost::variant. - load_impl(ar, variant, typename std::is_pointer::type()); - } -}; - -/** - * The objective of this class is to create a wrapper for - * boost::variant. - * Cereal supports the serialization of boost::variant, but - * we need to serialize it if it holds a raw pointers. - * This class depeds on the PointerWrapper we have already created in which it is - * used to serialize each variant independently - */ -template -class PointerVariantWrapper -{ - public: - PointerVariantWrapper(boost::variant& pointerVar) : - pointerVariant(pointerVar) - {} - - template - void save(Archive& ar) const - { - // which represents the index in std::variant. - int which = pointerVariant.which(); - ar(CEREAL_NVP(which)); - save_visitor s(ar); - boost::apply_visitor(s, pointerVariant); - } - - template - void load(Archive& ar) - { - // Load the size of the serialized type. - int which; - ar(CEREAL_NVP(which)); - - // Create function pointers to each overload of load_visitor::load, for - // all T in VariantTypes. - using LoadFuncType = void(*)(Archive&, boost::variant&); - LoadFuncType loadFuncArray[] = { &load_visitor::load... }; - - if (which >= int(sizeof(loadFuncArray)/sizeof(loadFuncArray[0]))) - throw std::runtime_error("Invalid 'which' selector when" - "deserializing boost::variant"); - - loadFuncArray[which](ar, pointerVariant); - } - - private: - boost::variant& pointerVariant; -}; - -/** - * Cereal does not support the serialization of raw pointer. - * This macro enable developers to serialize boost::variant that holds raw - * pointers by using the above PointerVariantWrapper class which replace the - * internal raw pointers by smart pointer internally. - * - * @param T boost::variant that holds raw pointer to be serialized. - */ -#define CEREAL_VARIANT_POINTER(T) cereal::make_pointer_variant(T) - -} // namespace cereal - -#endif // CEREAL_POINTER_VARIANT_WRAPPER_HPP diff --git a/src/mlpack/core/cereal/pointer_vector_variant_wrapper.hpp b/src/mlpack/core/cereal/pointer_vector_variant_wrapper.hpp deleted file mode 100644 index 76f035e7b5..0000000000 --- a/src/mlpack/core/cereal/pointer_vector_variant_wrapper.hpp +++ /dev/null @@ -1,97 +0,0 @@ -/** - * @file core/cereal/pointer_vector_variant_wrapper.hpp - * @author Omar Shrit - * - * Implementation of a boost::variant wrapper to enable the serialization of - * the pointers inside boost variant in cereal - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_CORE_CEREAL_POINTER_VECTOR_VARIANT_WRAPPER_HPP -#define MLPACK_CORE_CEREAL_POINTER_VECTOR_VARIANT_WRAPPER_HPP - -#include "pointer_wrapper.hpp" -#include "pointer_variant_wrapper.hpp" -#include "pointer_vector_wrapper.hpp" - -namespace cereal { - -// Forward declaration -template -class PointerVectorVariantWrapper; - -/** - * Serialize a std::vector of boost variants in which the variant in each boost - * variant is a raw pointer. - * This wrapper will wrap each boost variant independently by encapsulating each - * boost variant into the PoninterVariantWrapper we have created already. - * - * @param t A reference to a vector of boost variants that holds raw pointer. - */ -template -inline PointerVectorVariantWrapper -make_vector_pointer_variant(std::vector>& t) -{ - return PointerVectorVariantWrapper(t); -} - -/** - * The objective of this class is to create a wrapper for - * a vector of boost::variant that holds pointer. - * Cereal supports the serialization of boost::variant, but - * we need to serialize it if it holds a vector of boost::variant that holds a - * pointers. - */ -template -class PointerVectorVariantWrapper -{ - public: - PointerVectorVariantWrapper( - std::vector>& vecPointerVar) - : vectorPointerVariant(vecPointerVar) - {} - - template - void save(Archive& ar) const - { - size_t vecSize = vectorPointerVariant.size(); - ar(CEREAL_NVP(vecSize)); - for (size_t i = 0; i < vectorPointerVariant.size(); ++i) - { - ar(CEREAL_VARIANT_POINTER(vectorPointerVariant.at(i))); - } - } - - template - void load(Archive& ar) - { - size_t vecSize = 0; - ar(CEREAL_NVP(vecSize)); - vectorPointerVariant.resize(vecSize); - for (size_t i = 0; i < vectorPointerVariant.size(); ++i) - { - ar(CEREAL_VARIANT_POINTER(vectorPointerVariant.at(i))); - } - } - - private: - std::vector>& vectorPointerVariant; -}; - -/** - * Cereal does not support the serialization of raw pointer. - * This macro enable developers to serialize a std vector that holds boost::variants - * that holds raw pointers by using the above PointerVectorVariantWrapper class - * which replace the internal raw pointers by smart pointer internally. - * - * @param T std::vector that holds raw pointer to be serialized. - */ -#define CEREAL_VECTOR_VARIANT_POINTER(T) cereal::make_vector_pointer_variant(T) - -} // namespace cereal - -#endif // CEREAL_POINTER_VECTOR_VARIANT_WRAPPER_HPP - diff --git a/src/mlpack/methods/ann/layer_names.hpp b/src/mlpack/methods/ann/layer_names.hpp deleted file mode 100644 index 15596efea3..0000000000 --- a/src/mlpack/methods/ann/layer_names.hpp +++ /dev/null @@ -1,443 +0,0 @@ -/** - * @file methods/ann/layer_names.hpp - * @author Sreenik Seal - * - * Implementation of a class that converts a given ann layer to string format. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ - -#include -#include -#include -#include -#include - -using namespace mlpack::ann; - -/** - * Implementation of a class that returns the string representation of the - * name of the given layer. - */ -class LayerNameVisitor : public boost::static_visitor -{ - public: - //! Create the LayerNameVisitor object. - LayerNameVisitor() - { - } - - /** - * Return the name of the given layer of type AdaptiveMaxPooling as string. - * - * @param * Given layer of type AdaptiveMaxPooling. - * @return The string representation of the layer. - */ - std::string LayerString(AdaptiveMaxPooling<> * /*layer*/) const - { - return "adaptivemaxpooling"; - } - - /** - * Return the name of the given layer of type AdaptiveMeanPooling as string. - * - * @param * Given layer of type AdaptiveMeanPooling. - * @return The string representation of the layer. - */ - std::string LayerString(AdaptiveMeanPooling<> * /*layer*/) const - { - return "adaptivemeanpooling"; - } - - /** - * Return the name of the given layer of type AtrousConvolution as a string. - * - * @param * Given layer of type AtrousConvolution. - * @return The string representation of the layer. - */ - std::string LayerString(AtrousConvolution<>* /*layer*/) const - { - return "atrousconvolution"; - } - - /** - * Return the name of the given layer of type AlphaDropout as a string. - * - * @param * Given layer of type AlphaDropout. - * @return The string representation of the layer. - */ - std::string LayerString(AlphaDropout<>* /*layer*/) const - { - return "alphadropout"; - } - - /** - * Return the name of the given layer of type BatchNorm as a string. - * - * @param * Given layer of type BatchNorm. - * @return The string representation of the layer. - */ - std::string LayerString(BatchNorm<>* /*layer*/) const - { - return "batchnorm"; - } - - /** - * Return the name of the given layer of type Constant as a string. - * - * @param * Given layer of type Constant. - * @return The string representation of the layer. - */ - std::string LayerString(Constant<>* /*layer*/) const - { - return "constant"; - } - - /** - * Return the name of the given layer of type Convolution as a string. - * - * @param * Given layer of type Convolution. - * @return The string representation of the layer. - */ - std::string LayerString(Convolution<>* /*layer*/) const - { - return "convolution"; - } - - /** - * Return the name of the given layer of type DropConnect as a string. - * - * @param * Given layer of type DropConnect. - * @return The string representation of the layer. - */ - std::string LayerString(DropConnect<>* /*layer*/) const - { - return "dropconnect"; - } - - /** - * Return the name of the given layer of type Dropout as a string. - * - * @param * Given layer of type Dropout. - * @return The string representation of the layer. - */ - std::string LayerString(Dropout<>* /*layer*/) const - { - return "dropout"; - } - - /** - * Return the name of the given layer of type FlexibleReLU as a string. - * - * @param * Given layer of type FlexibleReLU. - * @return The string representation of the layer. - */ - std::string LayerString(FlexibleReLU<>* /*layer*/) const - { - return "flexiblerelu"; - } - - /** - * Return the name of the given layer of type LayerNorm as a string. - * - * @param * Given layer of type LayerNorm. - * @return The string representation of the layer. - */ - std::string LayerString(LayerNorm<>* /*layer*/) const - { - return "layernorm"; - } - - /** - * Return the name of the given layer of type Linear as a string. - * - * @param * Given layer of type Linear. - * @return The string representation of the layer. - */ - std::string LayerString(Linear<>* /*layer*/) const - { - return "linear"; - } - - /** - * Return the name of the given layer of type LinearNoBias as a string. - * - * @param * Given layer of type LinearNoBias. - * @return The string representation of the layer. - */ - std::string LayerString(LinearNoBias<>* /*layer*/) const - { - return "linearnobias"; - } - - /** - * Return the name of the given layer of type NoisyLinear as a string. - * - * @param * Given layer of type NoisyLinear. - * @return The string representation of the layer. - */ - std::string LayerString(NoisyLinear<>* /*layer*/) const - { - return "noisylinear"; - } - - /** - * Return the name of the given layer of type MaxPooling as a string. - * - * @param * Given layer of type MaxPooling. - * @return The string representation of the layer. - */ - std::string LayerString(MaxPooling<>* /*layer*/) const - { - return "maxpooling"; - } - - /** - * Return the name of the given layer of type MeanPooling as a string. - * - * @param * Given layer of type MeanPooling. - * @return The string representation of the layer. - */ - std::string LayerString(MeanPooling<>* /*layer*/) const - { - return "meanpooling"; - } - - /** - * Return the name of the given layer of type LpPooling as a string. - * - * @param * Given layer of type LpPooling. - * @return The string representation of the layer. - */ - std::string LayerString(LpPooling<>* /*layer*/) const - { - return "lppooling"; - } - - /** - * Return the name of the given layer of type MultiplyConstant as a string. - * - * @param * Given layer of type MultiplyConstant. - * @return The string representation of the layer. - */ - std::string LayerString(MultiplyConstant<>* /*layer*/) const - { - return "multiplyconstant"; - } - - /** - * Return the name of the given layer of type ReLULayer as a string. - * - * @param * Given layer of type ReLULayer. - * @return The string representation of the layer. - */ - std::string LayerString(ReLULayer<>* /*layer*/) const - { - return "relu"; - } - - /** - * Return the name of the given layer of type TransposedConvolution as a - * string. - * - * @param * Given layer of type TransposedConvolution. - * @return The string representation of the layer. - */ - std::string LayerString(TransposedConvolution<>* /*layer*/) const - { - return "transposedconvolution"; - } - - /** - * Return the name of the given layer of type IdentityLayer as a string. - * - * @param * Given layer of type IdentityLayer. - * @return The string representation of the layer. - */ - std::string LayerString(IdentityLayer<>* /*layer*/) const - { - return "identity"; - } - - /** - * Return the name of the given layer of type TanHLayer as a string. - * - * @param * Given layer of type TanHLayer. - * @return The string representation of the layer. - */ - std::string LayerString(TanHLayer<>* /*layer*/) const - { - return "tanh"; - } - - /** - * Return the name of the given layer of type ELU as a string. - * - * @param * Given layer of type ELU. - * @return The string representation of the layer. - */ - std::string LayerString(ELU<>* /*layer*/) const - { - return "elu"; - } - - /** - * Return the name of the given layer of type HardTanH as a string. - * - * @param * Given layer of type HardTanH. - * @return The string representation of the layer. - */ - std::string LayerString(HardTanH<>* /*layer*/) const - { - return "hardtanh"; - } - - /** - * Return the name of the given layer of type LeakyReLU as a string. - * - * @param * Given layer of type LeakyReLU. - * @return The string representation of the layer. - */ - std::string LayerString(LeakyReLU<>* /*layer*/) const - { - return "leakyrelu"; - } - - /** - * Return the name of the given layer of type PReLU as a string. - * - * @param * Given layer of type PReLU. - * @return The string representation of the layer. - */ - std::string LayerString(PReLU<>* /*layer*/) const - { - return "prelu"; - } - - /** - * Return the name of the given layer of type SigmoidLayer as a string. - * - * @param * Given layer of type SigmoidLayer. - * @return The string representation of the layer. - */ - std::string LayerString(SigmoidLayer<>* /*layer*/) const - { - return "sigmoid"; - } - - /** - * Return the name of the given layer of type LogSoftMax as a string. - * - * @param * Given layer of type LogSoftMax. - * @return The string representation of the layer. - */ - std::string LayerString(LogSoftMax<>* /*layer*/) const - { - return "logsoftmax"; - } - - /* - * Return the name of the given layer of type LSTM as a string. - * - * @param * Given layer of type LSTM. - * @return The string representation of the layer. - */ - std::string LayerString(LSTM<>* /*layer*/) const - { - return "lstm"; - } - - /** - * Return the name of the given layer of type CReLU as a string. - * - * @param * Given layer of type CReLU. - * @return The string representation of the layer. - */ - std::string LayerString(CReLU<>* /*layer*/) const - { - return "crelu"; - } - - /** - * Return the name of the given layer of type Highway as a string. - * - * @param * Given layer of type Highway. - * @return The string representation of the layer. - */ - std::string LayerString(Highway<>* /*layer*/) const - { - return "highway"; - } - - /** - * Return the name of the given layer of type GRU as a string. - * - * @param * Given layer of type GRU. - * @return The string representation of the layer. - */ - std::string LayerString(GRU<>* /*layer*/) const - { - return "gru"; - } - - /** - * Return the name of the given layer of type Glimpse as a string. - * - * @param * Given layer of type Glimpse. - * @return The string representation of the layer. - */ - std::string LayerString(Glimpse<>* /*layer*/) const - { - return "glimpse"; - } - - /** - * Return the name of the given layer of type FastLSTM as a string. - * - * @param * Given layer of type FastLSTM. - * @return The string representation of the layer. - */ - std::string LayerString(FastLSTM<>* /*layer*/) const - { - return "fastlstm"; - } - - /** - * Return the name of the given layer of type WeightNorm as a string. - * - * @param * Given layer of type WeightNorm. - * @return The string representation of the layer. - */ - std::string LayerString(WeightNorm<>* /*layer*/) const - { - return "weightnorm"; - } - - /** - * Return the name of the layer of specified type as a string. - * - * @param * Given layer of any type. - * @return A string declaring that the layer is unsupported. - */ - template - std::string LayerString(T* /*layer*/) const - { - return "unsupported"; - } - - //! Overload function call. - std::string operator()(MoreTypes layer) const - { - return layer.apply_visitor(*this); - } - - //! Overload function call. - template - std::string operator()(LayerType* layer) const - { - return LayerString(layer); - } -}; diff --git a/src/mlpack/methods/ann/brnn.hpp b/src/mlpack/methods/ann/not_adapted/brnn.hpp similarity index 100% rename from src/mlpack/methods/ann/brnn.hpp rename to src/mlpack/methods/ann/not_adapted/brnn.hpp diff --git a/src/mlpack/methods/ann/brnn_impl.hpp b/src/mlpack/methods/ann/not_adapted/brnn_impl.hpp similarity index 100% rename from src/mlpack/methods/ann/brnn_impl.hpp rename to src/mlpack/methods/ann/not_adapted/brnn_impl.hpp diff --git a/src/mlpack/methods/ann/gan/CMakeLists.txt b/src/mlpack/methods/ann/not_adapted/gan/CMakeLists.txt similarity index 100% rename from src/mlpack/methods/ann/gan/CMakeLists.txt rename to src/mlpack/methods/ann/not_adapted/gan/CMakeLists.txt diff --git a/src/mlpack/methods/ann/gan/gan.hpp b/src/mlpack/methods/ann/not_adapted/gan/gan.hpp similarity index 100% rename from src/mlpack/methods/ann/gan/gan.hpp rename to src/mlpack/methods/ann/not_adapted/gan/gan.hpp diff --git a/src/mlpack/methods/ann/gan/gan_impl.hpp b/src/mlpack/methods/ann/not_adapted/gan/gan_impl.hpp similarity index 100% rename from src/mlpack/methods/ann/gan/gan_impl.hpp rename to src/mlpack/methods/ann/not_adapted/gan/gan_impl.hpp diff --git a/src/mlpack/methods/ann/gan/gan_policies.hpp b/src/mlpack/methods/ann/not_adapted/gan/gan_policies.hpp similarity index 100% rename from src/mlpack/methods/ann/gan/gan_policies.hpp rename to src/mlpack/methods/ann/not_adapted/gan/gan_policies.hpp diff --git a/src/mlpack/methods/ann/gan/metrics/CMakeLists.txt b/src/mlpack/methods/ann/not_adapted/gan/metrics/CMakeLists.txt similarity index 100% rename from src/mlpack/methods/ann/gan/metrics/CMakeLists.txt rename to src/mlpack/methods/ann/not_adapted/gan/metrics/CMakeLists.txt diff --git a/src/mlpack/methods/ann/gan/metrics/inception_score.hpp b/src/mlpack/methods/ann/not_adapted/gan/metrics/inception_score.hpp similarity index 100% rename from src/mlpack/methods/ann/gan/metrics/inception_score.hpp rename to src/mlpack/methods/ann/not_adapted/gan/metrics/inception_score.hpp diff --git a/src/mlpack/methods/ann/gan/metrics/inception_score_impl.hpp b/src/mlpack/methods/ann/not_adapted/gan/metrics/inception_score_impl.hpp similarity index 100% rename from src/mlpack/methods/ann/gan/metrics/inception_score_impl.hpp rename to src/mlpack/methods/ann/not_adapted/gan/metrics/inception_score_impl.hpp diff --git a/src/mlpack/methods/ann/gan/wgan_impl.hpp b/src/mlpack/methods/ann/not_adapted/gan/wgan_impl.hpp similarity index 100% rename from src/mlpack/methods/ann/gan/wgan_impl.hpp rename to src/mlpack/methods/ann/not_adapted/gan/wgan_impl.hpp diff --git a/src/mlpack/methods/ann/gan/wgangp_impl.hpp b/src/mlpack/methods/ann/not_adapted/gan/wgangp_impl.hpp similarity index 100% rename from src/mlpack/methods/ann/gan/wgangp_impl.hpp rename to src/mlpack/methods/ann/not_adapted/gan/wgangp_impl.hpp diff --git a/src/mlpack/methods/ann/rbm/CMakeLists.txt b/src/mlpack/methods/ann/not_adapted/rbm/CMakeLists.txt similarity index 100% rename from src/mlpack/methods/ann/rbm/CMakeLists.txt rename to src/mlpack/methods/ann/not_adapted/rbm/CMakeLists.txt diff --git a/src/mlpack/methods/ann/rbm/rbm.hpp b/src/mlpack/methods/ann/not_adapted/rbm/rbm.hpp similarity index 100% rename from src/mlpack/methods/ann/rbm/rbm.hpp rename to src/mlpack/methods/ann/not_adapted/rbm/rbm.hpp diff --git a/src/mlpack/methods/ann/rbm/rbm_impl.hpp b/src/mlpack/methods/ann/not_adapted/rbm/rbm_impl.hpp similarity index 100% rename from src/mlpack/methods/ann/rbm/rbm_impl.hpp rename to src/mlpack/methods/ann/not_adapted/rbm/rbm_impl.hpp diff --git a/src/mlpack/methods/ann/rbm/rbm_policies.hpp b/src/mlpack/methods/ann/not_adapted/rbm/rbm_policies.hpp similarity index 100% rename from src/mlpack/methods/ann/rbm/rbm_policies.hpp rename to src/mlpack/methods/ann/not_adapted/rbm/rbm_policies.hpp diff --git a/src/mlpack/methods/ann/rbm/spike_slab_rbm_impl.hpp b/src/mlpack/methods/ann/not_adapted/rbm/spike_slab_rbm_impl.hpp similarity index 100% rename from src/mlpack/methods/ann/rbm/spike_slab_rbm_impl.hpp rename to src/mlpack/methods/ann/not_adapted/rbm/spike_slab_rbm_impl.hpp diff --git a/src/mlpack/methods/ann/util/CMakeLists.txt b/src/mlpack/methods/ann/util/CMakeLists.txt deleted file mode 100644 index dffec0c265..0000000000 --- a/src/mlpack/methods/ann/util/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Define the files we need to compile -# Anything not in this list will not be compiled into mlpack. -set(SOURCES - check_input_shape.hpp -) - -# Add directory name to sources. -set(DIR_SRCS) -foreach(file ${SOURCES}) - set(DIR_SRCS ${DIR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/${file}) -endforeach() -# Append sources (with directory name) to list of all mlpack sources (used at -# the parent scope). -set(MLPACK_SRCS ${MLPACK_SRCS} ${DIR_SRCS} PARENT_SCOPE) \ No newline at end of file diff --git a/src/mlpack/methods/ann/util/check_input_shape.hpp b/src/mlpack/methods/ann/util/check_input_shape.hpp deleted file mode 100644 index 59f2c72da2..0000000000 --- a/src/mlpack/methods/ann/util/check_input_shape.hpp +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @file methods/ann/util/check_input_shape.hpp - * @author Khizir Siddiqui - * @author Nippun Sharma - * - * Definition of the CheckInputShape() function that checks - * whether the shape of input is consistent with the first layer - * of the neural network. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ - -#ifndef MLPACK_METHODS_ANN_UTIL_CHECK_INPUT_SHAPE_HPP -#define MLPACK_METHODS_ANN_UTIL_CHECK_INPUT_SHAPE_HPP - -#include - -namespace mlpack { -namespace ann /** Artificial Neural Network. */{ - -template -void CheckInputShape(const T& network, - const size_t inputShape, - const std::string& functionName) -{ - for (size_t l = 0; l < network.size(); ++l) - { - size_t layerInShape = boost::apply_visitor(InShapeVisitor(), network[l]); - if (layerInShape == 0) - { - continue; - } - else if (layerInShape == inputShape) - { - break; - } - else - { - std::string estr = functionName + ": the first layer of the network " + - "expects " + std::to_string(layerInShape) + " elements, but the " + - "input has " + std::to_string(inputShape) + " dimensions!"; - throw std::logic_error(estr); - } - } -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/util/deterministic_update.hpp b/src/mlpack/methods/ann/util/deterministic_update.hpp deleted file mode 100644 index 682358b580..0000000000 --- a/src/mlpack/methods/ann/util/deterministic_update.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/** - * @file methods/ann/util/deterministic_update.hpp - * @author Marcus Edel - * - * Definition of the DeterministicUpdate() function to update the layer and - * sub-layer training/testing state. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ - -#ifndef MLPACK_METHODS_ANN_UTIL_DETERMINISTIC_UPDATE_HPP -#define MLPACK_METHODS_ANN_UTIL_DETERMINISTIC_UPDATE_HPP - -namespace mlpack { -namespace ann /** Artificial Neural Network. */{ - -/** - * Update the deterministic parameter for the given layer and all sub-layer - * with the specified value. - * - * @note During training you should set the deterministic parameter for each - * layer to false and during testing you should set deterministic to true. - * - * @tparam LayerType The type of the given layer e.g. Dropout, DropConnect. - * @param layer The layer (including sub-layer) to be updated. - * @param deterministic The training/testing state, - * training = false, testing = true. - */ -template -void DeterministicUpdate(const LayerType& layer, const bool deterministic) -{ - layer->Deterministic() = deterministic; - - if (layer->Model().size() > 0) - { - for (size_t i = 0; i < layer->Model().size(); ++i) - DeterministicUpdate(layer->Model()[i], deterministic); - } -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/util/gradient_update.hpp b/src/mlpack/methods/ann/util/gradient_update.hpp deleted file mode 100644 index e5fdab685b..0000000000 --- a/src/mlpack/methods/ann/util/gradient_update.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/** - * @file methods/ann/util/gradient_update.hpp - * @author Marcus Edel - * - * Definition of the GradientUpdate() function which assignes a portion of the - * given gradient to the layer/sub-layer. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ - -#ifndef MLPACK_METHODS_ANN_UTIL_GRADIENT_UPDATE_HPP -#define MLPACK_METHODS_ANN_UTIL_GRADIENT_UPDATE_HPP - -namespace mlpack { -namespace ann /** Artificial Neural Network. */{ - -/** - * Assign a portion of the given gradient matrix to the given layer/sub-layer. - * - * @tparam LayerType The type of the layer that the gradient is assigned to - * e.g. Linear, Convolution. - * @tparam MathTest The type of the gradient matrix e.g. arma::Mat, - * arma::Mat. - * @param layer The layer that the gradient is assigned to. - * @param offset The beginning of the gradient portion we assign to the layer. - */ -template -size_t GradientUpdate( - const LayerType& layer, MatType& gradient, const size_t offset) -{ - size_t size = 0; - - if (layer->Parameters().n_elem > 0) - { - layer->Gradient() = arma::mat(gradient.memptr() + offset, - layer->Parameters().n_rows, layer->Parameters().n_cols, false, false); - size += layer->Parameters().n_elem; - } - - if (layer->Model().size() > 0) - { - for (size_t i = 0; i < layer->Model().size(); ++i) - size += GradientUpdate(layer->Model()[i], gradient, offset + size); - } - - return size; -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/util/loss_update.hpp b/src/mlpack/methods/ann/util/loss_update.hpp deleted file mode 100644 index dbe648731b..0000000000 --- a/src/mlpack/methods/ann/util/loss_update.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/** - * @file methods/ann/util/loss_update.hpp - * @author Marcus Edel - * - * Definition of the LossUpdate() function which returns the layer/sub-layer - * loss. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ - -#ifndef MLPACK_METHODS_ANN_UTIL_LOSS_UPDATE_HPP -#define MLPACK_METHODS_ANN_UTIL_LOSS_UPDATE_HPP - -namespace mlpack { -namespace ann /** Artificial Neural Network. */{ - -/** - * Get the los from the given layer/sub-layer. - * - * @tparam Layer The type of the given layer. - * @param layer The layer to get the loss for. - * @return The layer loss. - */ -template -double LossUpdate(const LayerType& layer) -{ - double loss = layer->Loss(); - - if (layer->Model().size() > 0) - { - for (size_t i = 0; i < layer->Model().size(); ++i) - loss += LossUpdate(layer->Model()[i]); - } - - return loss; -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/util/reset_update.hpp b/src/mlpack/methods/ann/util/reset_update.hpp deleted file mode 100644 index 0a0fb6bfb6..0000000000 --- a/src/mlpack/methods/ann/util/reset_update.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @file methods/ann/util/reset_update.hpp - * @author Marcus Edel - * - * Definition of the ResetUpdate() function which resets the layer state. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ - -#ifndef MLPACK_METHODS_ANN_UTIL_RESET_UPDATE_HPP -#define MLPACK_METHODS_ANN_UTIL_RESET_UPDATE_HPP - -namespace mlpack { -namespace ann /** Artificial Neural Network. */{ - -/** - * Call the Reset() function for the given layer/sub-layer. - * - * @tparam LayerType The type of the layer that the Reset() function is called. - * @param layer The layer for which the Reset() function is called. - */ -template -void ResetUpdate(const LayerType& layer) -{ - layer->Reset(); - - if (layer->Model().size() > 0) - { - for (size_t i = 0; i < layer->Model().size(); ++i) - ResetUpdate(layer->Model()[i]); - } -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/CMakeLists.txt b/src/mlpack/methods/ann/visitor/CMakeLists.txt deleted file mode 100644 index fa207d6092..0000000000 --- a/src/mlpack/methods/ann/visitor/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ -# Define the files we need to compile -# Anything not in this list will not be compiled into mlpack. -set(SOURCES - add_visitor.hpp - add_visitor_impl.hpp - backward_visitor.hpp - backward_visitor_impl.hpp - bias_set_visitor.hpp - bias_set_visitor_impl.hpp - copy_visitor.hpp - copy_visitor_impl.hpp - delete_visitor.hpp - delete_visitor_impl.hpp - delta_visitor.hpp - delta_visitor_impl.hpp - deterministic_set_visitor.hpp - deterministic_set_visitor_impl.hpp - forward_visitor.hpp - forward_visitor_impl.hpp - gradient_set_visitor.hpp - gradient_set_visitor_impl.hpp - gradient_update_visitor.hpp - gradient_update_visitor_impl.hpp - gradient_visitor.hpp - gradient_visitor_impl.hpp - gradient_zero_visitor.hpp - gradient_zero_visitor_impl.hpp - load_output_parameter_visitor.hpp - load_output_parameter_visitor_impl.hpp - loss_visitor.hpp - loss_visitor_impl.hpp - output_height_visitor.hpp - output_height_visitor_impl.hpp - output_parameter_visitor.hpp - output_parameter_visitor_impl.hpp - output_width_visitor.hpp - output_width_visitor_impl.hpp - parameters_set_visitor.hpp - parameters_set_visitor_impl.hpp - parameters_visitor.hpp - parameters_visitor_impl.hpp - reset_cell_visitor.hpp - reset_cell_visitor_impl.hpp - reset_visitor.hpp - reset_visitor_impl.hpp - reward_set_visitor.hpp - reward_set_visitor_impl.hpp - run_set_visitor.hpp - run_set_visitor_impl.hpp - save_output_parameter_visitor.hpp - save_output_parameter_visitor_impl.hpp - set_input_height_visitor.hpp - set_input_height_visitor_impl.hpp - set_input_width_visitor.hpp - set_input_width_visitor_impl.hpp - weight_set_visitor.hpp - weight_set_visitor_impl.hpp - weight_size_visitor.hpp - weight_size_visitor_impl.hpp - input_shape_visitor.hpp - input_shape_visitor_impl.hpp -) - -# Add directory name to sources. -set(DIR_SRCS) -foreach(file ${SOURCES}) - set(DIR_SRCS ${DIR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/${file}) -endforeach() -# Append sources (with directory name) to list of all mlpack sources (used at -# the parent scope). -set(MLPACK_SRCS ${MLPACK_SRCS} ${DIR_SRCS} PARENT_SCOPE) diff --git a/src/mlpack/methods/ann/visitor/add_visitor.hpp b/src/mlpack/methods/ann/visitor/add_visitor.hpp deleted file mode 100644 index fe8096a0ba..0000000000 --- a/src/mlpack/methods/ann/visitor/add_visitor.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/** - * @file methods/ann/visitor/add_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the Add() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_ADD_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_ADD_VISITOR_HPP - -#include -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * AddVisitor exposes the Add() method of the given module. - */ -template -class AddVisitor : public boost::static_visitor -{ - public: - //! Exposes the Add() method of the given module. - template - AddVisitor(T newLayer); - - //! Exposes the Add() method. - template - void operator()(LayerType* layer) const; - - void operator()(MoreTypes layer) const; - - private: - //! The layer that should be added. - LayerTypes newLayer; - - //! Only add the layer if the module implements the Add() function. - template - typename std::enable_if< - HasAddCheck)>::value, void>::type - LayerAdd(T* layer) const; - - //! Do not add the layer if the module doesn't implement the Add() function. - template - typename std::enable_if< - !HasAddCheck)>::value, void>::type - LayerAdd(T* layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "add_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/add_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/add_visitor_impl.hpp deleted file mode 100644 index 62725e95ed..0000000000 --- a/src/mlpack/methods/ann/visitor/add_visitor_impl.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/** - * @file methods/ann/visitor/add_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the Add() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_ADD_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_ADD_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "add_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! AddVisitor visitor class. -template -template -inline AddVisitor::AddVisitor(T newLayer) : - newLayer(std::move(newLayer)) -{ - /* Nothing to do here. */ -} - -template -template -inline void AddVisitor::operator()(LayerType* layer) const -{ - LayerAdd(layer); -} - -template -inline void AddVisitor::operator()(MoreTypes layer) const -{ - layer.apply_visitor(*this); -} - -template -template -inline typename std::enable_if< - HasAddCheck)>::value, void>::type -AddVisitor::LayerAdd(T* layer) const -{ - layer->Add(newLayer); -} - -template -template -inline typename std::enable_if< - !HasAddCheck)>::value, void>::type -AddVisitor::LayerAdd(T* /* layer */) const -{ - /* Nothing to do here. */ -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/backward_visitor.hpp b/src/mlpack/methods/ann/visitor/backward_visitor.hpp deleted file mode 100644 index e59ff53eef..0000000000 --- a/src/mlpack/methods/ann/visitor/backward_visitor.hpp +++ /dev/null @@ -1,85 +0,0 @@ -/** - * @file methods/ann/visitor/backward_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the Backward() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_BACKWARD_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_BACKWARD_VISITOR_HPP - -#include -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * BackwardVisitor executes the Backward() function given the input, error and - * delta parameter. - */ -class BackwardVisitor : public boost::static_visitor -{ - public: - //! Execute the Backward() function given the input, error and delta - //! parameter. - BackwardVisitor(const arma::mat& input, - const arma::mat& error, - arma::mat& delta); - - //! Execute the Backward() function for the layer with the specified index. - BackwardVisitor(const arma::mat& input, - const arma::mat& error, - arma::mat& delta, - const size_t index); - - //! Execute the Backward() function. - template - void operator()(LayerType* layer) const; - - void operator()(MoreTypes layer) const; - - private: - //! The input parameter set. - const arma::mat& input; - - //! The error parameter. - const arma::mat& error; - - //! The delta parameter. - arma::mat& delta; - - //! The index of the layer to run. - size_t index; - - //! Indicates whether to use index or not - bool hasIndex; - - //! Execute the Backward() function if the module does not have Run() - //! check. - template - typename std::enable_if< - !HasRunCheck::value, void>::type - LayerBackward(T* layer, arma::mat& input) const; - - //! Execute the Backward() function if the module is has Run() function. - template - typename std::enable_if< - HasRunCheck::value, void>::type - LayerBackward(T* layer, arma::mat& input) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "backward_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/backward_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/backward_visitor_impl.hpp deleted file mode 100644 index 24f6c180d9..0000000000 --- a/src/mlpack/methods/ann/visitor/backward_visitor_impl.hpp +++ /dev/null @@ -1,84 +0,0 @@ -/** - * @file methods/ann/visitor/backward_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the Backward() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_BACKWARD_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_BACKWARD_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "backward_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! BackwardVisitor visitor class. -inline BackwardVisitor::BackwardVisitor(const arma::mat& input, - const arma::mat& error, - arma::mat& delta) : - input(input), - error(error), - delta(delta), - index(0), - hasIndex(false) -{ - /* Nothing to do here. */ -} - -inline BackwardVisitor::BackwardVisitor(const arma::mat& input, - const arma::mat& error, - arma::mat& delta, - const size_t index) : - input(input), - error(error), - delta(delta), - index(index), - hasIndex(true) -{ - /* Nothing to do here. */ -} - -template -inline void BackwardVisitor::operator()(LayerType* layer) const -{ - LayerBackward(layer, layer->OutputParameter()); -} - -inline void BackwardVisitor::operator()(MoreTypes layer) const -{ - layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - !HasRunCheck::value, void>::type -BackwardVisitor::LayerBackward(T* layer, arma::mat& /* input */) const -{ - layer->Backward(input, error, delta); -} - -template -inline typename std::enable_if< - HasRunCheck::value, void>::type -BackwardVisitor::LayerBackward(T* layer, arma::mat& /* input */) const -{ - if (!hasIndex) - { - layer->Backward(input, error, delta); - } - else - { - layer->Backward(input, error, delta, index); - } -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/bias_set_visitor.hpp b/src/mlpack/methods/ann/visitor/bias_set_visitor.hpp deleted file mode 100644 index c081c73a2a..0000000000 --- a/src/mlpack/methods/ann/visitor/bias_set_visitor.hpp +++ /dev/null @@ -1,82 +0,0 @@ -/** - * @file methods/ann/visitor/bias_set_visitor.hpp - * @author Toshal Agrawal - * - * This file provides an abstraction for the Bias() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_BIAS_SET_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_BIAS_SET_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * BiasSetVisitor updates the module bias parameters given the parameters set. - */ -class BiasSetVisitor : public boost::static_visitor -{ - public: - //! Update the bias parameters given the parameters' set and offset. - BiasSetVisitor(arma::mat& weight, const size_t offset = 0); - - //! Update the parameters' set. - template - size_t operator()(LayerType* layer) const; - - size_t operator()(MoreTypes layer) const; - - private: - //! The parameters' set. - arma::mat& weight; - - //! The parameters' offset. - const size_t offset; - - //! Do not update the bias parameters if the module doesn't implement the - //! Bias() or Model() function. - template - typename std::enable_if< - !HasBiasCheck::value && - !HasModelCheck::value, size_t>::type - LayerSize(T* layer) const; - - //! Update the bias parameters if the module implements the Model() function. - template - typename std::enable_if< - !HasBiasCheck::value && - HasModelCheck::value, size_t>::type - LayerSize(T* layer) const; - - //! Update the bias parameters if the module implements the Bias() function. - template - typename std::enable_if< - HasBiasCheck::value && - !HasModelCheck::value, size_t>::type - LayerSize(T* layer) const; - - //! Update the bias parameters if the module implements the Model() and - //! Bias() function. - template - typename std::enable_if< - HasBiasCheck::value && - HasModelCheck::value, size_t>::type - LayerSize(T* layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "bias_set_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/bias_set_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/bias_set_visitor_impl.hpp deleted file mode 100644 index 2eacbb61d6..0000000000 --- a/src/mlpack/methods/ann/visitor/bias_set_visitor_impl.hpp +++ /dev/null @@ -1,101 +0,0 @@ -/** - * @file methods/ann/visitor/bias_set_visitor_impl.hpp - * @author Toshal Agrawal - * - * Implementation of the Bias() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_BIAS_SET_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_BIAS_SET_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "bias_set_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! BiasSetVisitor visitor class. -inline BiasSetVisitor::BiasSetVisitor(arma::mat& weight, const size_t offset) : - weight(weight), - offset(offset) -{ - /* Nothing to do here. */ -} - -template -inline size_t BiasSetVisitor::operator()(LayerType* layer) const -{ - return LayerSize(layer); -} - -inline size_t BiasSetVisitor::operator()(MoreTypes layer) const -{ - return layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - !HasBiasCheck::value && - !HasModelCheck::value, size_t>::type -BiasSetVisitor::LayerSize(T* /* layer */) const -{ - return 0; -} - -template -inline typename std::enable_if< - !HasBiasCheck::value && - HasModelCheck::value, size_t>::type -BiasSetVisitor::LayerSize(T* layer) const -{ - size_t modelOffset = 0; - - for (size_t i = 0; i < layer->Model().size(); ++i) - { - modelOffset += boost::apply_visitor(BiasSetVisitor( - weight, modelOffset + offset), layer->Model()[i]); - } - - return modelOffset; -} - -template -inline typename std::enable_if< - HasBiasCheck::value && - !HasModelCheck::value, size_t>::type -BiasSetVisitor::LayerSize(T* layer) const -{ - layer->Bias() = arma::mat(weight.memptr() + offset, - layer->Bias().n_rows, layer->Bias().n_cols, false, false); - - return layer->Bias().n_elem; -} - -template -inline typename std::enable_if< - HasBiasCheck::value && - HasModelCheck::value, size_t>::type -BiasSetVisitor::LayerSize(T* layer) const -{ - layer->Bias() = arma::mat(weight.memptr() + offset, - layer->Bias().n_rows, layer->Bias().n_cols, false, false); - - size_t modelOffset = layer->Bias().n_elem; - - for (size_t i = 0; i < layer->Model().size(); ++i) - { - modelOffset += boost::apply_visitor(BiasSetVisitor( - weight, modelOffset + offset), layer->Model()[i]); - } - - return modelOffset; -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/copy_visitor.hpp b/src/mlpack/methods/ann/visitor/copy_visitor.hpp deleted file mode 100644 index 14bf5f91ad..0000000000 --- a/src/mlpack/methods/ann/visitor/copy_visitor.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/** - * @file methods/ann/visitor/copy_visitor.hpp - * @author Shangtong Zhang - * - * This file provides an abstraction for copy between layers. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_COPY_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_COPY_VISITOR_HPP - -#include -#include - -namespace mlpack { -namespace ann { - -/** - * This visitor is to support copy constructor for neural network module. - * We want a layer-wise copy rather than simple duplicate the pointer. - */ -template -class CopyVisitor : public boost::static_visitor > -{ - public: - template - LayerTypes operator()(LayerType*) const; - - LayerTypes operator()(MoreTypes) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation -#include "copy_visitor_impl.hpp" -#endif - diff --git a/src/mlpack/methods/ann/visitor/copy_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/copy_visitor_impl.hpp deleted file mode 100644 index d143e18799..0000000000 --- a/src/mlpack/methods/ann/visitor/copy_visitor_impl.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/** - * @file methods/ann/visitor/copy_visitor_impl.hpp - * @author Shangtong Zhang - * - * This file provides an implementation for copy between layers - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_COPY_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_COPY_VISITOR_IMPL_HPP - -#include -#include - -namespace mlpack { -namespace ann { - -template -template -inline LayerTypes -CopyVisitor::operator()(LayerType* layer) const -{ - return new LayerType(*layer); -} - -template -inline LayerTypes -CopyVisitor::operator()(MoreTypes layer) const -{ - return layer.apply_visitor(*this); -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/delete_visitor.hpp b/src/mlpack/methods/ann/visitor/delete_visitor.hpp deleted file mode 100644 index d65f4e3e4d..0000000000 --- a/src/mlpack/methods/ann/visitor/delete_visitor.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/** - * @file methods/ann/visitor/delete_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the Delete() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_DELETE_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_DELETE_VISITOR_HPP - -#include -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * DeleteVisitor executes the destructor of the instantiated object. - */ -class DeleteVisitor : public boost::static_visitor -{ - public: - //! Execute the destructor if the layer does not hold layers internally. - template - typename std::enable_if< - !HasModelCheck::value, void>::type - operator()(LayerType* layer) const; - - //! Execute the destructor if the layer does hold layers internally. - template - typename std::enable_if< - HasModelCheck::value, void>::type - operator()(LayerType* layer) const; - - void operator()(MoreTypes layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "delete_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/delete_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/delete_visitor_impl.hpp deleted file mode 100644 index f9f43936e3..0000000000 --- a/src/mlpack/methods/ann/visitor/delete_visitor_impl.hpp +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @file methods/ann/visitor/delete_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the Delete() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_DELETE_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_DELETE_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "delete_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! DeleteVisitor visitor class. -template -inline typename std::enable_if< - !HasModelCheck::value, void>::type -DeleteVisitor::operator()(LayerType* layer) const -{ - if (layer) - delete layer; -} - -template -inline typename std::enable_if< - HasModelCheck::value, void>::type -DeleteVisitor::operator()(LayerType* layer) const -{ - if (layer) - { - for (size_t i = 0; i < layer->Model().size(); ++i) - boost::apply_visitor(DeleteVisitor(), layer->Model()[i]); - - delete layer; - } -} - -inline void DeleteVisitor::operator()(MoreTypes layer) const -{ - layer.apply_visitor(*this); -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/delta_visitor.hpp b/src/mlpack/methods/ann/visitor/delta_visitor.hpp deleted file mode 100644 index 12ecfd2017..0000000000 --- a/src/mlpack/methods/ann/visitor/delta_visitor.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/** - * @file methods/ann/visitor/delta_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the Delta() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_DELTA_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_DELTA_VISITOR_HPP - -#include -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * DeltaVisitor exposes the delta parameter of the given module. - */ -class DeltaVisitor : public boost::static_visitor -{ - public: - //! Return the delta parameter. - template - arma::mat& operator()(LayerType* layer) const; - - arma::mat& operator()(MoreTypes layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "delta_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/delta_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/delta_visitor_impl.hpp deleted file mode 100644 index 3a8e2b6b92..0000000000 --- a/src/mlpack/methods/ann/visitor/delta_visitor_impl.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file methods/ann/visitor/delta_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the Delta() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_DELTA_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_DELTA_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "delta_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! DeltaVisitor visitor class. -template -inline arma::mat& DeltaVisitor::operator()(LayerType *layer) const -{ - return layer->Delta(); -} - -inline arma::mat& DeltaVisitor::operator()(MoreTypes layer) const -{ - return layer.apply_visitor(*this); -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/deterministic_set_visitor.hpp b/src/mlpack/methods/ann/visitor/deterministic_set_visitor.hpp deleted file mode 100644 index f70d740e80..0000000000 --- a/src/mlpack/methods/ann/visitor/deterministic_set_visitor.hpp +++ /dev/null @@ -1,83 +0,0 @@ -/** - * @file methods/ann/visitor/deterministic_set_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the Deterministic() function for - * different layers and automatically directs any parameter to the right layer - * type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_DETERMINISTIC_SET_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_DETERMINISTIC_SET_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * DeterministicSetVisitor set the deterministic parameter given the - * deterministic value. - */ -class DeterministicSetVisitor : public boost::static_visitor -{ - public: - //! Set the deterministic parameter given the current deterministic value. - DeterministicSetVisitor(const bool deterministic = true); - - //! Set the deterministic parameter. - template - void operator()(LayerType* layer) const; - - void operator()(MoreTypes layer) const; - - private: - //! The deterministic parameter. - const bool deterministic; - - //! Set the deterministic parameter if the module implements the - //! Deterministic() and Model() function. - template - typename std::enable_if< - HasDeterministicCheck::value && - HasModelCheck::value, void>::type - LayerDeterministic(T* layer) const; - - //! Set the deterministic parameter if the module implements the - //! Model() function. - template - typename std::enable_if< - !HasDeterministicCheck::value && - HasModelCheck::value, void>::type - LayerDeterministic(T* layer) const; - - //! Set the deterministic parameter if the module implements the - //! Deterministic() function. - template - typename std::enable_if< - HasDeterministicCheck::value && - !HasModelCheck::value, void>::type - LayerDeterministic(T* layer) const; - - //! Do not set the deterministic parameter if the module doesn't implement the - //! Deterministic() or Model() function. - template - typename std::enable_if< - !HasDeterministicCheck::value && - !HasModelCheck::value, void>::type - LayerDeterministic(T* layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "deterministic_set_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/deterministic_set_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/deterministic_set_visitor_impl.hpp deleted file mode 100644 index 06d8bafb03..0000000000 --- a/src/mlpack/methods/ann/visitor/deterministic_set_visitor_impl.hpp +++ /dev/null @@ -1,88 +0,0 @@ -/** - * @file methods/ann/visitor/deterministic_set_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the Deterministic() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_DETERMINISTIC_SET_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_DETERMINISTIC_SET_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "deterministic_set_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! DeterministicSetVisitor visitor class. -inline DeterministicSetVisitor::DeterministicSetVisitor( - const bool deterministic) : deterministic(deterministic) -{ - /* Nothing to do here. */ -} - -template -inline void DeterministicSetVisitor::operator()(LayerType* layer) const -{ - LayerDeterministic(layer); -} - -inline void DeterministicSetVisitor::operator()(MoreTypes layer) const -{ - layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - HasDeterministicCheck::value && - HasModelCheck::value, void>::type -DeterministicSetVisitor::LayerDeterministic(T* layer) const -{ - layer->Deterministic() = deterministic; - - for (size_t i = 0; i < layer->Model().size(); ++i) - { - boost::apply_visitor(DeterministicSetVisitor(deterministic), - layer->Model()[i]); - } -} - -template -inline typename std::enable_if< - !HasDeterministicCheck::value && - HasModelCheck::value, void>::type -DeterministicSetVisitor::LayerDeterministic(T* layer) const -{ - for (size_t i = 0; i < layer->Model().size(); ++i) - { - boost::apply_visitor(DeterministicSetVisitor(deterministic), - layer->Model()[i]); - } -} - -template -inline typename std::enable_if< - HasDeterministicCheck::value && - !HasModelCheck::value, void>::type -DeterministicSetVisitor::LayerDeterministic(T* layer) const -{ - layer->Deterministic() = deterministic; -} - -template -inline typename std::enable_if< - !HasDeterministicCheck::value && - !HasModelCheck::value, void>::type -DeterministicSetVisitor::LayerDeterministic(T* /* input */) const -{ - /* Nothing to do here. */ -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/forward_visitor.hpp b/src/mlpack/methods/ann/visitor/forward_visitor.hpp deleted file mode 100644 index ac825f11ee..0000000000 --- a/src/mlpack/methods/ann/visitor/forward_visitor.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @file methods/ann/visitor/forward_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the Forward() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_FORWARD_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_FORWARD_VISITOR_HPP - -#include -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * ForwardVisitor executes the Forward() function given the input and output - * parameter. - */ -class ForwardVisitor : public boost::static_visitor -{ - public: - //! Execute the Forward() function given the input and output parameter. - ForwardVisitor(const arma::mat& input, arma::mat& output); - - //! Execute the Forward() function. - template - void operator()(LayerType* layer) const; - - void operator()(MoreTypes layer) const; - - private: - //! The input parameter set. - const arma::mat& input; - - //! The output parameter set. - arma::mat& output; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "forward_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/forward_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/forward_visitor_impl.hpp deleted file mode 100644 index 248d852c53..0000000000 --- a/src/mlpack/methods/ann/visitor/forward_visitor_impl.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/** - * @file methods/ann/visitor/forward_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the Forward() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_FORWARD_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_FORWARD_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "forward_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! ForwardVisitor visitor class. -inline ForwardVisitor::ForwardVisitor(const arma::mat& input, arma::mat& output) : - input(input), - output(output) -{ - /* Nothing to do here. */ -} - -template -inline void ForwardVisitor::operator()(LayerType* layer) const -{ - layer->Forward(input, output); -} - -inline void ForwardVisitor::operator()(MoreTypes layer) const -{ - layer.apply_visitor(*this); -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/gradient_set_visitor.hpp b/src/mlpack/methods/ann/visitor/gradient_set_visitor.hpp deleted file mode 100644 index 4c492b3f0e..0000000000 --- a/src/mlpack/methods/ann/visitor/gradient_set_visitor.hpp +++ /dev/null @@ -1,82 +0,0 @@ -/** - * @file methods/ann/visitor/gradient_set_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the Gradient() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_GRADIENT_SET_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_GRADIENT_SET_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * GradientSetVisitor update the gradient parameter given the gradient set. - */ -class GradientSetVisitor : public boost::static_visitor -{ - public: - //! Update the gradient parameter given the gradient set. - GradientSetVisitor(arma::mat& gradient, size_t offset = 0); - - //! Update the gradient parameter. - template - size_t operator()(LayerType* layer) const; - - size_t operator()(MoreTypes layer) const; - - private: - //! The gradient set. - arma::mat& gradient; - - //! The gradient offset. - size_t offset; - - //! Update the gradient if the module implements the Gradient() function. - template - typename std::enable_if< - HasGradientCheck::value && - !HasModelCheck::value, size_t>::type - LayerGradients(T* layer, arma::mat& input) const; - - //! Update the gradient if the module implements the Model() function. - template - typename std::enable_if< - !HasGradientCheck::value && - HasModelCheck::value, size_t>::type - LayerGradients(T* layer, arma::mat& input) const; - - //! Update the gradient if the module implements the Gradient() and Model() - //! function. - template - typename std::enable_if< - HasGradientCheck::value && - HasModelCheck::value, size_t>::type - LayerGradients(T* layer, arma::mat& input) const; - - //! Do not update the gradient parameter if the module doesn't implement the - //! Gradient() or Model() function. - template - typename std::enable_if< - !HasGradientCheck::value && - !HasModelCheck::value, size_t>::type - LayerGradients(T* layer, P& input) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "gradient_set_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/gradient_set_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/gradient_set_visitor_impl.hpp deleted file mode 100644 index 85e148da25..0000000000 --- a/src/mlpack/methods/ann/visitor/gradient_set_visitor_impl.hpp +++ /dev/null @@ -1,100 +0,0 @@ -/** - * @file methods/ann/visitor/gradient_set_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the Gradient() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_GRADIENT_SET_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_GRADIENT_SET_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "gradient_set_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! GradientSetVisitor visitor class. -inline GradientSetVisitor::GradientSetVisitor(arma::mat& gradient, - size_t offset) : - gradient(gradient), - offset(offset) -{ - /* Nothing to do here. */ -} - -template -inline size_t GradientSetVisitor::operator()(LayerType* layer) const -{ - return LayerGradients(layer, layer->OutputParameter()); -} - -inline size_t GradientSetVisitor::operator()(MoreTypes layer) const -{ - return layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - HasGradientCheck::value && - !HasModelCheck::value, size_t>::type -GradientSetVisitor::LayerGradients(T* layer, arma::mat& /* input */) const -{ - layer->Gradient() = arma::mat(gradient.memptr() + offset, - layer->Parameters().n_rows, layer->Parameters().n_cols, false, false); - - return layer->Parameters().n_elem; -} - -template -inline typename std::enable_if< - !HasGradientCheck::value && - HasModelCheck::value, size_t>::type -GradientSetVisitor::LayerGradients(T* layer, arma::mat& /* input */) const -{ - size_t modelOffset = 0; - for (size_t i = 0; i < layer->Model().size(); ++i) - { - modelOffset += boost::apply_visitor(GradientSetVisitor( - gradient, modelOffset + offset), layer->Model()[i]); - } - - return modelOffset; -} - -template -inline typename std::enable_if< - HasGradientCheck::value && - HasModelCheck::value, size_t>::type -GradientSetVisitor::LayerGradients(T* layer, arma::mat& /* input */) const -{ - layer->Gradient() = arma::mat(gradient.memptr() + offset, - layer->Parameters().n_rows, layer->Parameters().n_cols, false, false); - - size_t modelOffset = layer->Parameters().n_elem; - for (size_t i = 0; i < layer->Model().size(); ++i) - { - modelOffset += boost::apply_visitor(GradientSetVisitor( - gradient, modelOffset + offset), layer->Model()[i]); - } - - return modelOffset; -} - -template -inline typename std::enable_if< - !HasGradientCheck::value && - !HasModelCheck::value, size_t>::type -GradientSetVisitor::LayerGradients(T* /* layer */, P& /* input */) const -{ - return 0; -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/gradient_update_visitor.hpp b/src/mlpack/methods/ann/visitor/gradient_update_visitor.hpp deleted file mode 100644 index feedf0d299..0000000000 --- a/src/mlpack/methods/ann/visitor/gradient_update_visitor.hpp +++ /dev/null @@ -1,82 +0,0 @@ -/** - * @file methods/ann/visitor/gradient_update_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the Gradient() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_GRADIENT_UPDATE_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_GRADIENT_UPDATE_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * GradientUpdateVisitor update the gradient parameter given the gradient set. - */ -class GradientUpdateVisitor : public boost::static_visitor -{ - public: - //! Update the gradient parameter given the gradient set. - GradientUpdateVisitor(arma::mat& gradient, size_t offset = 0); - - //! Update the gradient parameter. - template - size_t operator()(LayerType* layer) const; - - size_t operator()(MoreTypes layer) const; - - private: - //! The gradient set. - arma::mat& gradient; - - //! The gradient offset. - size_t offset; - - //! Update the gradient if the module implements the Gradient() function. - template - typename std::enable_if< - HasGradientCheck::value && - !HasModelCheck::value, size_t>::type - LayerGradients(T* layer, arma::mat& input) const; - - //! Update the gradient if the module implements the Model() function. - template - typename std::enable_if< - !HasGradientCheck::value && - HasModelCheck::value, size_t>::type - LayerGradients(T* layer, arma::mat& input) const; - - //! Update the gradient if the module implements the Gradient() and Model() - //! function. - template - typename std::enable_if< - HasGradientCheck::value && - HasModelCheck::value, size_t>::type - LayerGradients(T* layer, arma::mat& input) const; - - //! Do not update the gradient parameter if the module doesn't implement the - //! Gradient() or Model() function. - template - typename std::enable_if< - !HasGradientCheck::value && - !HasModelCheck::value, size_t>::type - LayerGradients(T* layer, P& input) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "gradient_update_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/gradient_update_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/gradient_update_visitor_impl.hpp deleted file mode 100644 index f233eaf65d..0000000000 --- a/src/mlpack/methods/ann/visitor/gradient_update_visitor_impl.hpp +++ /dev/null @@ -1,106 +0,0 @@ -/** - * @file methods/ann/visitor/gradient_update_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the Gradient() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_GRADIENT_UPDATE_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_GRADIENT_UPDATE_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "gradient_update_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! GradientUpdateVisitor visitor class. -inline GradientUpdateVisitor::GradientUpdateVisitor(arma::mat& gradient, - size_t offset) : - gradient(gradient), - offset(offset) -{ - /* Nothing to do here. */ -} - -template -inline size_t GradientUpdateVisitor::operator()(LayerType* layer) const -{ - return LayerGradients(layer, layer->OutputParameter()); -} - -inline size_t GradientUpdateVisitor::operator()(MoreTypes layer) const -{ - return layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - HasGradientCheck::value && - !HasModelCheck::value, size_t>::type -GradientUpdateVisitor::LayerGradients(T* layer, arma::mat& /* input */) const -{ - if (layer->Parameters().n_elem != 0) - { - layer->Gradient() = gradient.submat(offset, 0, - offset + layer->Parameters().n_elem - 1, 0);; - } - - return layer->Parameters().n_elem; -} - -template -inline typename std::enable_if< - !HasGradientCheck::value && - HasModelCheck::value, size_t>::type -GradientUpdateVisitor::LayerGradients(T* layer, arma::mat& /* input */) const -{ - size_t modelOffset = 0; - for (size_t i = 0; i < layer->Model().size(); ++i) - { - modelOffset += boost::apply_visitor(GradientUpdateVisitor( - gradient, modelOffset + offset), layer->Model()[i]); - } - - return modelOffset; -} - -template -inline typename std::enable_if< - HasGradientCheck::value && - HasModelCheck::value, size_t>::type -GradientUpdateVisitor::LayerGradients(T* layer, arma::mat& /* input */) const -{ - if (layer->Parameters().n_elem != 0) - { - layer->Gradient() = gradient.submat(offset, 0, - offset + layer->Parameters().n_elem - 1, 0);; - } - - size_t modelOffset = layer->Parameters().n_elem; - for (size_t i = 0; i < layer->Model().size(); ++i) - { - modelOffset += boost::apply_visitor(GradientUpdateVisitor( - gradient, modelOffset + offset), layer->Model()[i]); - } - - return modelOffset; -} - -template -inline typename std::enable_if< - !HasGradientCheck::value && - !HasModelCheck::value, size_t>::type -GradientUpdateVisitor::LayerGradients(T* /* layer */, P& /* input */) const -{ - return 0; -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/gradient_visitor.hpp b/src/mlpack/methods/ann/visitor/gradient_visitor.hpp deleted file mode 100644 index fc04c96161..0000000000 --- a/src/mlpack/methods/ann/visitor/gradient_visitor.hpp +++ /dev/null @@ -1,89 +0,0 @@ -/** - * @file methods/ann/visitor/gradient_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the Gradient() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_GRADIENT_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_GRADIENT_VISITOR_HPP - -#include -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * SearchModeVisitor executes the Gradient() method of the given module using - * the input and delta parameter. - */ -class GradientVisitor : public boost::static_visitor -{ - public: - //! Executes the Gradient() method of the given module using the input and - //! delta parameter. - GradientVisitor(const arma::mat& input, const arma::mat& delta); - - //! Executes the Gradient() method for the layer with the specified index. - GradientVisitor(const arma::mat& input, - const arma::mat& delta, - const size_t index); - - //! Executes the Gradient() method. - template - void operator()(LayerType* layer) const; - - void operator()(MoreTypes layer) const; - - private: - //! The input set. - const arma::mat& input; - - //! The delta parameter. - const arma::mat& delta; - - //! Index of the layer to run. - size_t index; - - //! Indicates whether to use index or not - bool hasIndex; - - //! Execute the Gradient() function if the module implements the Gradient() - //! function. - template - typename std::enable_if< - HasGradientCheck::value && - !HasRunCheck::value, void>::type - LayerGradients(T* layer, arma::mat& input) const; - - //! Execute the Gradient() function if the module implements the Gradient() - //! and has a Run() function. - template - typename std::enable_if< - HasGradientCheck::value && - HasRunCheck::value, void>::type - LayerGradients(T* layer, arma::mat& input) const; - - //! Do not execute the Gradient() function if the module doesn't implement - //! the Gradient() function. - template - typename std::enable_if< - !HasGradientCheck::value, void>::type - LayerGradients(T* layer, P& input) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "gradient_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/gradient_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/gradient_visitor_impl.hpp deleted file mode 100644 index 3537aa9959..0000000000 --- a/src/mlpack/methods/ann/visitor/gradient_visitor_impl.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/** - * @file methods/ann/visitor/gradient_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the Gradient() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_GRADIENT_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_GRADIENT_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "gradient_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! GradientVisitor visitor class. -inline GradientVisitor::GradientVisitor(const arma::mat& input, - const arma::mat& delta) : - input(input), - delta(delta), - index(0), - hasIndex(false) -{ - /* Nothing to do here. */ -} - -inline GradientVisitor::GradientVisitor(const arma::mat& input, - const arma::mat& delta, - const size_t index) : - input(input), - delta(delta), - index(index), - hasIndex(true) -{ - /* Nothing to do here. */ -} - -template -inline void GradientVisitor::operator()(LayerType* layer) const -{ - LayerGradients(layer, layer->OutputParameter()); -} - -inline void GradientVisitor::operator()(MoreTypes layer) const -{ - layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - HasGradientCheck::value && - !HasRunCheck::value, void>::type -GradientVisitor::LayerGradients(T* layer, arma::mat& /* input */) const -{ - layer->Gradient(input, delta, layer->Gradient()); -} - -template -inline typename std::enable_if< - HasGradientCheck::value && - HasRunCheck::value, void>::type -GradientVisitor::LayerGradients(T* layer, arma::mat& /* input */) const -{ - if (!hasIndex) - { - layer->Gradient(input, delta, layer->Gradient()); - } - else - { - layer->Gradient(input, delta, layer->Gradient(), index); - } -} - -template -inline typename std::enable_if< - !HasGradientCheck::value, void>::type -GradientVisitor::LayerGradients(T* /* layer */, P& /* input */) const -{ - /* Nothing to do here. */ -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/gradient_zero_visitor.hpp b/src/mlpack/methods/ann/visitor/gradient_zero_visitor.hpp deleted file mode 100644 index 3480796089..0000000000 --- a/src/mlpack/methods/ann/visitor/gradient_zero_visitor.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file methods/ann/visitor/gradient_zero_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the Gradient() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_GRADIENT_ZERO_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_GRADIENT_ZERO_VISITOR_HPP - -#include -#include - -#include - -namespace mlpack { -namespace ann { - -/* - * GradientZeroVisitor set the gradient to zero for the given module. - */ -class GradientZeroVisitor : public boost::static_visitor -{ - public: - //! Set the gradient to zero for the given module. - GradientZeroVisitor(); - - //! Set the gradient to zero. - template - void operator()(LayerType* layer) const; - - void operator()(MoreTypes layer) const; - - private: - //! Set the gradient to zero if the module implements the Gradient() function. - template - typename std::enable_if< - HasGradientCheck::value, void>::type - LayerGradients(T* layer, arma::mat& input) const; - - //! Do not set the gradient to zero if the module doesn't implement the - //! Gradient() function. - template - typename std::enable_if< - !HasGradientCheck::value, void>::type - LayerGradients(T* layer, P& input) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "gradient_zero_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/gradient_zero_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/gradient_zero_visitor_impl.hpp deleted file mode 100644 index de39a692a6..0000000000 --- a/src/mlpack/methods/ann/visitor/gradient_zero_visitor_impl.hpp +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @file methods/ann/visitor/gradient_zero_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the Gradient() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_GRADIENT_ZERO_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_GRADIENT_ZERO_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "gradient_zero_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! GradientZeroVisitor visitor class. -inline GradientZeroVisitor::GradientZeroVisitor() -{ - /* Nothing to do here. */ -} - -template -inline void GradientZeroVisitor::operator()(LayerType* layer) const -{ - LayerGradients(layer, layer->OutputParameter()); -} - -inline void GradientZeroVisitor::operator()(MoreTypes layer) const -{ - layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - HasGradientCheck::value, void>::type -GradientZeroVisitor::LayerGradients(T* layer, arma::mat& /* input */) const -{ - layer->Gradient().zeros(); -} - -template -inline typename std::enable_if< - !HasGradientCheck::value, void>::type -GradientZeroVisitor::LayerGradients(T* /* layer */, P& /* input */) const -{ - /* Nothing to do here. */ -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp b/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp deleted file mode 100644 index c27135aae3..0000000000 --- a/src/mlpack/methods/ann/visitor/input_shape_visitor.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @file methods/ann/visitor/input_shape_visitor.hpp - * @author Khizir Siddiqui - * @author Nippun Sharma - * - * This file provides an abstraction for the InputShape() function for - * different layers and automatically directs any parameter to the right layer - * type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_INPUT_SHAPE_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_INPUT_SHAPE_VISITOR_HPP - -#include -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * InShapeVisitor returns the input shape a Layer expects. - */ -class InShapeVisitor : public boost::static_visitor -{ - public: - //! Return the input shape of layer. - template - size_t operator()(LayerType* layer) const; - - size_t operator()(MoreTypes layer) const; - - private: - //! If the module doesn't implement the InputShape() function return 0. - template - typename std::enable_if< - !HasInputShapeCheck::value, size_t>::type - LayerInputShape(T* layer) const; - - //! If the module implements the InputShape() function returns the input shape. - template - typename std::enable_if< - HasInputShapeCheck::value, size_t>::type - LayerInputShape(T* layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "input_shape_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp deleted file mode 100644 index bda5f7b604..0000000000 --- a/src/mlpack/methods/ann/visitor/input_shape_visitor_impl.hpp +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @file methods/ann/visitor/input_shape_visitor_impl.hpp - * @author Khizir Siddiqui - * @author Nippun Sharma - * - * Implementation of the InputShape() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_INPUT_SHAPE_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_INPUT_SHAPE_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "input_shape_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! InShapeVisitor visitor class. -template -inline std::size_t InShapeVisitor::operator()(LayerType* layer) const -{ - return LayerInputShape(layer); -} - -inline std::size_t InShapeVisitor::operator()(MoreTypes layer) const -{ - return layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - !HasInputShapeCheck::value, std::size_t>::type -InShapeVisitor::LayerInputShape(T* /* layer */) const -{ - return 0; -} - -template -inline typename std::enable_if< - HasInputShapeCheck::value, std::size_t>::type -InShapeVisitor::LayerInputShape(T* layer) const -{ - return layer->InputShape(); -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/load_output_parameter_visitor.hpp b/src/mlpack/methods/ann/visitor/load_output_parameter_visitor.hpp deleted file mode 100644 index 2546d52f90..0000000000 --- a/src/mlpack/methods/ann/visitor/load_output_parameter_visitor.hpp +++ /dev/null @@ -1,65 +0,0 @@ -/** - * @file methods/ann/visitor/load_output_parameter_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the OutputParameter() function for - * different layers and automatically directs any parameter to the right layer - * type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_LOAD_OUTPUT_PARAMETER_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_LOAD_OUTPUT_PARAMETER_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * LoadOutputParameterVisitor restores the output parameter using the given - * parameter set. - */ -class LoadOutputParameterVisitor : public boost::static_visitor -{ - public: - //! Restore the output parameter given a parameter set. - LoadOutputParameterVisitor(std::vector& parameter); - - //! Restore the output parameter. - template - void operator()(LayerType* layer) const; - - void operator()(MoreTypes layer) const; - - private: - //! The parameter set. - std::vector& parameter; - - //! Restore the output parameter for a module which doesn't implement the - //! Model() function. - template - typename std::enable_if< - !HasModelCheck::value, void>::type - OutputParameter(T* layer) const; - - //! Restore the output parameter for a module which implements the Model() - //! function. - template - typename std::enable_if< - HasModelCheck::value, void>::type - OutputParameter(T* layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "load_output_parameter_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/load_output_parameter_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/load_output_parameter_visitor_impl.hpp deleted file mode 100644 index 5c384643ee..0000000000 --- a/src/mlpack/methods/ann/visitor/load_output_parameter_visitor_impl.hpp +++ /dev/null @@ -1,66 +0,0 @@ -/** - * @file methods/ann/visitor/load_output_parameter_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the OutputParameter() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_LOAD_OUTPUT_PARAMETER_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_LOAD_OUTPUT_PARAMETER_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "load_output_parameter_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! LoadOutputParameterVisitor visitor class. -inline LoadOutputParameterVisitor::LoadOutputParameterVisitor( - std::vector& parameter) : parameter(parameter) -{ - /* Nothing to do here. */ -} - -template -inline void LoadOutputParameterVisitor::operator()(LayerType* layer) const -{ - OutputParameter(layer); -} - -inline void LoadOutputParameterVisitor::operator()(MoreTypes layer) const -{ - layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - !HasModelCheck::value, void>::type -LoadOutputParameterVisitor::OutputParameter(T* layer) const -{ - layer->OutputParameter() = parameter.back(); - parameter.pop_back(); -} - -template -inline typename std::enable_if< - HasModelCheck::value, void>::type -LoadOutputParameterVisitor::OutputParameter(T* layer) const -{ - for (size_t i = 0; i < layer->Model().size(); ++i) - { - boost::apply_visitor(LoadOutputParameterVisitor(parameter), - layer->Model()[layer->Model().size() - i - 1]); - } - - layer->OutputParameter() = parameter.back(); - parameter.pop_back(); -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/loss_visitor.hpp b/src/mlpack/methods/ann/visitor/loss_visitor.hpp deleted file mode 100644 index d9ca99763f..0000000000 --- a/src/mlpack/methods/ann/visitor/loss_visitor.hpp +++ /dev/null @@ -1,71 +0,0 @@ -/** - * @file methods/ann/visitor/loss_visitor.hpp - * @author Atharva Khandait - * - * This file provides an abstraction for the Loss() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_LOSS_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_LOSS_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * LossVisitor exposes the Loss() method of the given module. - */ -class LossVisitor : public boost::static_visitor -{ - public: - //! Return the Loss. - template - double operator()(LayerType* layer) const; - - double operator()(MoreTypes layer) const; - - private: - //! Return 0 if the module doesn't implement the Loss() or Model() function. - template - typename std::enable_if< - !HasLoss::value && - !HasModelCheck::value, double>::type - LayerLoss(T* layer) const; - - //! Return the output height if the module implements the Loss() function. - template - typename std::enable_if< - HasLoss::value && - !HasModelCheck::value, double>::type - LayerLoss(T* layer) const; - - //! Return the loss if the module implements the Model() function. - template - typename std::enable_if< - !HasLoss::value && - HasModelCheck::value, double>::type - LayerLoss(T* layer) const; - - //! Return the loss if the module implements the Model() or loss() function. - template - typename std::enable_if< - HasLoss::value && - HasModelCheck::value, double>::type - LayerLoss(T* layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "loss_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/loss_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/loss_visitor_impl.hpp deleted file mode 100644 index ee8d6cb402..0000000000 --- a/src/mlpack/methods/ann/visitor/loss_visitor_impl.hpp +++ /dev/null @@ -1,99 +0,0 @@ -/** - * @file methods/ann/visitor/loss_visitor_impl.hpp - * @author Atharva Khandait - * - * Implementation of the Loss() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_LOSS_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_LOSS_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "loss_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! LossVisitor visitor class. -template -inline double LossVisitor::operator()(LayerType* layer) const -{ - return LayerLoss(layer); -} - -inline double LossVisitor::operator()(MoreTypes layer) const -{ - return layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - !HasLoss::value && - !HasModelCheck::value, double>::type -LossVisitor::LayerLoss(T* /* layer */) const -{ - return 0; -} - -template -inline typename std::enable_if< - HasLoss::value && - !HasModelCheck::value, double>::type -LossVisitor::LayerLoss(T* layer) const -{ - return layer->Loss(); -} - -template -inline typename std::enable_if< - !HasLoss::value && - HasModelCheck::value, double>::type -LossVisitor::LayerLoss(T* layer) const -{ - for (size_t i = 0; i < layer->Model().size(); ++i) - { - double loss = boost::apply_visitor(LossVisitor(), - layer->Model()[layer->Model().size() - 1 - i]); - - if (loss != 0) - { - return loss; - } - } - - return 0; -} - -template -inline typename std::enable_if< - HasLoss::value && - HasModelCheck::value, double>::type -LossVisitor::LayerLoss(T* layer) const -{ - double loss = layer->Loss(); - - if (loss == 0) - { - for (size_t i = 0; i < layer->Model().size(); ++i) - { - loss = boost::apply_visitor(LossVisitor(), - layer->Model()[layer->Model().size() - 1 - i]); - - if (loss != 0) - { - return loss; - } - } - } - - return loss; -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/output_height_visitor.hpp b/src/mlpack/methods/ann/visitor/output_height_visitor.hpp deleted file mode 100644 index f14350b9ef..0000000000 --- a/src/mlpack/methods/ann/visitor/output_height_visitor.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @file methods/ann/visitor/output_height_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the OutputHeight() function for - * different layers and automatically directs any parameter to the right layer - * type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_OUTPUT_HEIGHT_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_OUTPUT_HEIGHT_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * OutputHeightVisitor exposes the OutputHeight() method of the given module. - */ -class OutputHeightVisitor : public boost::static_visitor -{ - public: - //! Return the output height. - template - size_t operator()(LayerType* layer) const; - - size_t operator()(MoreTypes layer) const; - - private: - //! Return 0 if the module doesn't implement the InputHeight() or Model() - //! function. - template - typename std::enable_if< - !HasInputHeight::value && - !HasModelCheck::value, size_t>::type - LayerOutputHeight(T* layer) const; - - //! Return the output height if the module implements the InputHeight() - //! function. - template - typename std::enable_if< - HasInputHeight::value && - !HasModelCheck::value, size_t>::type - LayerOutputHeight(T* layer) const; - - //! Return the output height if the module implements the Model() function. - template - typename std::enable_if< - !HasInputHeight::value && - HasModelCheck::value, size_t>::type - LayerOutputHeight(T* layer) const; - - //! Return the output height if the module implements the Model() or - //! InputHeight() function. - template - typename std::enable_if< - HasInputHeight::value && - HasModelCheck::value, size_t>::type - LayerOutputHeight(T* layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "output_height_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/output_height_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/output_height_visitor_impl.hpp deleted file mode 100644 index ae219da220..0000000000 --- a/src/mlpack/methods/ann/visitor/output_height_visitor_impl.hpp +++ /dev/null @@ -1,99 +0,0 @@ -/** - * @file methods/ann/visitor/output_height_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the OutputHeight() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_OUTPUT_HEIGHT_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_OUTPUT_HEIGHT_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "output_height_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! OutputHeightVisitor visitor class. -template -inline size_t OutputHeightVisitor::operator()(LayerType* layer) const -{ - return LayerOutputHeight(layer); -} - -inline size_t OutputHeightVisitor::operator()(MoreTypes layer) const -{ - return layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - !HasInputHeight::value && - !HasModelCheck::value, size_t>::type -OutputHeightVisitor::LayerOutputHeight(T* /* layer */) const -{ - return 0; -} - -template -inline typename std::enable_if< - HasInputHeight::value && - !HasModelCheck::value, size_t>::type -OutputHeightVisitor::LayerOutputHeight(T* layer) const -{ - return layer->OutputHeight(); -} - -template -inline typename std::enable_if< - !HasInputHeight::value && - HasModelCheck::value, size_t>::type -OutputHeightVisitor::LayerOutputHeight(T* layer) const -{ - for (size_t i = 0; i < layer->Model().size(); ++i) - { - size_t outputHeight = boost::apply_visitor(OutputHeightVisitor(), - layer->Model()[layer->Model().size() - 1 - i]); - - if (outputHeight != 0) - { - return outputHeight; - } - } - - return 0; -} - -template -inline typename std::enable_if< - HasInputHeight::value && - HasModelCheck::value, size_t>::type -OutputHeightVisitor::LayerOutputHeight(T* layer) const -{ - size_t outputHeight = layer->OutputHeight(); - - if (outputHeight == 0) - { - for (size_t i = 0; i < layer->Model().size(); ++i) - { - outputHeight = boost::apply_visitor(OutputHeightVisitor(), - layer->Model()[layer->Model().size() - 1 - i]); - - if (outputHeight != 0) - { - return outputHeight; - } - } - } - - return outputHeight; -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/output_parameter_visitor.hpp b/src/mlpack/methods/ann/visitor/output_parameter_visitor.hpp deleted file mode 100644 index 6a12226464..0000000000 --- a/src/mlpack/methods/ann/visitor/output_parameter_visitor.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/** - * @file methods/ann/visitor/output_parameter_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the OutputParameter() function for - * different layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_OUTPUT_PARAMETER_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_OUTPUT_PARAMETER_VISITOR_HPP - -#include -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * OutputParameterVisitor exposes the output parameter of the given module. - */ -class OutputParameterVisitor : public boost::static_visitor -{ - public: - //! Return the output parameter set. - template - arma::mat& operator()(LayerType* layer) const; - - arma::mat& operator()(MoreTypes layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "output_parameter_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/output_parameter_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/output_parameter_visitor_impl.hpp deleted file mode 100644 index 5086669548..0000000000 --- a/src/mlpack/methods/ann/visitor/output_parameter_visitor_impl.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file methods/ann/visitor/output_parameter_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the OutputParameter() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_OUTPUT_PARAMETER_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_OUTPUT_PARAMETER_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "output_parameter_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! OutputParameterVisitor visitor class. -template -inline arma::mat& OutputParameterVisitor::operator()(LayerType *layer) const -{ - return layer->OutputParameter(); -} - -inline arma::mat& OutputParameterVisitor::operator()(MoreTypes layer) const -{ - return layer.apply_visitor(*this); -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/output_width_visitor.hpp b/src/mlpack/methods/ann/visitor/output_width_visitor.hpp deleted file mode 100644 index d6a0fa83ed..0000000000 --- a/src/mlpack/methods/ann/visitor/output_width_visitor.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @file methods/ann/visitor/output_width_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the OutputWidth() function for - * different layers and automatically directs any parameter to the right layer - * type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_OUTPUT_WIDTH_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_OUTPUT_WIDTH_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * OutputWidthVisitor exposes the OutputWidth() method of the given module. - */ -class OutputWidthVisitor : public boost::static_visitor -{ - public: - //! Return the output width. - template - size_t operator()(LayerType* layer) const; - - size_t operator()(MoreTypes layer) const; - - private: - //! Return 0 if the module doesn't implement the InputWidth() or Model() - //! function. - template - typename std::enable_if< - !HasInputWidth::value && - !HasModelCheck::value, size_t>::type - LayerOutputWidth(T* layer) const; - - //! Return the output width if the module implements the InputWidth() - //! function. - template - typename std::enable_if< - HasInputWidth::value && - !HasModelCheck::value, size_t>::type - LayerOutputWidth(T* layer) const; - - //! Return the output width if the module implements the Model() function. - template - typename std::enable_if< - !HasInputWidth::value && - HasModelCheck::value, size_t>::type - LayerOutputWidth(T* layer) const; - - //! Return the output width if the module implements the Model() or - //! InputWidth() function. - template - typename std::enable_if< - HasInputWidth::value && - HasModelCheck::value, size_t>::type - LayerOutputWidth(T* layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "output_width_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/output_width_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/output_width_visitor_impl.hpp deleted file mode 100644 index 3d68087d83..0000000000 --- a/src/mlpack/methods/ann/visitor/output_width_visitor_impl.hpp +++ /dev/null @@ -1,99 +0,0 @@ -/** - * @file methods/ann/visitor/output_width_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the OutputWidth() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_OUTPUT_WIDTH_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_OUTPUT_WIDTH_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "output_width_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! OutputWidthVisitor visitor class. -template -inline size_t OutputWidthVisitor::operator()(LayerType* layer) const -{ - return LayerOutputWidth(layer); -} - -inline size_t OutputWidthVisitor::operator()(MoreTypes layer) const -{ - return layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - !HasInputWidth::value && - !HasModelCheck::value, size_t>::type -OutputWidthVisitor::LayerOutputWidth(T* /* layer */) const -{ - return 0; -} - -template -inline typename std::enable_if< - HasInputWidth::value && - !HasModelCheck::value, size_t>::type -OutputWidthVisitor::LayerOutputWidth(T* layer) const -{ - return layer->OutputWidth(); -} - -template -inline typename std::enable_if< - !HasInputWidth::value && - HasModelCheck::value, size_t>::type -OutputWidthVisitor::LayerOutputWidth(T* layer) const -{ - for (size_t i = 0; i < layer->Model().size(); ++i) - { - size_t outputWidth = boost::apply_visitor(OutputWidthVisitor(), - layer->Model()[layer->Model().size() - 1 - i]); - - if (outputWidth != 0) - { - return outputWidth; - } - } - - return 0; -} - -template -inline typename std::enable_if< - HasInputWidth::value && - HasModelCheck::value, size_t>::type -OutputWidthVisitor::LayerOutputWidth(T* layer) const -{ - size_t outputWidth = layer->OutputWidth(); - - if (outputWidth == 0) - { - for (size_t i = 0; i < layer->Model().size(); ++i) - { - outputWidth = boost::apply_visitor(OutputWidthVisitor(), - layer->Model()[layer->Model().size() - 1 - i]); - - if (outputWidth != 0) - { - return outputWidth; - } - } - } - - return outputWidth; -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/parameters_set_visitor.hpp b/src/mlpack/methods/ann/visitor/parameters_set_visitor.hpp deleted file mode 100644 index c8cba59bb2..0000000000 --- a/src/mlpack/methods/ann/visitor/parameters_set_visitor.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/** - * @file methods/ann/visitor/parameters_set_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the Parameters() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_PARAMETERS_SET_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_PARAMETERS_SET_VISITOR_HPP - -#include -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * ParametersSetVisitor update the parameters set using the given matrix. - */ -class ParametersSetVisitor : public boost::static_visitor -{ - public: - //! Update the parameters set given the parameters matrix. - ParametersSetVisitor(arma::mat& parameters); - - //! Update the parameters set. - template - void operator()(LayerType *layer) const; - - void operator()(MoreTypes layer) const; - - private: - //! The parameters set. - arma::mat& parameters; - - //! Do not update the parameters set if the module doesn't implement the - //! Parameters() function. - template - typename std::enable_if< - !HasParametersCheck::value, void>::type - LayerParameters(T* layer, P& output) const; - - //! Update the parameters set if the module implements the Parameters() - //! function. - template - typename std::enable_if< - HasParametersCheck::value, void>::type - LayerParameters(T* layer, P& output) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "parameters_set_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/parameters_set_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/parameters_set_visitor_impl.hpp deleted file mode 100644 index 820a5ab464..0000000000 --- a/src/mlpack/methods/ann/visitor/parameters_set_visitor_impl.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @file methods/ann/visitor/parameters_set_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the Parameters() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_PARAMETERS_SET_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_PARAMETERS_SET_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "parameters_set_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! ParametersSetVisitor visitor class. -inline ParametersSetVisitor::ParametersSetVisitor(arma::mat& parameters) : - parameters(parameters) -{ - /* Nothing to do here. */ -} - -template -inline void ParametersSetVisitor::operator()(LayerType *layer) const -{ - LayerParameters(layer, layer->OutputParameter()); -} - -inline void ParametersSetVisitor::operator()(MoreTypes layer) const -{ - layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - !HasParametersCheck::value, void>::type -ParametersSetVisitor::LayerParameters(T* /* layer */, P& /* output */) const -{ - /* Nothing to do here. */ -} - -template -inline typename std::enable_if< - HasParametersCheck::value, void>::type -ParametersSetVisitor::LayerParameters(T* layer, P& /* output */) const -{ - layer->Parameters() = parameters; -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/parameters_visitor.hpp b/src/mlpack/methods/ann/visitor/parameters_visitor.hpp deleted file mode 100644 index 36a0b30bf5..0000000000 --- a/src/mlpack/methods/ann/visitor/parameters_visitor.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/** - * @file methods/ann/visitor/parameters_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the Parameters() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_PARAMETERS_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_PARAMETERS_VISITOR_HPP - -#include -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * ParametersVisitor exposes the parameters set of the given module and stores - * the parameters set into the given matrix. - */ -class ParametersVisitor : public boost::static_visitor -{ - public: - //! Store the parameters set into the given parameters matrix. - ParametersVisitor(arma::mat& parameters); - - //! Set the parameters set. - template - void operator()(LayerType* layer) const; - - void operator()(MoreTypes layer) const; - - private: - //! The parameters set. - arma::mat& parameters; - - //! Do not set the parameters set if the module doesn't implement the - //! Parameters() function. - template - typename std::enable_if< - !HasParametersCheck::value, void>::type - LayerParameters(T* layer, P& output) const; - - //! Set the parameters set if the module implements the Parameters() function. - template - typename std::enable_if< - HasParametersCheck::value, void>::type - LayerParameters(T* layer, P& output) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "parameters_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/parameters_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/parameters_visitor_impl.hpp deleted file mode 100644 index c58604c995..0000000000 --- a/src/mlpack/methods/ann/visitor/parameters_visitor_impl.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @file methods/ann/visitor/parameters_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the Parameters() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_PARAMETERS_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_PARAMETERS_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "parameters_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! ParametersVisitor visitor class. -inline ParametersVisitor::ParametersVisitor(arma::mat& parameters) : - parameters(parameters) -{ - /* Nothing to do here. */ -} - -template -inline void ParametersVisitor::operator()(LayerType *layer) const -{ - LayerParameters(layer, layer->OutputParameter()); -} - -inline void ParametersVisitor::operator()(MoreTypes layer) const -{ - layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - !HasParametersCheck::value, void>::type -ParametersVisitor::LayerParameters(T* /* layer */, P& /* output */) const -{ - /* Nothing to do here. */ -} - -template -inline typename std::enable_if< - HasParametersCheck::value, void>::type -ParametersVisitor::LayerParameters(T* layer, P& /* output */) const -{ - parameters = layer->Parameters(); -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/reset_cell_visitor.hpp b/src/mlpack/methods/ann/visitor/reset_cell_visitor.hpp deleted file mode 100644 index ba88ce161b..0000000000 --- a/src/mlpack/methods/ann/visitor/reset_cell_visitor.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/** - * @file methods/ann/visitor/reset_cell_visitor.hpp - * @author Sumedh Ghaisas - * - * Boost static visitor abstraction for calling ResetCell function on RNN cells. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_RESET_CELL_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_RESET_CELL_VISITOR_HPP - -#include -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * ResetCellVisitor executes the ResetCell() function. - */ -class ResetCellVisitor : public boost::static_visitor -{ - public: - //! Reset the cell using the given size. - ResetCellVisitor(const size_t size); - - //! Execute the ResetCell() function. - template - void operator()(LayerType* layer) const; - - void operator()(MoreTypes layer) const; - - private: - size_t size; - - //! Execute the ResetCell() function for a module which implements - //! the ResetCell() function. - template - typename std::enable_if< - HasResetCellCheck::value, void>::type - ResetCell(T* layer) const; - - //! Do not execute the Reset() function for a module which doesn't implement - // the Reset() or Model() function. - template - typename std::enable_if< - !HasResetCellCheck::value, void>::type - ResetCell(T* layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "reset_cell_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/reset_cell_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/reset_cell_visitor_impl.hpp deleted file mode 100644 index c687a553c0..0000000000 --- a/src/mlpack/methods/ann/visitor/reset_cell_visitor_impl.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @file methods/ann/visitor/reset_cell_visitor_impl.hpp - * @author Sumedh Ghaisas - * - * Implementation of the ResetCell() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_RESET_CELL_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_RESET_CELL_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "reset_cell_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! ResetVisitor visitor class. -inline ResetCellVisitor::ResetCellVisitor(const size_t size) : size(size) -{ - /* Nothing to do here. */ -} - -//! ResetVisitor visitor class. -template -inline void ResetCellVisitor::operator()(LayerType* layer) const -{ - ResetCell(layer); -} - -inline void ResetCellVisitor::operator()(MoreTypes layer) const -{ - layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - HasResetCellCheck::value, void>::type -ResetCellVisitor::ResetCell(T* layer) const -{ - layer->ResetCell(size); -} - -template -inline typename std::enable_if< - !HasResetCellCheck::value, void>::type -ResetCellVisitor::ResetCell(T* /* layer */) const -{ - /* Nothing to do here. */ -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/reset_visitor.hpp b/src/mlpack/methods/ann/visitor/reset_visitor.hpp deleted file mode 100644 index 72545cf53d..0000000000 --- a/src/mlpack/methods/ann/visitor/reset_visitor.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @file methods/ann/visitor/reset_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the Reset() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_RESET_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_RESET_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * ResetVisitor executes the Reset() function. - */ -class ResetVisitor : public boost::static_visitor -{ - public: - //! Execute the Reset() function. - template - void operator()(LayerType* layer) const; - - void operator()(MoreTypes layer) const; - - private: - //! Execute the Reset() function for a module which implements the Reset() - //! function. - template - typename std::enable_if< - HasResetCheck::value && - !HasModelCheck::value, void>::type - ResetParameter(T* layer) const; - - //! Execute the Reset() function for a module which implements the Model() - //! function. - template - typename std::enable_if< - !HasResetCheck::value && - HasModelCheck::value, void>::type - ResetParameter(T* layer) const; - - //! Execute the Reset() function for a module which implements the Reset() - //! and Model() function. - template - typename std::enable_if< - HasResetCheck::value && - HasModelCheck::value, void>::type - ResetParameter(T* layer) const; - - //! Do not execute the Reset() function for a module which doesn't implement - // the Reset() or Model() function. - template - typename std::enable_if< - !HasResetCheck::value && - !HasModelCheck::value, void>::type - ResetParameter(T* layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "reset_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/reset_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/reset_visitor_impl.hpp deleted file mode 100644 index 9754c9baa5..0000000000 --- a/src/mlpack/methods/ann/visitor/reset_visitor_impl.hpp +++ /dev/null @@ -1,80 +0,0 @@ -/** - * @file methods/ann/visitor/reset_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the Reset() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_RESET_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_RESET_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "reset_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! ResetVisitor visitor class. -template -inline void ResetVisitor::operator()(LayerType* layer) const -{ - ResetParameter(layer); -} - -inline void ResetVisitor::operator()(MoreTypes layer) const -{ - layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - HasResetCheck::value && - !HasModelCheck::value, void>::type -ResetVisitor::ResetParameter(T* layer) const -{ - layer->Reset(); -} - -template -inline typename std::enable_if< - !HasResetCheck::value && - HasModelCheck::value, void>::type -ResetVisitor::ResetParameter(T* layer) const -{ - for (size_t i = 0; i < layer->Model().size(); ++i) - { - boost::apply_visitor(ResetVisitor(), layer->Model()[i]); - } -} - -template -inline typename std::enable_if< - HasResetCheck::value && - HasModelCheck::value, void>::type -ResetVisitor::ResetParameter(T* layer) const -{ - for (size_t i = 0; i < layer->Model().size(); ++i) - { - boost::apply_visitor(ResetVisitor(), layer->Model()[i]); - } - - layer->Reset(); -} - -template -inline typename std::enable_if< - !HasResetCheck::value && - !HasModelCheck::value, void>::type -ResetVisitor::ResetParameter(T* /* layer */) const -{ - /* Nothing to do here. */ -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/reward_set_visitor.hpp b/src/mlpack/methods/ann/visitor/reward_set_visitor.hpp deleted file mode 100644 index a4c6301d00..0000000000 --- a/src/mlpack/methods/ann/visitor/reward_set_visitor.hpp +++ /dev/null @@ -1,81 +0,0 @@ -/** - * @file methods/ann/visitor/reward_set_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the Reward() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_REWARD_SET_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_REWARD_SET_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * RewardSetVisitor set the reward parameter given the reward value. - */ -class RewardSetVisitor : public boost::static_visitor -{ - public: - //! Set the reward parameter given the reward value. - RewardSetVisitor(const double reward); - - //! Set the reward parameter. - template - void operator()(LayerType* layer) const; - - void operator()(MoreTypes layer) const; - - private: - //! The reward value. - const double reward; - - //! Set the deterministic parameter if the module implements the - //! Deterministic() and Model() function. - template - typename std::enable_if< - HasRewardCheck::value && - HasModelCheck::value, void>::type - LayerReward(T* layer) const; - - //! Set the deterministic parameter if the module implements the - //! Model() function. - template - typename std::enable_if< - !HasRewardCheck::value && - HasModelCheck::value, void>::type - LayerReward(T* layer) const; - - //! Set the deterministic parameter if the module implements the - //! Deterministic() function. - template - typename std::enable_if< - HasRewardCheck::value && - !HasModelCheck::value, void>::type - LayerReward(T* layer) const; - - //! Do not set the deterministic parameter if the module doesn't implement the - //! Deterministic() or Model() function. - template - typename std::enable_if< - !HasRewardCheck::value && - !HasModelCheck::value, void>::type - LayerReward(T* layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "reward_set_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/reward_set_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/reward_set_visitor_impl.hpp deleted file mode 100644 index 8bc0eb5a21..0000000000 --- a/src/mlpack/methods/ann/visitor/reward_set_visitor_impl.hpp +++ /dev/null @@ -1,87 +0,0 @@ -/** - * @file methods/ann/visitor/reward_set_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the Reward() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_REWARD_SET_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_REWARD_SET_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "reward_set_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! RewardSetVisitor visitor class. -inline RewardSetVisitor::RewardSetVisitor(const double reward) : reward(reward) -{ - /* Nothing to do here. */ -} - -template -inline void RewardSetVisitor::operator()(LayerType* layer) const -{ - LayerReward(layer); -} - -inline void RewardSetVisitor::operator()(MoreTypes layer) const -{ - layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - HasRewardCheck::value && - HasModelCheck::value, void>::type -RewardSetVisitor::LayerReward(T* layer) const -{ - layer->Reward() = reward; - - for (size_t i = 0; i < layer->Model().size(); ++i) - { - boost::apply_visitor(RewardSetVisitor(reward), - layer->Model()[i]); - } -} - -template -inline typename std::enable_if< - !HasRewardCheck::value && - HasModelCheck::value, void>::type -RewardSetVisitor::LayerReward(T* layer) const -{ - for (size_t i = 0; i < layer->Model().size(); ++i) - { - boost::apply_visitor(RewardSetVisitor(reward), - layer->Model()[i]); - } -} - -template -inline typename std::enable_if< - HasRewardCheck::value && - !HasModelCheck::value, void>::type -RewardSetVisitor::LayerReward(T* layer) const -{ - layer->Reward() = reward; -} - -template -inline typename std::enable_if< - !HasRewardCheck::value && - !HasModelCheck::value, void>::type -RewardSetVisitor::LayerReward(T* /* input */) const -{ - /* Nothing to do here. */ -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/run_set_visitor.hpp b/src/mlpack/methods/ann/visitor/run_set_visitor.hpp deleted file mode 100644 index b993ea07f2..0000000000 --- a/src/mlpack/methods/ann/visitor/run_set_visitor.hpp +++ /dev/null @@ -1,83 +0,0 @@ -/** - * @file methods/ann/visitor/run_set_visitor.hpp - * @author Saksham Bansal - * - * This file provides an abstraction for the Run() function for - * different layers and automatically directs any parameter to the right layer - * type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_RUN_SET_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_RUN_SET_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * RunSetVisitor set the run parameter given the - * run value. - */ -class RunSetVisitor : public boost::static_visitor -{ - public: - //! Set the run parameter given the current run value. - RunSetVisitor(const bool run = true); - - //! Set the run parameter. - template - void operator()(LayerType* layer) const; - - void operator()(MoreTypes layer) const; - - private: - //! The run parameter. - const bool run; - - //! Set the run parameter if the module implements the - //! Run() and Model() function. - template - typename std::enable_if< - HasRunCheck::value && - HasModelCheck::value, void>::type - LayerRun(T* layer) const; - - //! Set the run parameter if the module implements the - //! Model() function. - template - typename std::enable_if< - !HasRunCheck::value && - HasModelCheck::value, void>::type - LayerRun(T* layer) const; - - //! Set the run parameter if the module implements the - //! Run() function. - template - typename std::enable_if< - HasRunCheck::value && - !HasModelCheck::value, void>::type - LayerRun(T* layer) const; - - //! Do not set the run parameter if the module doesn't implement the - //! Run() or Model() function. - template - typename std::enable_if< - !HasRunCheck::value && - !HasModelCheck::value, void>::type - LayerRun(T* layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "run_set_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/run_set_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/run_set_visitor_impl.hpp deleted file mode 100644 index 5e0ece0217..0000000000 --- a/src/mlpack/methods/ann/visitor/run_set_visitor_impl.hpp +++ /dev/null @@ -1,88 +0,0 @@ -/** - * @file methods/ann/visitor/run_set_visitor_impl.hpp - * @author Saksham Bansal - * - * Implementation of the Run() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_RUN_SET_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_RUN_SET_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "run_set_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! RunSetVisitor visitor class. -inline RunSetVisitor::RunSetVisitor( - const bool run) : run(run) -{ - /* Nothing to do here. */ -} - -template -inline void RunSetVisitor::operator()(LayerType* layer) const -{ - LayerRun(layer); -} - -inline void RunSetVisitor::operator()(MoreTypes layer) const -{ - layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - HasRunCheck::value && - HasModelCheck::value, void>::type -RunSetVisitor::LayerRun(T* layer) const -{ - layer->Run() = run; - - for (size_t i = 0; i < layer->Model().size(); ++i) - { - boost::apply_visitor(RunSetVisitor(run), - layer->Model()[i]); - } -} - -template -inline typename std::enable_if< - !HasRunCheck::value && - HasModelCheck::value, void>::type -RunSetVisitor::LayerRun(T* layer) const -{ - for (size_t i = 0; i < layer->Model().size(); ++i) - { - boost::apply_visitor(RunSetVisitor(run), - layer->Model()[i]); - } -} - -template -inline typename std::enable_if< - HasRunCheck::value && - !HasModelCheck::value, void>::type -RunSetVisitor::LayerRun(T* layer) const -{ - layer->Run() = run; -} - -template -inline typename std::enable_if< - !HasRunCheck::value && - !HasModelCheck::value, void>::type -RunSetVisitor::LayerRun(T* /* input */) const -{ - /* Nothing to do here. */ -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/save_output_parameter_visitor.hpp b/src/mlpack/methods/ann/visitor/save_output_parameter_visitor.hpp deleted file mode 100644 index 2ff0c9ea4e..0000000000 --- a/src/mlpack/methods/ann/visitor/save_output_parameter_visitor.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/** - * @file methods/ann/visitor/save_output_parameter_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the OutputParameter() function for - * different layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_SAVE_OUTPUT_PARAMETER_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_SAVE_OUTPUT_PARAMETER_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * SaveOutputParameterVisitor saves the output parameter into the given - * parameter set. - */ -class SaveOutputParameterVisitor : public boost::static_visitor -{ - public: - //! Save the output parameter into the given parameter set. - SaveOutputParameterVisitor(std::vector& parameter); - - //! Save the output parameter. - template - void operator()(LayerType* layer) const; - - void operator()(MoreTypes layer) const; - - private: - //! The parameter set. - std::vector& parameter; - - //! Save the output parameter for a module which doesn't implement the - //! Model() function. - template - typename std::enable_if< - !HasModelCheck::value, void>::type - OutputParameter(T* layer) const; - - //! Save the output parameter for a module which implements the Model() - //! function. - template - typename std::enable_if< - HasModelCheck::value, void>::type - OutputParameter(T* layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "save_output_parameter_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/save_output_parameter_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/save_output_parameter_visitor_impl.hpp deleted file mode 100644 index cc3559c165..0000000000 --- a/src/mlpack/methods/ann/visitor/save_output_parameter_visitor_impl.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/** - * @file methods/ann/visitor/save_output_parameter_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the OutputParameter() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_SAVE_OUTPUT_PARAMETER_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_SAVE_OUTPUT_PARAMETER_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "load_output_parameter_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! SaveOutputParameterVisitor visitor class. -inline SaveOutputParameterVisitor::SaveOutputParameterVisitor( - std::vector& parameter) : parameter(parameter) -{ - /* Nothing to do here. */ -} - -template -inline void SaveOutputParameterVisitor::operator()(LayerType* layer) const -{ - OutputParameter(layer); -} - -inline void SaveOutputParameterVisitor::operator()(MoreTypes layer) const -{ - layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - !HasModelCheck::value, void>::type -SaveOutputParameterVisitor::OutputParameter(T* layer) const -{ - parameter.push_back(layer->OutputParameter()); -} - -template -inline typename std::enable_if< - HasModelCheck::value, void>::type -SaveOutputParameterVisitor::OutputParameter(T* layer) const -{ - parameter.push_back(layer->OutputParameter()); - - for (size_t i = 0; i < layer->Model().size(); ++i) - { - boost::apply_visitor(SaveOutputParameterVisitor(parameter), - layer->Model()[i]); - } -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/set_input_height_visitor.hpp b/src/mlpack/methods/ann/visitor/set_input_height_visitor.hpp deleted file mode 100644 index 7e47e4ca13..0000000000 --- a/src/mlpack/methods/ann/visitor/set_input_height_visitor.hpp +++ /dev/null @@ -1,84 +0,0 @@ -/** - * @file methods/ann/visitor/set_input_height_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the InputHeight() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_SET_INPUT_HEIGHT_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_SET_INPUT_HEIGHT_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * SetInputHeightVisitor updates the input height parameter with the given input - * height. - */ -class SetInputHeightVisitor : public boost::static_visitor -{ - public: - //! Update the input height parameter with the given input height. - SetInputHeightVisitor(const size_t inputHeight = 0, const bool reset = false); - - //! Update the input height parameter. - template - bool operator()(LayerType* layer) const; - - bool operator()(MoreTypes layer) const; - - private: - //! The input height parameter. - size_t inputHeight; - - //! If set reset the height parameter if already set. - bool reset; - - //! Do nothing if the module doesn't implement the InputHeight() or Model() - //! function. - template - typename std::enable_if< - !HasInputHeight::value && - !HasModelCheck::value, bool>::type - LayerInputHeight(T* layer) const; - - //! Update the input height if the module implements the InputHeight() - //! function. - template - typename std::enable_if< - HasInputHeight::value && - !HasModelCheck::value, bool>::type - LayerInputHeight(T* layer) const; - - //! Update the input height if the module implements the Model() function. - template - typename std::enable_if< - !HasInputHeight::value && - HasModelCheck::value, bool>::type - LayerInputHeight(T* layer) const; - - //! Update the input height if the module implements the InputHeight() or - //! Model() function. - template - typename std::enable_if< - HasInputHeight::value && - HasModelCheck::value, bool>::type - LayerInputHeight(T* layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "set_input_height_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/set_input_height_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/set_input_height_visitor_impl.hpp deleted file mode 100644 index a5a3f8c0f7..0000000000 --- a/src/mlpack/methods/ann/visitor/set_input_height_visitor_impl.hpp +++ /dev/null @@ -1,102 +0,0 @@ -/** - * @file methods/ann/visitor/set_input_height_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the InputHeight() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_SET_INPUT_HEIGHT_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_SET_INPUT_HEIGHT_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "set_input_height_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! SetInputHeightVisitor visitor class. -inline SetInputHeightVisitor::SetInputHeightVisitor(const size_t inputHeight, - const bool reset) : - inputHeight(inputHeight), - reset(reset) -{ - /* Nothing to do here. */ -} - -template -inline bool SetInputHeightVisitor::operator()(LayerType* layer) const -{ - return LayerInputHeight(layer); -} - -inline bool SetInputHeightVisitor::operator()(MoreTypes layer) const -{ - return layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - !HasInputHeight::value && - !HasModelCheck::value, bool>::type -SetInputHeightVisitor::LayerInputHeight(T* /* layer */) const -{ - return false; -} - -template -inline typename std::enable_if< - HasInputHeight::value && - !HasModelCheck::value, bool>::type -SetInputHeightVisitor::LayerInputHeight(T* layer) const -{ - if (layer->InputHeight() == 0 || reset) - { - layer->InputHeight() = inputHeight; - } - - return true; -} - -template -inline typename std::enable_if< - !HasInputHeight::value && - HasModelCheck::value, bool>::type -SetInputHeightVisitor::LayerInputHeight(T* layer) const -{ - for (size_t i = 0; i < layer->Model().size(); ++i) - { - boost::apply_visitor(SetInputHeightVisitor(inputHeight, reset), - layer->Model()[i]); - } - - return true; -} - -template -inline typename std::enable_if< - HasInputHeight::value && - HasModelCheck::value, bool>::type -SetInputHeightVisitor::LayerInputHeight(T* layer) const -{ - if (layer->InputHeight() == 0 || reset) - { - layer->InputHeight() = inputHeight; - } - - for (size_t i = 0; i < layer->Model().size(); ++i) - { - boost::apply_visitor(SetInputHeightVisitor(inputHeight, reset), - layer->Model()[i]); - } - - return true; -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/set_input_width_visitor.hpp b/src/mlpack/methods/ann/visitor/set_input_width_visitor.hpp deleted file mode 100644 index f7fbd6f4e2..0000000000 --- a/src/mlpack/methods/ann/visitor/set_input_width_visitor.hpp +++ /dev/null @@ -1,83 +0,0 @@ -/** - * @file methods/ann/visitor/set_input_width_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the InputWidth() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_SET_INPUT_WIDTH_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_SET_INPUT_WIDTH_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * SetInputWidthVisitor updates the input width parameter with the given input - * width. - */ -class SetInputWidthVisitor : public boost::static_visitor -{ - public: - //! Update the input width parameter with the given input width. - SetInputWidthVisitor(const size_t inputWidth = 0, const bool reset = false); - - //! Update the input width parameter. - template - bool operator()(LayerType* layer) const; - - bool operator()(MoreTypes layer) const; - - private: - //! The input width parameter. - size_t inputWidth; - - //! If set reset the height parameter if already set. - bool reset; - - //! Do nothing if the module doesn't implement the InputWidth() or Model() - //! function. - template - typename std::enable_if< - !HasInputWidth::value && - !HasModelCheck::value, bool>::type - LayerInputWidth(T* layer) const; - - //! Update the input width if the module implements the InputWidth() function. - template - typename std::enable_if< - HasInputWidth::value && - !HasModelCheck::value, bool>::type - LayerInputWidth(T* layer) const; - - //! Update the input width if the module implements the Model() function. - template - typename std::enable_if< - !HasInputWidth::value && - HasModelCheck::value, bool>::type - LayerInputWidth(T* layer) const; - - //! Update the input width if the module implements the InputWidth() or - //! Model() function. - template - typename std::enable_if< - HasInputWidth::value && - HasModelCheck::value, bool>::type - LayerInputWidth(T* layer) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "set_input_width_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/set_input_width_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/set_input_width_visitor_impl.hpp deleted file mode 100644 index 56224ed009..0000000000 --- a/src/mlpack/methods/ann/visitor/set_input_width_visitor_impl.hpp +++ /dev/null @@ -1,102 +0,0 @@ -/** - * @file methods/ann/visitor/set_input_width_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the InputWidth() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_SET_INPUT_WIDTH_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_SET_INPUT_WIDTH_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "set_input_width_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! SetInputWidthVisitor visitor class. -inline SetInputWidthVisitor::SetInputWidthVisitor(const size_t inputWidth, - const bool reset) : - inputWidth(inputWidth), - reset(reset) -{ - /* Nothing to do here. */ -} - -template -inline bool SetInputWidthVisitor::operator()(LayerType* layer) const -{ - return LayerInputWidth(layer); -} - -inline bool SetInputWidthVisitor::operator()(MoreTypes layer) const -{ - return layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - !HasInputWidth::value && - !HasModelCheck::value, bool>::type -SetInputWidthVisitor::LayerInputWidth(T* /* layer */) const -{ - return false; -} - -template -inline typename std::enable_if< - HasInputWidth::value && - !HasModelCheck::value, bool>::type -SetInputWidthVisitor::LayerInputWidth(T* layer) const -{ - if (layer->InputWidth() == 0 || reset) - { - layer->InputWidth() = inputWidth; - } - - return true; -} - -template -inline typename std::enable_if< - !HasInputWidth::value && - HasModelCheck::value, bool>::type -SetInputWidthVisitor::LayerInputWidth(T* layer) const -{ - for (size_t i = 0; i < layer->Model().size(); ++i) - { - boost::apply_visitor(SetInputWidthVisitor(inputWidth, reset), - layer->Model()[i]); - } - - return true; -} - -template -inline typename std::enable_if< - HasInputWidth::value && - HasModelCheck::value, bool>::type -SetInputWidthVisitor::LayerInputWidth(T* layer) const -{ - if (layer->InputWidth() == 0 || reset) - { - layer->InputWidth() = inputWidth; - } - - for (size_t i = 0; i < layer->Model().size(); ++i) - { - boost::apply_visitor(SetInputWidthVisitor(inputWidth, reset), - layer->Model()[i]); - } - - return true; -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/weight_set_visitor.hpp b/src/mlpack/methods/ann/visitor/weight_set_visitor.hpp deleted file mode 100644 index 81c6c110df..0000000000 --- a/src/mlpack/methods/ann/visitor/weight_set_visitor.hpp +++ /dev/null @@ -1,82 +0,0 @@ -/** - * @file methods/ann/visitor/weight_set_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the Weight() function for different - * layers and automatically directs any parameter to the right layer type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_WEIGHT_SET_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_WEIGHT_SET_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * WeightSetVisitor update the module parameters given the parameters set. - */ -class WeightSetVisitor : public boost::static_visitor -{ - public: - //! Update the parameters given the parameters set and offset. - WeightSetVisitor(arma::mat& weight, const size_t offset = 0); - - //! Update the parameters set. - template - size_t operator()(LayerType* layer) const; - - size_t operator()(MoreTypes layer) const; - - private: - //! The parameters set. - arma::mat& weight; - - //! The parameters offset. - const size_t offset; - - //! Do not update the parameters if the module doesn't implement the - //! Parameters() or Model() function. - template - typename std::enable_if< - !HasParametersCheck::value && - !HasModelCheck::value, size_t>::type - LayerSize(T* layer, P&& input) const; - - //! Update the parameters if the module implements the Model() function. - template - typename std::enable_if< - !HasParametersCheck::value && - HasModelCheck::value, size_t>::type - LayerSize(T* layer, P&& input) const; - - //! Update the parameters if the module implements the Parameters() function. - template - typename std::enable_if< - HasParametersCheck::value && - !HasModelCheck::value, size_t>::type - LayerSize(T* layer, P&& input) const; - - //! Update the parameters if the module implements the Model() and - //! Parameters() function. - template - typename std::enable_if< - HasParametersCheck::value && - HasModelCheck::value, size_t>::type - LayerSize(T* layer, P&& input) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "weight_set_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/weight_set_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/weight_set_visitor_impl.hpp deleted file mode 100644 index fa52a469c7..0000000000 --- a/src/mlpack/methods/ann/visitor/weight_set_visitor_impl.hpp +++ /dev/null @@ -1,100 +0,0 @@ -/** - * @file methods/ann/visitor/weight_set_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the Weight() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_WEIGHT_SET_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_WEIGHT_SET_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "weight_set_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! WeightSetVisitor visitor class. -inline WeightSetVisitor::WeightSetVisitor(arma::mat& weight, - const size_t offset) : - weight(weight), - offset(offset) -{ - /* Nothing to do here. */ -} - -template -inline size_t WeightSetVisitor::operator()(LayerType* layer) const -{ - return LayerSize(layer, layer->OutputParameter()); -} - -inline size_t WeightSetVisitor::operator()(MoreTypes layer) const -{ - return layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - !HasParametersCheck::value && - !HasModelCheck::value, size_t>::type -WeightSetVisitor::LayerSize(T* /* layer */, P&& /*output */) const -{ - return 0; -} - -template -inline typename std::enable_if< - !HasParametersCheck::value && - HasModelCheck::value, size_t>::type -WeightSetVisitor::LayerSize(T* layer, P&& /*output */) const -{ - size_t modelOffset = 0; - for (size_t i = 0; i < layer->Model().size(); ++i) - { - modelOffset += boost::apply_visitor(WeightSetVisitor( - weight, modelOffset + offset), layer->Model()[i]); - } - - return modelOffset; -} - -template -inline typename std::enable_if< - HasParametersCheck::value && - !HasModelCheck::value, size_t>::type -WeightSetVisitor::LayerSize(T* layer, P&& /* output */) const -{ - layer->Parameters() = arma::mat(weight.memptr() + offset, - layer->Parameters().n_rows, layer->Parameters().n_cols, false, false); - - return layer->Parameters().n_elem; -} - -template -inline typename std::enable_if< - HasParametersCheck::value && - HasModelCheck::value, size_t>::type -WeightSetVisitor::LayerSize(T* layer, P&& /* output */) const -{ - layer->Parameters() = arma::mat(weight.memptr() + offset, - layer->Parameters().n_rows, layer->Parameters().n_cols, false, false); - - size_t modelOffset = layer->Parameters().n_elem; - for (size_t i = 0; i < layer->Model().size(); ++i) - { - modelOffset += boost::apply_visitor(WeightSetVisitor( - weight, modelOffset + offset), layer->Model()[i]); - } - - return modelOffset; -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/methods/ann/visitor/weight_size_visitor.hpp b/src/mlpack/methods/ann/visitor/weight_size_visitor.hpp deleted file mode 100644 index 074ca56614..0000000000 --- a/src/mlpack/methods/ann/visitor/weight_size_visitor.hpp +++ /dev/null @@ -1,76 +0,0 @@ -/** - * @file methods/ann/visitor/weight_size_visitor.hpp - * @author Marcus Edel - * - * This file provides an abstraction for the WeightSize() function for - * different layers and automatically directs any parameter to the right layer - * type. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_WEIGHT_SIZE_VISITOR_HPP -#define MLPACK_METHODS_ANN_VISITOR_WEIGHT_SIZE_VISITOR_HPP - -#include - -#include - -namespace mlpack { -namespace ann { - -/** - * WeightSizeVisitor returns the number of weights of the given module. - */ -class WeightSizeVisitor : public boost::static_visitor -{ - public: - //! Return the number of weights. - template - size_t operator()(LayerType* layer) const; - - size_t operator()(MoreTypes layer) const; - - private: - //! If the module doesn't implement the Parameters() or Model() function - //! return 0. - template - typename std::enable_if< - !HasParametersCheck::value && - !HasModelCheck::value, size_t>::type - LayerSize(T* layer, P& output) const; - - //! Return the number of parameters if the module implements the Model() - //! function. - template - typename std::enable_if< - !HasParametersCheck::value && - HasModelCheck::value, size_t>::type - LayerSize(T* layer, P& output) const; - - //! Return the number of parameters if the module implements the Parameters() - //! function. - template - typename std::enable_if< - HasParametersCheck::value && - !HasModelCheck::value, size_t>::type - LayerSize(T* layer, P& output) const; - - //! Return the accumulated number of parameters if the module implements the - //! Parameters() and Model() function. - template - typename std::enable_if< - HasParametersCheck::value && - HasModelCheck::value, size_t>::type - LayerSize(T* layer, P& output) const; -}; - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "weight_size_visitor_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/visitor/weight_size_visitor_impl.hpp b/src/mlpack/methods/ann/visitor/weight_size_visitor_impl.hpp deleted file mode 100644 index 50ef266a63..0000000000 --- a/src/mlpack/methods/ann/visitor/weight_size_visitor_impl.hpp +++ /dev/null @@ -1,84 +0,0 @@ -/** - * @file methods/ann/visitor/weight_size_visitor_impl.hpp - * @author Marcus Edel - * - * Implementation of the WeightSize() function layer abstraction. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_VISITOR_WEIGHT_SIZE_VISITOR_IMPL_HPP -#define MLPACK_METHODS_ANN_VISITOR_WEIGHT_SIZE_VISITOR_IMPL_HPP - -// In case it hasn't been included yet. -#include "weight_size_visitor.hpp" - -namespace mlpack { -namespace ann { - -//! WeightSizeVisitor visitor class. -template -inline size_t WeightSizeVisitor::operator()(LayerType* layer) const -{ - return LayerSize(layer, layer->OutputParameter()); -} - -inline size_t WeightSizeVisitor::operator()(MoreTypes layer) const -{ - return layer.apply_visitor(*this); -} - -template -inline typename std::enable_if< - !HasParametersCheck::value && - !HasModelCheck::value, size_t>::type -WeightSizeVisitor::LayerSize(T* /* layer */, P& /* output */) const -{ - return 0; -} - -template -inline typename std::enable_if< - !HasParametersCheck::value && - HasModelCheck::value, size_t>::type -WeightSizeVisitor::LayerSize(T* layer, P& /* output */) const -{ - size_t weights = 0; - for (size_t i = 0; i < layer->Model().size(); ++i) - { - weights += boost::apply_visitor(WeightSizeVisitor(), layer->Model()[i]); - } - - return weights; -} - -template -inline typename std::enable_if< - HasParametersCheck::value && - !HasModelCheck::value, size_t>::type -WeightSizeVisitor::LayerSize(T* layer, P& /* output */) const -{ - return layer->Parameters().n_elem; -} - -template -inline typename std::enable_if< - HasParametersCheck::value && - HasModelCheck::value, size_t>::type -WeightSizeVisitor::LayerSize(T* layer, P& /* output */) const -{ - size_t weights = layer->Parameters().n_elem; - for (size_t i = 0; i < layer->Model().size(); ++i) - { - weights += boost::apply_visitor(WeightSizeVisitor(), layer->Model()[i]); - } - - return weights; -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index e101a20ffb..0f0ce6d831 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -3,7 +3,7 @@ include(CTest) # mlpack test executable. add_executable(mlpack_test EXCLUDE_FROM_ALL - # activation_functions_test.cpp +# activation_functions_test.cpp adaboost_test.cpp akfn_test.cpp aknn_test.cpp @@ -59,7 +59,6 @@ add_executable(mlpack_test krann_search_test.cpp ksinit_test.cpp lars_test.cpp -# layer_names_test.cpp lin_alg_test.cpp linear_regression_test.cpp lmnn_test.cpp @@ -95,7 +94,7 @@ add_executable(mlpack_test random_test.cpp randomized_svd_test.cpp range_search_test.cpp - rbm_network_test.cpp +# rbm_network_test.cpp rectangle_tree_test.cpp recurrent_network_test.cpp # rnn_reber_test.cpp diff --git a/src/mlpack/tests/ann_visitor_test.cpp b/src/mlpack/tests/ann_visitor_test.cpp deleted file mode 100644 index 29f376611e..0000000000 --- a/src/mlpack/tests/ann_visitor_test.cpp +++ /dev/null @@ -1,235 +0,0 @@ -/** - * @file tests/ann_visitor_test.cpp - * - * Tests for testing visitors in ANN's of mlpack. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#include -#include -#include -#include -#include -#include - -#include "catch.hpp" -#include "test_catch_tools.hpp" - -using namespace mlpack; -using namespace mlpack::ann; - -/** - * Test that the BiasSetVisitor works properly. - */ -TEST_CASE("BiasSetVisitorTest", "[ANNVisitorTest]") -{ - LayerTypes<> linear = new Linear<>(10, 10); - - arma::mat layerWeights(110, 1); - layerWeights.zeros(); - - ResetVisitor resetVisitor; - - boost::apply_visitor(WeightSetVisitor(layerWeights, 0), linear); - - boost::apply_visitor(resetVisitor, linear); - - arma::mat weight = {"1 2 3 4 5 6 7 8 9 10"}; - - size_t biasSize = boost::apply_visitor(BiasSetVisitor(weight, 0), linear); - - REQUIRE(biasSize == 10); - - arma::mat input(10, 1), output; - input.randu(); - - boost::apply_visitor(ForwardVisitor(input, output), linear); - - REQUIRE(arma::accu(output) == 55); - - boost::apply_visitor(DeleteVisitor(), linear); -} - -/** - * Check correctness of WeightSize() for a layer. - */ -void CheckCorrectnessOfWeightSize(LayerTypes<>& layer) -{ - size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), - layer); - - arma::mat parameters; - boost::apply_visitor(ParametersVisitor(parameters), layer); - - REQUIRE(weightSize == parameters.n_elem); -} - -/** - * Test that WeightSetVisitor works properly. - */ -TEST_CASE("WeightSetVisitorTest", "[ANNVisitorTest]") -{ - size_t randomSize = arma::randi(arma::distr_param(1, 100)); - - LayerTypes<> linear = new Linear<>(randomSize, randomSize); - - arma::mat layerWeights(randomSize * randomSize + randomSize, 1); - layerWeights.zeros(); - - size_t setWeights = boost::apply_visitor(WeightSetVisitor(layerWeights, 0), - linear); - - REQUIRE(setWeights == randomSize * randomSize + randomSize); -} - -/** - * Test that WeightSizeVisitor works properly for linear layer. - */ -TEST_CASE("WeightSizeVisitorTestForLinearLayer", "[ANNVisitorTest]") -{ - size_t randomInSize = arma::randi(arma::distr_param(1, 100)); - size_t randomOutSize = arma::randi(arma::distr_param(1, 100)); - - LayerTypes<> linearLayer = new Linear<>(randomInSize, randomOutSize); - - CheckCorrectnessOfWeightSize(linearLayer); -} - -/** - * Test that WeightSizeVisitor works properly for concat layer. - */ -TEST_CASE("WeightSizeVisitorTestForConcatLayer", "[ANNVisitorTest]") -{ - LayerTypes<> concatLayer = new Concat<>(); - - CheckCorrectnessOfWeightSize(concatLayer); -} - -/** - * Test that WeightSizeVisitor works properly for fast lstm layer. - */ -TEST_CASE("WeightSizeVisitorTestForFastLSTMLayer", "[ANNVisitorTest]") -{ - size_t randomInSize = arma::randi(arma::distr_param(1, 100)); - size_t randomOutSize = arma::randi(arma::distr_param(1, 100)); - - LayerTypes<> fastLSTMLayer = new FastLSTM<>(randomInSize, randomOutSize); - - CheckCorrectnessOfWeightSize(fastLSTMLayer); -} - -/** - * Test that WeightSizeVisitor works properly for Add layer. - */ -TEST_CASE("WeightSizeVisitorTestForAddLayer", "[ANNVisitorTest]") -{ - size_t randomOutSize = arma::randi(arma::distr_param(1, 100)); - - LayerTypes<> addLayer = new Add<>(randomOutSize); - - CheckCorrectnessOfWeightSize(addLayer); -} - -/** - * Test that WeightSizeVisitor works properly for Atrous Convolution Layer. - */ -TEST_CASE("WeightSizeVisitorTestForAtrousConvolutionLayer", "[ANNVisitorTest]") -{ - size_t randomInSize = arma::randi(arma::distr_param(1, 100)); - size_t randomOutSize = arma::randi(arma::distr_param(1, 100)); - size_t randomKernelWidth = arma::randi(arma::distr_param(1, 100)); - size_t randomKernelHeight = arma::randi(arma::distr_param(1, 100)); - - LayerTypes<> atrousConvLayer = new AtrousConvolution<>(randomInSize, - randomOutSize, randomKernelWidth, randomKernelHeight); - - CheckCorrectnessOfWeightSize(atrousConvLayer); -} - - -/** - * Test that WeightSizeVisitor works properly for Convolution layer. - */ -TEST_CASE("WeightSizeVisitorTestForConvLayer", "[ANNVisitorTest]") -{ - size_t randomInSize = arma::randi(arma::distr_param(1, 100)); - size_t randomOutSize = arma::randi(arma::distr_param(1, 100)); - size_t randomKernelWidth = arma::randi(arma::distr_param(1, 100)); - size_t randomKernelHeight = arma::randi(arma::distr_param(1, 100)); - - LayerTypes<> convLayer = new Convolution<>(randomInSize, randomOutSize, - randomKernelWidth, randomKernelHeight); - CheckCorrectnessOfWeightSize(convLayer); -} - -/** - * Test that WeightSizeVisitor works properly for BatchNorm layer. - */ -TEST_CASE("WeightSizeVisitorTestForBatchNormLayer", "[ANNVisitorTest]") -{ - size_t randomSize = arma::randi(arma::distr_param(1, 100)); - - LayerTypes<> batchNorm = new BatchNorm<>(randomSize); - CheckCorrectnessOfWeightSize(batchNorm); -} - -/** - * Test that WeightSizeVisitor works properly for LSTM layer. - */ -TEST_CASE("WeightSizeVisitorTestForLSTMLayer", "[ANNVisitorTest]") -{ - size_t randomInSize = arma::randi(arma::distr_param(1, 100)); - size_t randomOutSize = arma::randi(arma::distr_param(1, 100)); - - LayerTypes<> lstm = new LSTM<>(randomInSize, randomOutSize); - CheckCorrectnessOfWeightSize(lstm); -} - -/** - * Test that WeightSizeVisitor works properly for Transposed Convolution layer. - */ -TEST_CASE("WeightSizeVisitorTestForTransposedConvLayer", "[ANNVisitorTest]") -{ - size_t randomInSize = arma::randi(arma::distr_param(1, 100)); - size_t randomOutSize = arma::randi(arma::distr_param(1, 100)); - size_t randomKernelWidth = arma::randi(arma::distr_param(1, 100)); - size_t randomKernelHeight = arma::randi(arma::distr_param(1, 100)); - - LayerTypes<> transposedConvLayer = new TransposedConvolution<>(randomInSize, - randomOutSize, randomKernelWidth, randomKernelHeight); - - CheckCorrectnessOfWeightSize(transposedConvLayer); -} - -/** - * Test that WeightSizeVisitor works properly for noisy linear layer. - */ -TEST_CASE("WeightSizeVisitorTestForNoisyLinearLayer", "[ANNVisitorTest]") -{ - size_t randomInSize = arma::randi(arma::distr_param(1, 100)); - size_t randomOutSize = arma::randi(arma::distr_param(1, 100)); - - LayerTypes<> noisyLinearLayer = new NoisyLinear<>(randomInSize, - randomOutSize); - - CheckCorrectnessOfWeightSize(noisyLinearLayer); -} - -/** - * Test that WeightSizeVisitor works properly for Multihead Attention layer. - */ -TEST_CASE("WeightSizeVisitorTestForMultiheadAttentionLayer", "[ANNVisitorTest]") -{ - size_t randomtgtSeqLen = arma::randi(arma::distr_param(1, 100)); - size_t randomsrcSeqLen = arma::randi(arma::distr_param(1, 100)); - size_t randomembedDim = 768; - size_t randomnumHeads = 12; - - LayerTypes<> MultiheadAttentionLayer = new MultiheadAttention<>( - randomtgtSeqLen, randomsrcSeqLen, randomembedDim, randomnumHeads); - - CheckCorrectnessOfWeightSize(MultiheadAttentionLayer); -} diff --git a/src/mlpack/tests/layer_names_test.cpp b/src/mlpack/tests/layer_names_test.cpp deleted file mode 100644 index 9d94f0ff67..0000000000 --- a/src/mlpack/tests/layer_names_test.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/** - * @file tests/layer_names_test.cpp - * @author Sreenik Seal - * - * Tests for testing the string representation of - * layers in mlpack's ANN module. - * - * 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 - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#include -#include -#include -#include - -#include "catch.hpp" - -using namespace mlpack; -using namespace ann; - -/** - * Test if the LayerNameVisitor works properly. - */ -TEST_CASE("LayerNameVisitorTest", "[LayerNamesTest]") -{ - LayerTypes<> atrousConvolution = new AtrousConvolution<>(); - LayerTypes<> alphaDropout = new AlphaDropout<>(); - LayerTypes<> batchNorm = new BatchNorm<>(); - LayerTypes<> constant = new Constant<>(); - LayerTypes<> convolution = new Convolution<>(); - LayerTypes<> dropConnect = new DropConnect<>(); - LayerTypes<> dropout = new Dropout<>(); - LayerTypes<> flexibleReLU = new FlexibleReLU<>(); - LayerTypes<> layerNorm = new LayerNorm<>(); - LayerTypes<> linear = new Linear<>(); - LayerTypes<> linearNoBias = new LinearNoBias<>(); - LayerTypes<> maxPooling = new MaxPooling<>(); - LayerTypes<> meanPooling = new MeanPooling<>(); - LayerTypes<> multiplyConstant = new MultiplyConstant<>(); - LayerTypes<> reLULayer = new ReLULayer<>(); - LayerTypes<> transposedConvolution = new TransposedConvolution<>(); - LayerTypes<> identityLayer = new IdentityLayer<>(); - LayerTypes<> tanHLayer = new TanHLayer<>(); - LayerTypes<> eLU = new ELU<>(); - LayerTypes<> hardTanH = new HardTanH<>(); - LayerTypes<> leakyReLU = new LeakyReLU<>(); - LayerTypes<> pReLU = new PReLU<>(); - LayerTypes<> sigmoidLayer = new SigmoidLayer<>(); - LayerTypes<> logSoftMax = new LogSoftMax<>(); - LayerTypes<> lstmLayer = new LSTM<>(100, 10); - LayerTypes<> creluLayer = new CReLU<>(); - LayerTypes<> highwayLayer = new Highway<>(); - LayerTypes<> gruLayer = new GRU<>(); - LayerTypes<> glimpseLayer = new Glimpse<>(); - LayerTypes<> fastlstmLayer = new FastLSTM<>(); - LayerTypes<> weightnormLayer = new WeightNorm<>(new IdentityLayer<>()); - - // Bilinear interpolation is not yet supported by the string converter. - LayerTypes<> unsupportedLayer = new BilinearInterpolation<>(); - - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - atrousConvolution) == "atrousconvolution"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - alphaDropout) == "alphadropout"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - batchNorm) == "batchnorm"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - constant) == "constant"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - convolution) == "convolution"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - dropConnect) == "dropconnect"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - dropout) == "dropout"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - flexibleReLU) == "flexiblerelu"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - layerNorm) == "layernorm"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - linear) == "linear"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - linearNoBias) == "linearnobias"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - maxPooling) == "maxpooling"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - meanPooling) == "meanpooling"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - multiplyConstant) == "multiplyconstant"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - reLULayer) == "relu"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - transposedConvolution) == "transposedconvolution"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - identityLayer) == "identity"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - tanHLayer) == "tanh"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - eLU) == "elu"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - hardTanH) == "hardtanh"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - leakyReLU) == "leakyrelu"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - pReLU) == "prelu"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - sigmoidLayer) == "sigmoid"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - logSoftMax) == "logsoftmax"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - unsupportedLayer) == "unsupported"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - lstmLayer) == "lstm"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - creluLayer) == "crelu"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - highwayLayer) == "highway"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - gruLayer) == "gru"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - glimpseLayer) == "glimpse"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - fastlstmLayer) == "fastlstm"); - REQUIRE(boost::apply_visitor(LayerNameVisitor(), - weightnormLayer) == "weightnorm"); - // Delete all instances. - boost::apply_visitor(DeleteVisitor(), atrousConvolution); - boost::apply_visitor(DeleteVisitor(), alphaDropout); - boost::apply_visitor(DeleteVisitor(), batchNorm); - boost::apply_visitor(DeleteVisitor(), constant); - boost::apply_visitor(DeleteVisitor(), convolution); - boost::apply_visitor(DeleteVisitor(), dropConnect); - boost::apply_visitor(DeleteVisitor(), dropout); - boost::apply_visitor(DeleteVisitor(), flexibleReLU); - boost::apply_visitor(DeleteVisitor(), layerNorm); - boost::apply_visitor(DeleteVisitor(), linear); - boost::apply_visitor(DeleteVisitor(), linearNoBias); - boost::apply_visitor(DeleteVisitor(), maxPooling); - boost::apply_visitor(DeleteVisitor(), meanPooling); - boost::apply_visitor(DeleteVisitor(), multiplyConstant); - boost::apply_visitor(DeleteVisitor(), reLULayer); - boost::apply_visitor(DeleteVisitor(), transposedConvolution); - boost::apply_visitor(DeleteVisitor(), identityLayer); - boost::apply_visitor(DeleteVisitor(), tanHLayer); - boost::apply_visitor(DeleteVisitor(), eLU); - boost::apply_visitor(DeleteVisitor(), hardTanH); - boost::apply_visitor(DeleteVisitor(), leakyReLU); - boost::apply_visitor(DeleteVisitor(), pReLU); - boost::apply_visitor(DeleteVisitor(), sigmoidLayer); - boost::apply_visitor(DeleteVisitor(), logSoftMax); - boost::apply_visitor(DeleteVisitor(), unsupportedLayer); - boost::apply_visitor(DeleteVisitor(), lstmLayer); - boost::apply_visitor(DeleteVisitor(), creluLayer); - boost::apply_visitor(DeleteVisitor(), highwayLayer); - boost::apply_visitor(DeleteVisitor(), gruLayer); - boost::apply_visitor(DeleteVisitor(), glimpseLayer); - boost::apply_visitor(DeleteVisitor(), fastlstmLayer); - boost::apply_visitor(DeleteVisitor(), weightnormLayer); -} diff --git a/src/mlpack/tests/gan_test.cpp b/src/mlpack/tests/not_adapted/gan_test.cpp similarity index 100% rename from src/mlpack/tests/gan_test.cpp rename to src/mlpack/tests/not_adapted/gan_test.cpp diff --git a/src/mlpack/tests/rbm_network_test.cpp b/src/mlpack/tests/not_adapted/rbm_network_test.cpp similarity index 100% rename from src/mlpack/tests/rbm_network_test.cpp rename to src/mlpack/tests/not_adapted/rbm_network_test.cpp diff --git a/src/mlpack/tests/wgan_test.cpp b/src/mlpack/tests/not_adapted/wgan_test.cpp similarity index 100% rename from src/mlpack/tests/wgan_test.cpp rename to src/mlpack/tests/not_adapted/wgan_test.cpp