Update RBF<> layer so tests pass.

This commit is contained in:
Ryan Curtin
2021-07-23 16:43:46 -04:00
parent 927fabff8a
commit e3f4654a8a
7 changed files with 18 additions and 12 deletions
+1 -1
View File
@@ -58,7 +58,7 @@
//#include <mlpack/methods/ann/layer/padding.hpp>
//#include <mlpack/methods/ann/layer/parametric_relu.hpp>
//#include <mlpack/methods/ann/layer/positional_encoding.hpp>
//#include <mlpack/methods/ann/layer/radial_basis_function.hpp>
#include <mlpack/methods/ann/layer/radial_basis_function.hpp>
//#include <mlpack/methods/ann/layer/recurrent.hpp>
//#include <mlpack/methods/ann/layer/recurrent_attention.hpp>
//#include <mlpack/methods/ann/layer/reinforce_normal.hpp>
@@ -68,6 +68,9 @@ class RBF : public Layer<InputType, OutputType>
InputType& centres,
double betas = 0);
//! Clone the LinearType object. This handles polymorphism correctly.
RBF* Clone() const { return new RBF(*this); }
/**
* Ordinary feed forward pass of the radial basis function.
*
@@ -83,12 +86,12 @@ class RBF : public Layer<InputType, OutputType>
const OutputType& /* gy */,
OutputType& /* g */);
const std::vector<size_t>& OutputDimensions() const
void ComputeOutputDimensions()
{
std::vector<size_t> outputDimensions(inputDimensions.size(), 1);
this->outputDimensions = std::vector<size_t>(this->inputDimensions.size(),
1);
// This flattens the input.
outputDimensions[0] = outSize;
return outputDimensions;
this->outputDimensions[0] = outSize;
}
/**
@@ -2,7 +2,6 @@
* @file radial_basis_function_impl.hpp
* @author Himanshu Pathak
*
*
* 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
@@ -96,7 +95,7 @@ void RBF<InputType, OutputType, Activation>::serialize(
ar(CEREAL_NVP(distances));
ar(CEREAL_NVP(centres));
ar(CEREAL_NVP(betas);
ar(CEREAL_NVP(betas));
}
} // namespace ann
@@ -125,6 +125,7 @@
CEREAL_REGISTER_TYPE(mlpack::ann::NoisyLinearType<__VA_ARGS__>); \
CEREAL_REGISTER_TYPE(mlpack::ann::ConcatenateType<__VA_ARGS__>); \
CEREAL_REGISTER_TYPE(mlpack::ann::AddType<__VA_ARGS__>); \
CEREAL_REGISTER_TYPE(mlpack::ann::RBF<__VA_ARGS__>); \
// TODO: continue...
+1
View File
@@ -35,6 +35,7 @@ add_executable(mlpack_test
# facilities_test.cpp
# fastmks_test.cpp
feedforward_network_test.cpp
feedforward_network_2_test.cpp
# gan_test.cpp
# gmm_test.cpp
# hmm_test.cpp
+2 -1
View File
@@ -15,7 +15,8 @@
#include <mlpack/prereqs.hpp>
#include <mlpack/methods/ann/layer/layer.hpp>
#include <mlpack/methods/ann/layer/base_layer.hpp>
#include <mlpack/methods/ann/activation_functions/logistic_function.hpp>
namespace mlpack {
namespace ann {
@@ -14,6 +14,7 @@
#include <mlpack/core.hpp>
#include <mlpack/methods/ann/layer/layer.hpp>
#include <mlpack/methods/ann/layer/layer_types.hpp>
#include <mlpack/methods/ann/loss_functions/mean_squared_error.hpp>
#include <mlpack/methods/ann/ffn.hpp>
#include <mlpack/methods/kmeans/kmeans.hpp>
@@ -100,8 +101,8 @@ TEST_CASE("RBFNetworkTest", "[FeedForwardNetworkTest]")
kmeans.Cluster(trainData, 8, centroids);
FFN<MeanSquaredError<> > model;
model.Add<RBF<> >(trainData.n_rows, 8, centroids);
model.Add<Linear<> >(8, 3);
model.Add<RBF<> >(8, centroids);
model.Add<Linear>(3);
// RBFN neural net with MeanSquaredError.
TestNetwork<>(model, trainData, trainLabels1, testData, testLabels, 10, 0.1);
@@ -132,8 +133,8 @@ TEST_CASE("RBFNetworkTest", "[FeedForwardNetworkTest]")
kmeans1.Cluster(dataset, 140, centroids1);
FFN<MeanSquaredError<> > model1;
model1.Add<RBF<> >(dataset.n_rows, 140, centroids1, 4.1);
model1.Add<Linear<> >(140, 2);
model1.Add<RBF<> >(140, centroids1, 4.1);
model1.Add<Linear>(2);
// RBFN neural net with MeanSquaredError.
TestNetwork<>(model1, dataset, labels1, dataset, labels, 10, 0.1);