[mlpack-svn] r16805 - in mlpack/trunk/src/mlpack: methods/perceptron methods/perceptron/learning_policies tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Jul 10 07:21:42 EDT 2014
Author: saxena.udit
Date: Thu Jul 10 07:21:42 2014
New Revision: 16805
Log:
Changes are part of perceptron code review, as discussed with Ryan
Modified:
mlpack/trunk/src/mlpack/methods/perceptron/learning_policies/simple_weight_update.hpp
mlpack/trunk/src/mlpack/methods/perceptron/perceptron_impl.hpp
mlpack/trunk/src/mlpack/tests/perceptron_test.cpp
Modified: mlpack/trunk/src/mlpack/methods/perceptron/learning_policies/simple_weight_update.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/perceptron/learning_policies/simple_weight_update.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/perceptron/learning_policies/simple_weight_update.hpp Thu Jul 10 07:21:42 2014
@@ -42,12 +42,11 @@
const size_t vectorIndex,
const size_t rowIndex)
{
- arma::mat instance = trainData.col(labelIndex);
-
- weightVectors.row(rowIndex) = weightVectors.row(rowIndex) - instance.t();
+ weightVectors.row(rowIndex) = weightVectors.row(rowIndex) -
+ trainData.col(labelIndex).t();
weightVectors.row(vectorIndex) = weightVectors.row(vectorIndex) +
- instance.t();
+ trainData.col(labelIndex).t();
}
};
Modified: mlpack/trunk/src/mlpack/methods/perceptron/perceptron_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/perceptron/perceptron_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/perceptron/perceptron_impl.hpp Thu Jul 10 07:21:42 2014
@@ -101,15 +101,12 @@
arma::mat tempLabelMat;
arma::uword maxIndexRow, maxIndexCol;
double maxVal;
- MatType testData = test;
-
- MatType zOnes(1, test.n_cols);
- zOnes.fill(1);
- testData.insert_rows(0, zOnes);
for (int i = 0; i < test.n_cols; i++)
{
- tempLabelMat = weightVectors * testData.col(i);
+ tempLabelMat = weightVectors.submat(0,1,weightVectors.n_rows-1,
+ weightVectors.n_cols-1) *
+ test.col(i) + weightVectors.col(0);
maxVal = tempLabelMat.max(maxIndexRow, maxIndexCol);
maxVal *= 2;
predictedLabels(0, i) = maxIndexRow;
Modified: mlpack/trunk/src/mlpack/tests/perceptron_test.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/tests/perceptron_test.cpp (original)
+++ mlpack/trunk/src/mlpack/tests/perceptron_test.cpp Thu Jul 10 07:21:42 2014
@@ -13,6 +13,7 @@
using namespace mlpack;
using namespace arma;
using namespace mlpack::perceptron;
+using namespace mlpack::distribution;
BOOST_AUTO_TEST_SUITE(PerceptronTest);
@@ -133,6 +134,7 @@
Mat<size_t> labels;
labels << 0 << 0 << 0 << 1 << 0 << 1 << 1 << 1
<< 0 << 0 << 0 << 1 << 0 << 1 << 1 << 1;
+ // labels.print("Here too.");
Perceptron<> p(trainData, labels.row(0), 1000);
mat testData;
More information about the mlpack-svn
mailing list