[mlpack-git] master: Tabs to spaces. (b8dbd21)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:00:33 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40
>---------------------------------------------------------------
commit b8dbd21aedbfb8b5911037fa36efb09759f88026
Author: Ryan Curtin <ryan at ratml.org>
Date: Sat Sep 27 16:31:06 2014 +0000
Tabs to spaces.
>---------------------------------------------------------------
b8dbd21aedbfb8b5911037fa36efb09759f88026
.../linear_regression/linear_regression.cpp | 114 ++++++++++-----------
1 file changed, 57 insertions(+), 57 deletions(-)
diff --git a/src/mlpack/methods/linear_regression/linear_regression.cpp b/src/mlpack/methods/linear_regression/linear_regression.cpp
index 48b49af..753ea08 100644
--- a/src/mlpack/methods/linear_regression/linear_regression.cpp
+++ b/src/mlpack/methods/linear_regression/linear_regression.cpp
@@ -11,11 +11,11 @@ using namespace mlpack;
using namespace mlpack::regression;
LinearRegression::LinearRegression(const arma::mat& predictors,
- const arma::vec& responses,
- const double lambda,
- const bool intercept,
- const arma::vec& weights
- ) :
+ const arma::vec& responses,
+ const double lambda,
+ const bool intercept,
+ const arma::vec& weights
+ ) :
lambda(lambda),
intercept(intercept)
{
@@ -31,30 +31,30 @@ LinearRegression::LinearRegression(const arma::mat& predictors,
const size_t nCols = predictors.n_cols;
arma::mat p = predictors;
- arma::vec r = responses;
- // Here we add the row of ones to the predictors.
- // The intercept is not penalized. Add an "all ones" row to design and set
- // intercept = false to get a penalized intercept
- if(intercept)
- {
- p.insert_rows(0, arma::ones<arma::mat>(1,nCols));
- }
-
- if(weights.n_elem > 0)
- {
- p = p * diagmat(sqrt(weights));
+ arma::vec r = responses;
+ // Here we add the row of ones to the predictors.
+ // The intercept is not penalized. Add an "all ones" row to design and set
+ // intercept = false to get a penalized intercept
+ if(intercept)
+ {
+ p.insert_rows(0, arma::ones<arma::mat>(1,nCols));
+ }
+
+ if(weights.n_elem > 0)
+ {
+ p = p * diagmat(sqrt(weights));
r = sqrt(weights) % responses;
- }
+ }
if (lambda != 0.0)
{
// Add the identity matrix to the predictors (this is equivalent to ridge
// regression). See http://math.stackexchange.com/questions/299481/ for
// more information.
- p.insert_cols(nCols, predictors.n_rows);
+ p.insert_cols(nCols, predictors.n_rows);
p.submat(p.n_rows - predictors.n_rows, nCols, p.n_rows - 1, nCols +
- predictors.n_rows - 1) = sqrt(lambda) * arma::eye<arma::mat>(predictors.n_rows,
- predictors.n_rows);
+ predictors.n_rows - 1) = sqrt(lambda) * arma::eye<arma::mat>(predictors.n_rows,
+ predictors.n_rows);
}
// We compute the QR decomposition of the predictors.
@@ -73,7 +73,7 @@ LinearRegression::LinearRegression(const arma::mat& predictors,
else
{
// Copy responses into larger vector.
- r.insert_rows(nCols,p.n_cols - nCols);
+ r.insert_rows(nCols,p.n_cols - nCols);
arma::solve(parameters, R, arma::trans(Q) * r);
}
}
@@ -94,21 +94,21 @@ LinearRegression::LinearRegression(const LinearRegression& linearRegression) :
void LinearRegression::Predict(const arma::mat& points, arma::vec& predictions)
const
{
- if (intercept)
- {
- // We want to be sure we have the correct number of dimensions in the dataset.
+ if (intercept)
+ {
+ // We want to be sure we have the correct number of dimensions in the dataset.
Log::Assert(points.n_rows == parameters.n_rows-1);
- // Get the predictions, but this ignores the intercept value (parameters[0]).
- predictions = arma::trans(arma::trans(parameters.subvec(1, parameters.n_elem - 1)) * points);
- // Now add the intercept.
- predictions += parameters(0);
- }
- else
- {
- // We want to be sure we have the correct number of dimensions in the dataset.
+ // Get the predictions, but this ignores the intercept value (parameters[0]).
+ predictions = arma::trans(arma::trans(parameters.subvec(1, parameters.n_elem - 1)) * points);
+ // Now add the intercept.
+ predictions += parameters(0);
+ }
+ else
+ {
+ // We want to be sure we have the correct number of dimensions in the dataset.
Log::Assert(points.n_rows == parameters.n_rows);
- predictions = arma::trans(arma::trans(parameters) * points);
- }
+ predictions = arma::trans(arma::trans(parameters) * points);
+ }
}
@@ -122,28 +122,28 @@ double LinearRegression::ComputeError(const arma::mat& predictors,
// Calculate the differences between actual responses and predicted responses.
// We must also add the intercept (parameters(0)) to the predictions.
- arma::vec temp;
- if (intercept)
- {
- // Ensure that we have the correct number of dimensions in the dataset.
- if (nRows != parameters.n_rows - 1)
- {
- Log::Fatal << "The test data must have the same number of columns as the "
- "training file." << std::endl;
- }
- temp = responses - arma::trans( (arma::trans(parameters.subvec(1,
- parameters.n_elem - 1)) * predictors) + parameters(0));
- }
- else
- {
- // Ensure that we have the correct number of dimensions in the dataset.
- if (nRows != parameters.n_rows)
- {
- Log::Fatal << "The test data must have the same number of columns as the "
- "training file." << std::endl;
- }
- temp = responses - arma::trans((arma::trans(parameters) * predictors));
- }
+ arma::vec temp;
+ if (intercept)
+ {
+ // Ensure that we have the correct number of dimensions in the dataset.
+ if (nRows != parameters.n_rows - 1)
+ {
+ Log::Fatal << "The test data must have the same number of columns as the "
+ "training file." << std::endl;
+ }
+ temp = responses - arma::trans( (arma::trans(parameters.subvec(1,
+ parameters.n_elem - 1)) * predictors) + parameters(0));
+ }
+ else
+ {
+ // Ensure that we have the correct number of dimensions in the dataset.
+ if (nRows != parameters.n_rows)
+ {
+ Log::Fatal << "The test data must have the same number of columns as the "
+ "training file." << std::endl;
+ }
+ temp = responses - arma::trans((arma::trans(parameters) * predictors));
+ }
const double cost = arma::dot(temp, temp) / nCols;
return cost;
More information about the mlpack-git
mailing list