diff --git a/src/mlpack/methods/perceptron/perceptron.hpp b/src/mlpack/methods/perceptron/perceptron.hpp index 50eaa4d439..fd674c6144 100644 --- a/src/mlpack/methods/perceptron/perceptron.hpp +++ b/src/mlpack/methods/perceptron/perceptron.hpp @@ -98,7 +98,7 @@ private: */ void Train(const MatType& data, const arma::Row& labels, - const arma::rowvec& D); + const arma::rowvec& D = arma::rowvec()); }; } // namespace perceptron diff --git a/src/mlpack/methods/perceptron/perceptron_impl.hpp b/src/mlpack/methods/perceptron/perceptron_impl.hpp index 5b5cbc29ff..72b720ac60 100644 --- a/src/mlpack/methods/perceptron/perceptron_impl.hpp +++ b/src/mlpack/methods/perceptron/perceptron_impl.hpp @@ -37,10 +37,7 @@ Perceptron::Perceptron( // Start training. iter = iterations; - arma::rowvec D(data.n_cols); - D.fill(1.0);// giving equal weight to all the points. - - Train(data, labels, D); + Train(data, labels); } @@ -138,6 +135,8 @@ void Perceptron::Train( LearnPolicy LP; + const bool hasWeights = (D.n_elem > 0); + while ((i < iter) && (!converged)) { // This outer loop is for each iteration, and we use the 'converged' @@ -160,11 +159,16 @@ void Perceptron::Train( // Due to incorrect prediction, convergence set to false. converged = false; tempLabel = labels(0, j); + // Send maxIndexRow for knowing which weight to update, send j to know // the value of the vector to update it with. Send tempLabel to know // the correct class. - LP.UpdateWeights(data.col(j), weights, biases, maxIndexRow, tempLabel, - D(j)); + if (hasWeights) + LP.UpdateWeights(data.col(j), weights, biases, maxIndexRow, tempLabel, + D(j)); + else + LP.UpdateWeights(data.col(j), weights, biases, maxIndexRow, + tempLabel); } } }