diff --git a/src/mlpack/methods/ann/layer/layer_types.hpp b/src/mlpack/methods/ann/layer/layer_types.hpp index a01e730400..353da3f138 100644 --- a/src/mlpack/methods/ann/layer/layer_types.hpp +++ b/src/mlpack/methods/ann/layer/layer_types.hpp @@ -82,8 +82,7 @@ template + typename OutputDataType> class RBF; template*, VRClassReward*, VirtualBatchNorm*, - RBF* + RBF* >; template diff --git a/src/mlpack/methods/ann/layer/radial_basis_function.hpp b/src/mlpack/methods/ann/layer/radial_basis_function.hpp index d90ce09aba..ba9a27b8ea 100644 --- a/src/mlpack/methods/ann/layer/radial_basis_function.hpp +++ b/src/mlpack/methods/ann/layer/radial_basis_function.hpp @@ -37,8 +37,7 @@ namespace ann /** Artificial Neural Network. */ { template < typename InputDataType = arma::mat, - typename OutputDataType = arma::mat, - typename RegularizerType = NoRegularizer + typename OutputDataType = arma::mat > class RBF { @@ -55,8 +54,7 @@ class RBF */ RBF(const size_t inSize, const size_t outSize, - arma::mat& centres, - RegularizerType regularizer = RegularizerType()); + arma::mat& centres); /** * Reset the layer parameter. @@ -101,9 +99,6 @@ class RBF //! Modify the output parameter. OutputDataType& OutputParameter() { return outputParameter; } //! Get the parameters. - OutputDataType const& Parameters() const { return weights; } - //! Modify the parameters. - OutputDataType& Parameters() { return weights; } //! Get the input parameter. InputDataType const& InputParameter() const { return inputParameter; } @@ -121,9 +116,6 @@ class RBF //! Modify the delta. OutputDataType& Delta() { return delta; } - //! Modify the bias weights of the layer. - arma::mat& Sigmas() { return sigmas; } - /** * Serialize the layer. */ @@ -149,9 +141,6 @@ class RBF //! Locally-stored the output distances of the shape. OutputDataType distances; - //! Locally-stored weight object. - OutputDataType weights; - //! Locally-stored reset parameter used to initialize the layer once. bool reset; @@ -161,8 +150,6 @@ class RBF //! Locally-stored number of output units. size_t outSize; - //! Locally-stored regularizer object. - RegularizerType regularizer; }; // class RBF } // namespace ann diff --git a/src/mlpack/methods/ann/layer/radial_basis_function_impl.hpp b/src/mlpack/methods/ann/layer/radial_basis_function_impl.hpp index 36cde0f0a7..90d2c4e73a 100644 --- a/src/mlpack/methods/ann/layer/radial_basis_function_impl.hpp +++ b/src/mlpack/methods/ann/layer/radial_basis_function_impl.hpp @@ -17,9 +17,8 @@ namespace mlpack { namespace ann /** Artificial Neural Network. */ { -template -RBF::RBF() : +template +RBF::RBF() : inSize(0), outSize(0), reset(false) @@ -27,32 +26,26 @@ RBF::RBF() : // Nothing to do here. } -template -RBF::RBF( +template +RBF::RBF( const size_t inSize, const size_t outSize, - arma::mat& centres, - RegularizerType regularizer) : + arma::mat& centres) : inSize(inSize), outSize(outSize), centres(centres), - regularizer(regularizer), reset(false) { - weights.set_size(outSize * inSize + outSize, 1); } -template -void RBF::Reset() +template +void RBF::Reset() { } -template +template template -void RBF::Forward( +void RBF::Forward( const arma::Mat& input, arma::Mat& output) { @@ -73,17 +66,12 @@ void RBF::Forward( 2), 0), 0.5).t(); } - sigmas = arma::mean(distances, 1); - arma::mat betas = 1 / 2 * arma::pow(sigmas, 2); - distances = arma::pow(distances, 2); - distances = distances.each_col() % betas; - output = arma::exp(-1 * distances); + output = distances; } -template +template template -void RBF::Backward( +void RBF::Backward( const arma::Mat& /* input */, const arma::Mat& gy, arma::Mat& g) @@ -91,21 +79,15 @@ void RBF::Backward( g = centres.t() * gy; } -template +template template -void RBF::serialize( +void RBF::serialize( Archive& ar, const unsigned int /* version */) { ar & BOOST_SERIALIZATION_NVP(distances); ar & BOOST_SERIALIZATION_NVP(sigmas); ar & BOOST_SERIALIZATION_NVP(centres); - - // This is inefficient, but we have to allocate this memory so that - // WeightSetVisitor gets the right size. - if (Archive::is_loading::value) - weights.set_size(outSize * inSize + outSize, 1); } } // namespace ann diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index e719a6a0a7..372a5f6373 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -687,7 +687,7 @@ BOOST_AUTO_TEST_CASE(RBFNetworkTest) model.Add >(10, 2); model1.Add >(); // Vanilla neural net with logistic activation function. - TestNetwork<>(model1, dataset, labels, dataset, labels, 10, 0.2); + TestNetwork<>(model1, dataset, labels, dataset, labels, 10, 0.3); } BOOST_AUTO_TEST_SUITE_END();