[mlpack-git] master: Minor style fixes. (f13428a)
gitdub at mlpack.org
gitdub at mlpack.org
Wed Mar 23 12:07:32 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/7199297dd05a1a8dbc6525bdd7fcd13559596e6b...11b4b5e99199a2f360eba220ed0abe183fdae410
>---------------------------------------------------------------
commit f13428ad89946e601d3f54abdcd98cfd5e22bd74
Author: marcus <marcus.edel at fu-berlin.de>
Date: Wed Mar 23 17:07:32 2016 +0100
Minor style fixes.
>---------------------------------------------------------------
f13428ad89946e601d3f54abdcd98cfd5e22bd74
src/mlpack/tests/feedforward_network_test.cpp | 258 +++++++++++++-------------
1 file changed, 130 insertions(+), 128 deletions(-)
diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp
index 47aba10..57b3fe9 100644
--- a/src/mlpack/tests/feedforward_network_test.cpp
+++ b/src/mlpack/tests/feedforward_network_test.cpp
@@ -1,6 +1,7 @@
/**
* @file feedforward_network_test.cpp
* @author Marcus Edel
+ * @author Palash Ahuja
*
* Tests the feed forward network.
*/
@@ -288,7 +289,8 @@ BOOST_AUTO_TEST_CASE(DropoutNetworkTest)
}
/**
- * Train and evaluate a DropConnect network(with a baselayer) with the specified structure.
+ * Train and evaluate a DropConnect network(with a baselayer) with the
+ * specified structure.
*/
template<
typename PerformanceFunction,
@@ -304,66 +306,71 @@ void BuildDropConnectNetwork(MatType& trainData,
const size_t maxEpochs,
const double classificationErrorThreshold)
{
-/*
-* Construct a feed forward network with trainData.n_rows input nodes,
-* hiddenLayerSize hidden nodes and trainLabels.n_rows output nodes. The
-* network struct that looks like:
-*
-* Input Hidden DropConnect Output
-* Layer Layer Layer Layer
-* +-----+ +-----+ +-----+ +-----+
-* | | | | | | | |
-* | +------>| +------>| +------>| |
-* | | +>| | | | | |
-* +-----+ | +--+--+ +-----+ +-----+
-* |
-* Bias |
-* Layer |
-* +-----+ |
-* | | |
-* | +-----+
-* | |
-* +-----+
-*
-*
-*/
-LinearLayer<> inputLayer(trainData.n_rows, hiddenLayerSize);
-BiasLayer<> biasLayer(hiddenLayerSize);
-BaseLayer<PerformanceFunction> hiddenLayer0;
-
-LinearLayer<> hiddenLayer1(hiddenLayerSize, trainLabels.n_rows);
-DropConnectLayer<decltype(hiddenLayer1)> dropConnectLayer0(hiddenLayer1);
-
-BaseLayer<PerformanceFunction> outputLayer;
-
-OutputLayerType classOutputLayer;
-
-auto modules = std::tie(inputLayer, biasLayer, hiddenLayer0,
- dropConnectLayer0, outputLayer);
-
-FFN<decltype(modules), decltype(classOutputLayer), RandomInitialization,
- PerformanceFunctionType> net(modules, classOutputLayer);
-RMSprop<decltype(net)> opt(net, 0.01, 0.88, 1e-8,
- maxEpochs * trainData.n_cols, 1e-18);
-net.Train(trainData, trainLabels, opt);
-MatType prediction;
-net.Predict(testData, prediction);
-
-size_t error = 0;
-for (size_t i = 0; i < testData.n_cols; i++)
-{
- if (arma::sum(arma::sum(
- arma::abs(prediction.col(i) - testLabels.col(i)))) == 0)
- {
- error++;
- }
-}
-double classificationError = 1 - double(error) / testData.n_cols;
-BOOST_REQUIRE_LE(classificationError, classificationErrorThreshold);
+ /*
+ * Construct a feed forward network with trainData.n_rows input nodes,
+ * hiddenLayerSize hidden nodes and trainLabels.n_rows output nodes. The
+ * network struct that looks like:
+ *
+ * Input Hidden DropConnect Output
+ * Layer Layer Layer Layer
+ * +-----+ +-----+ +-----+ +-----+
+ * | | | | | | | |
+ * | +------>| +------>| +------>| |
+ * | | +>| | | | | |
+ * +-----+ | +--+--+ +-----+ +-----+
+ * |
+ * Bias |
+ * Layer |
+ * +-----+ |
+ * | | |
+ * | +-----+
+ * | |
+ * +-----+
+ *
+ *
+ */
+ LinearLayer<> inputLayer(trainData.n_rows, hiddenLayerSize);
+ BiasLayer<> biasLayer(hiddenLayerSize);
+ BaseLayer<PerformanceFunction> hiddenLayer0;
+
+ LinearLayer<> hiddenLayer1(hiddenLayerSize, trainLabels.n_rows);
+ DropConnectLayer<decltype(hiddenLayer1)> dropConnectLayer0(hiddenLayer1);
+
+ BaseLayer<PerformanceFunction> outputLayer;
+
+ OutputLayerType classOutputLayer;
+
+ auto modules = std::tie(inputLayer, biasLayer, hiddenLayer0,
+ dropConnectLayer0, outputLayer);
+
+ FFN<decltype(modules), decltype(classOutputLayer), RandomInitialization,
+ PerformanceFunctionType> net(modules, classOutputLayer);
+
+ RMSprop<decltype(net)> opt(net, 0.01, 0.88, 1e-8,
+ maxEpochs * trainData.n_cols, 1e-18);
+
+ net.Train(trainData, trainLabels, opt);
+
+ MatType prediction;
+ net.Predict(testData, prediction);
+
+ size_t error = 0;
+ for (size_t i = 0; i < testData.n_cols; i++)
+ {
+ if (arma::sum(arma::sum(
+ arma::abs(prediction.col(i) - testLabels.col(i)))) == 0)
+ {
+ error++;
+ }
+ }
+
+ double classificationError = 1 - double(error) / testData.n_cols;
+ BOOST_REQUIRE_LE(classificationError, classificationErrorThreshold);
}
/**
- * Train and evaluate a DropConnect network(with a linearlayer) with the specified structure.
+ * Train and evaluate a DropConnect network(with a linearlayer) with the
+ * specified structure.
*/
template<
typename PerformanceFunction,
@@ -379,60 +386,64 @@ void BuildDropConnectNetworkLinear(MatType& trainData,
const size_t maxEpochs,
const double classificationErrorThreshold)
{
-/*
-* Construct a feed forward network with trainData.n_rows input nodes,
-* hiddenLayerSize hidden nodes and trainLabels.n_rows output nodes. The
-* network struct that looks like:
-*
-* Input Hidden DropConnect Output
-* Layer Layer Layer Layer
-* +-----+ +-----+ +-----+ +-----+
-* | | | | | | | |
-* | +------>| +------>| +------>| |
-* | | +>| | | | | |
-* +-----+ | +--+--+ +-----+ +-----+
-* |
-* Bias |
-* Layer |
-* +-----+ |
-* | | |
-* | +-----+
-* | |
-* +-----+
-*
-*
-*/
-LinearLayer<> inputLayer(trainData.n_rows, hiddenLayerSize);
-BiasLayer<> biasLayer(hiddenLayerSize);
-BaseLayer<PerformanceFunction> hiddenLayer0;
-const size_t number_of_rows = trainLabels.n_rows;
-DropConnectLayer<> dropConnectLayer0(hiddenLayerSize, number_of_rows);
-
-BaseLayer<PerformanceFunction> outputLayer;
-
-OutputLayerType classOutputLayer;
-auto modules = std::tie(inputLayer, biasLayer, hiddenLayer0,
- dropConnectLayer0, outputLayer);
-
-FFN<decltype(modules), decltype(classOutputLayer), RandomInitialization,
- PerformanceFunctionType> net(modules, classOutputLayer);
-RMSprop<decltype(net)> opt(net, 0.01, 0.88, 1e-8,
- maxEpochs * trainData.n_cols, 1e-18);
-net.Train(trainData, trainLabels, opt);
-MatType prediction;
-net.Predict(testData, prediction);
-
-size_t error = 0;
-for (size_t i = 0; i < testData.n_cols; i++)
-{
- if (arma::sum(arma::sum(
- arma::abs(prediction.col(i) - testLabels.col(i)))) == 0)
- {
- error++;
- }
-}
-double classificationError = 1 - double(error) / testData.n_cols;
-BOOST_REQUIRE_LE(classificationError, classificationErrorThreshold);
+ /*
+ * Construct a feed forward network with trainData.n_rows input nodes,
+ * hiddenLayerSize hidden nodes and trainLabels.n_rows output nodes. The
+ * network struct that looks like:
+ *
+ * Input Hidden DropConnect Output
+ * Layer Layer Layer Layer
+ * +-----+ +-----+ +-----+ +-----+
+ * | | | | | | | |
+ * | +------>| +------>| +------>| |
+ * | | +>| | | | | |
+ * +-----+ | +--+--+ +-----+ +-----+
+ * |
+ * Bias |
+ * Layer |
+ * +-----+ |
+ * | | |
+ * | +-----+
+ * | |
+ * +-----+
+ *
+ *
+ */
+ LinearLayer<> inputLayer(trainData.n_rows, hiddenLayerSize);
+ BiasLayer<> biasLayer(hiddenLayerSize);
+ BaseLayer<PerformanceFunction> hiddenLayer0;
+
+ DropConnectLayer<> dropConnectLayer0(hiddenLayerSize, trainLabels.n_rows);
+
+ BaseLayer<PerformanceFunction> outputLayer;
+
+ OutputLayerType classOutputLayer;
+ auto modules = std::tie(inputLayer, biasLayer, hiddenLayer0,
+ dropConnectLayer0, outputLayer);
+
+ FFN<decltype(modules), decltype(classOutputLayer), RandomInitialization,
+ PerformanceFunctionType> net(modules, classOutputLayer);
+
+ RMSprop<decltype(net)> opt(net, 0.01, 0.88, 1e-8,
+ maxEpochs * trainData.n_cols, 1e-18);
+
+ net.Train(trainData, trainLabels, opt);
+
+ MatType prediction;
+ net.Predict(testData, prediction);
+
+ size_t error = 0;
+ for (size_t i = 0; i < testData.n_cols; i++)
+ {
+ if (arma::sum(arma::sum(
+ arma::abs(prediction.col(i) - testLabels.col(i)))) == 0)
+ {
+ error++;
+ }
+ }
+
+ double classificationError = 1 - double(error) / testData.n_cols;
+ BOOST_REQUIRE_LE(classificationError, classificationErrorThreshold);
}
/**
* Train the dropconnect network on a larger dataset.
@@ -464,8 +475,8 @@ BOOST_AUTO_TEST_CASE(DropConnectNetworkTest)
(trainData, trainLabels, testData, testLabels, 4, 100, 0.1);
BuildDropConnectNetworkLinear<LogisticFunction,
- BinaryClassificationLayer,
- MeanSquaredErrorFunction>
+ BinaryClassificationLayer,
+ MeanSquaredErrorFunction>
(trainData, trainLabels, testData, testLabels, 4, 100, 0.1);
dataset.load("mnist_first250_training_4s_and_9s.arm");
@@ -479,24 +490,15 @@ BOOST_AUTO_TEST_CASE(DropConnectNetworkTest)
// Vanilla neural net with logistic activation function.
BuildDropConnectNetwork<LogisticFunction,
- BinaryClassificationLayer,
- MeanSquaredErrorFunction>
+ BinaryClassificationLayer,
+ MeanSquaredErrorFunction>
(dataset, labels, dataset, labels, 8, 30, 0.4);
BuildDropConnectNetworkLinear<LogisticFunction,
- BinaryClassificationLayer,
- MeanSquaredErrorFunction>
+ BinaryClassificationLayer,
+ MeanSquaredErrorFunction>
(dataset, labels, dataset, labels, 8, 30, 0.4);
-
- // Vanilla neural net with tanh activation function.
- BuildDropConnectNetwork<TanhFunction,
- BinaryClassificationLayer,
- MeanSquaredErrorFunction>
- (dataset, labels, dataset, labels, 8, 30, 0.4);
- BuildDropConnectNetworkLinear<TanhFunction,
- BinaryClassificationLayer,
- MeanSquaredErrorFunction>
- (dataset, labels, dataset, labels, 8, 30, 0.4);
}
+
BOOST_AUTO_TEST_SUITE_END();
More information about the mlpack-git
mailing list