Skip to content

Instantly share code, notes, and snippets.

@arunreddy
Last active March 5, 2017 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arunreddy/4e67cb4a34a97d8f53f76fe673188214 to your computer and use it in GitHub Desktop.
Save arunreddy/4e67cb4a34a97d8f53f76fe673188214 to your computer and use it in GitHub Desktop.
Logistic Regression MLPACK.
// logistic_regression_test.cpp Lines[504-512]
// Very simple fake dataset.
arma::mat data("1 2 3;"
"1 2 3");
arma::Row<size_t> responses("1 1 0");
// Create a logistic regression object using a custom SGD object with a much
// smaller tolerance.
LogisticRegressionFunction<> lrf(data, responses, 0.001);
StandardSGD<LogisticRegressionFunction<>> sgd(lrf, 0.005, 500000, 1e-10);
LogisticRegression<> lr(sgd);
// Tried the following, but all of them resulted in errors.
LogisticRegression<StandardSGD> lr(sgd);
LogisticRegression<StandardSGD<>> lr(sgd);
LogisticRegression<StandardSGD<LogisticRegressionFunction>> lr(sgd);
//-----------------------------------------------------------------------
// Errors.
// With CLANG:
/home/arun/src/mlpack/mlpack/src/mlpack/tests/logistic_regression_test.cpp:512:24: error: no matching constructor for initialization of 'LogisticRegression<>'
LogisticRegression<> lr(sgd);
^ ~~~
/home/arun/src/mlpack/mlpack/src/mlpack/../mlpack/methods/logistic_regression/logistic_regression.hpp:34:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'StandardSGD<LogisticRegressionFunction<> >' (aka 'mlpack::optimization::SGD<mlpack::regression::LogisticRegressionFunction<arma::Mat<double> >, mlpack::optimization::EmptyUpdate>') to 'mlpack::regression::LogisticRegression<arma::Mat<double> >' for 1st argument
class LogisticRegression
^
/home/arun/src/mlpack/mlpack/src/mlpack/../mlpack/methods/logistic_regression/logistic_regression.hpp:34:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'StandardSGD<LogisticRegressionFunction<> >' (aka 'mlpack::optimization::SGD<mlpack::regression::LogisticRegressionFunction<arma::Mat<double> >, mlpack::optimization::EmptyUpdate>') to 'const mlpack::regression::LogisticRegression<arma::Mat<double> >' for 1st argument
/home/arun/src/mlpack/mlpack/src/mlpack/../mlpack/methods/logistic_regression/logistic_regression.hpp:87:3: note: candidate constructor not viable: no known conversion from 'StandardSGD<LogisticRegressionFunction<> >' (aka 'mlpack::optimization::SGD<mlpack::regression::LogisticRegressionFunction<arma::Mat<double> >, mlpack::optimization::EmptyUpdate>') to 'const size_t' (aka 'const unsigned long') for 1st argument
LogisticRegression(const size_t dimensionality = 0,
^
/home/arun/src/mlpack/mlpack/src/mlpack/../mlpack/methods/logistic_regression/logistic_regression.hpp:102:3: note: candidate template ignored: substitution failure : template template argument has different template parameters than its corresponding template template parameter
LogisticRegression(
^
/home/arun/src/mlpack/mlpack/src/mlpack/../mlpack/methods/logistic_regression/logistic_regression.hpp:52:3: note: candidate constructor not viable: requires at least 2 arguments, but 1 was provided
LogisticRegression(const MatType& predictors,
^
/home/arun/src/mlpack/mlpack/src/mlpack/../mlpack/methods/logistic_regression/logistic_regression.hpp:72:3: note: candidate constructor not viable: requires at least 3 arguments, but 1 was provided
LogisticRegression(const MatType& predictors,
^
//----------------------------------------------------
// With
LogisticRegression<StandardSGD<LogisticRegressionFunction<> >> lr(sgd);
/home/arun/src/mlpack/mlpack/src/mlpack/tests/logistic_regression_test.cpp:512:66: error: no matching constructor for initialization of 'LogisticRegression<StandardSGD<LogisticRegressionFunction<> > >' (aka 'LogisticRegression<mlpack::optimization::SGD<mlpack::regression::LogisticRegressionFunction<arma::Mat<double> >, mlpack::optimization::EmptyUpdate> >')
LogisticRegression<StandardSGD<LogisticRegressionFunction<> >> lr(sgd);
^ ~~~
/home/arun/src/mlpack/mlpack/src/mlpack/../mlpack/methods/logistic_regression/logistic_regression.hpp:34:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'StandardSGD<LogisticRegressionFunction<> >' (aka 'mlpack::optimization::SGD<mlpack::regression::LogisticRegressionFunction<arma::Mat<double> >, mlpack::optimization::EmptyUpdate>') to 'mlpack::regression::LogisticRegression<mlpack::optimization::SGD<mlpack::regression::LogisticRegressionFunction<arma::Mat<double> >, mlpack::optimization::EmptyUpdate> >' for 1st argument
class LogisticRegression
^
/home/arun/src/mlpack/mlpack/src/mlpack/../mlpack/methods/logistic_regression/logistic_regression.hpp:34:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'StandardSGD<LogisticRegressionFunction<> >' (aka 'mlpack::optimization::SGD<mlpack::regression::LogisticRegressionFunction<arma::Mat<double> >, mlpack::optimization::EmptyUpdate>') to 'const mlpack::regression::LogisticRegression<mlpack::optimization::SGD<mlpack::regression::LogisticRegressionFunction<arma::Mat<double> >, mlpack::optimization::EmptyUpdate> >' for 1st argument
/home/arun/src/mlpack/mlpack/src/mlpack/../mlpack/methods/logistic_regression/logistic_regression.hpp:87:3: note: candidate constructor not viable: no known conversion from 'StandardSGD<LogisticRegressionFunction<> >' (aka 'mlpack::optimization::SGD<mlpack::regression::LogisticRegressionFunction<arma::Mat<double> >, mlpack::optimization::EmptyUpdate>') to 'const size_t' (aka 'const unsigned long') for 1st argument
LogisticRegression(const size_t dimensionality = 0,
^
/home/arun/src/mlpack/mlpack/src/mlpack/../mlpack/methods/logistic_regression/logistic_regression.hpp:102:3: note: candidate template ignored: could not match 'LogisticRegressionFunction<mlpack::optimization::SGD<mlpack::regression::LogisticRegressionFunction<arma::Mat<double> >, mlpack::optimization::EmptyUpdate>>' against 'LogisticRegressionFunction<arma::Mat<double>>'
LogisticRegression(
^
/home/arun/src/mlpack/mlpack/src/mlpack/../mlpack/methods/logistic_regression/logistic_regression.hpp:52:3: note: candidate constructor not viable: requires at least 2 arguments, but 1 was provided
LogisticRegression(const MatType& predictors,
^
/home/arun/src/mlpack/mlpack/src/mlpack/../mlpack/methods/logistic_regression/logistic_regression.hpp:72:3: note: candidate constructor not viable: requires at least 3 arguments, but 1 was provided
LogisticRegression(const MatType& predictors,
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment