[mlpack-svn] r10864 - mlpack/trunk/src/mlpack/methods/linear_regression
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Dec 16 15:29:45 EST 2011
Author: vlad321
Date: 2011-12-16 15:29:44 -0500 (Fri, 16 Dec 2011)
New Revision: 10864
Modified:
mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression.cpp
mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression_main.cpp
Log:
Formatting of /linear_regression
Modified: mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression.cpp 2011-12-16 20:14:10 UTC (rev 10863)
+++ mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression.cpp 2011-12-16 20:29:44 UTC (rev 10864)
@@ -21,15 +21,15 @@
// We store the number of rows of the predictors.
// Reminder: Armadillo stores the data transposed from how we think of it,
// that is, columns are actually rows (see: column major order).
- size_t n_cols = predictors.n_cols;
+ size_t nCols = predictors.n_cols;
// Here we add the row of ones to the predictors.
arma::rowvec ones;
- ones.ones(n_cols);
+ ones.ones(nCols);
predictors.insert_rows(0, ones);
// We set the parameters to the correct size and initialize them to zero.
- parameters.zeros(n_cols);
+ parameters.zeros(nCols);
// We compute the QR decomposition of the predictors.
// We transpose the predictors because they are in column major order.
@@ -56,21 +56,21 @@
void LinearRegression::Predict(const arma::mat& points, arma::vec& predictions)
{
// We get the number of columns and rows of the dataset.
- const size_t n_cols = points.n_cols;
- const size_t n_rows = points.n_rows;
+ const size_t nCols = points.n_cols;
+ const size_t nRows = points.n_rows;
// We want to be sure we have the correct number of dimensions in the dataset.
- Log::Assert(n_rows == parameters.n_rows - 1);
+ Log::Assert(nRows == parameters.n_rows - 1);
- predictions.zeros(n_cols);
+ predictions.zeros(nCols);
// We set all the predictions to the intercept value initially.
predictions += parameters(0);
// Now we iterate through the dimensions of the data and parameters.
- for (size_t i = 1; i < n_rows + 1; ++i)
+ for (size_t i = 1; i < nRows + 1; ++i)
{
// Now we iterate through each row, or point, of the data.
- for (size_t j = 0; j < n_cols; ++j)
+ for (size_t j = 0; j < nCols; ++j)
{
// Increment each prediction value by x_i * a_i, or the next dimensional
// coefficient and x value.
Modified: mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression_main.cpp 2011-12-16 20:14:10 UTC (rev 10863)
+++ mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression_main.cpp 2011-12-16 20:29:44 UTC (rev 10864)
@@ -43,18 +43,18 @@
// Handle parameters
CLI::ParseCommandLine(argc, argv);
- const string train_name = CLI::GetParam<string>("input_file");
- const string test_name = CLI::GetParam<string>("test_file");
- const string response_name = CLI::GetParam<string>("input_responses");
- const string output_file = CLI::GetParam<string>("output_file");
- const string output_predictions = CLI::GetParam<string>("output_predictions");
+ const string trainName = CLI::GetParam<string>("input_file");
+ const string testName = CLI::GetParam<string>("test_file");
+ const string responseName = CLI::GetParam<string>("input_responses");
+ const string outputFile = CLI::GetParam<string>("outputFile");
+ const string outputPredictions = CLI::GetParam<string>("outputPredictions");
mat regressors;
mat responses;
- data::Load(train_name.c_str(), regressors, true);
+ data::Load(trainName.c_str(), regressors, true);
// Are the responses in a separate file?
- if (response_name == "")
+ if (responseName == "")
{
// The initial predictors for y, Nx1
responses = trans(regressors.row(regressors.n_rows - 1));
@@ -63,7 +63,7 @@
else
{
// The initial predictors for y, Nx1
- data::Load(response_name.c_str(), responses, true);
+ data::Load(responseName.c_str(), responses, true);
if (responses.n_rows == 1)
responses = trans(responses); // Probably loaded backwards, but that's ok.
@@ -79,13 +79,13 @@
LinearRegression lr(regressors, responses.unsafe_col(0));
// Save the parameters.
- data::Save(output_file.c_str(), lr.Parameters(), false);
+ data::Save(outputFile.c_str(), lr.Parameters(), false);
// Did we want to predict, too?
- if (test_name != "")
+ if (testName != "")
{
arma::mat points;
- data::Load(test_name.c_str(), points, true);
+ data::Load(testName.c_str(), points, true);
if (points.n_rows != regressors.n_rows)
Log::Fatal << "The test data must have the same number of columns as the "
@@ -95,6 +95,6 @@
lr.Predict(points, predictions);
// Save predictions.
- data::Save(output_predictions.c_str(), predictions, false);
+ data::Save(outputPredictions.c_str(), predictions, false);
}
}
More information about the mlpack-svn
mailing list