<p>I am trying to run a LogisticRegression as follows:<br>
void logisticTest(Kmer& k, const arma::vec& y_train)<br>
{<br>
// Train classifier<br>
arma::mat x_train = k.get_x();<br>
mlpack::regression::LogisticRegression<> fit(x_train, y_train);<br>
...</p>
<p>where the get_x function of the Kmer class returns an arma::mat which is 1x3069 (the same dimension as y_train)</p>
<p>I include in the header:<br>
#include <br>
#include <br>
#include <br>
#include <br>
#include <br>
#include <br>
#include <br>
#include <br>
#include <br>
#include <br>
#include </p>
<p>// Boost headers<br>
#include <br>
#include </p>
<p>// Armadillo/mlpack headers<br>
#include <br>
#include </p>
<p>Code compiles with:<br>
g++ -Wall -g -O0 -std=c++11 -c -o kmer.o kmer.cpp<br>
g++ -Wall -g -O0 -std=c++11 -c -o Assoc.o Assoc.cpp<br>
g++ -Wall -g -O0 -std=c++11 Assoc.o kmer.o -lmlpack -larmadillo -lboost_program_options -lblas -llapack -lm -o assoc</p>
<p>x and y are vectors of 0 or 1 (as doubles). I've tried with a number of different x and y of this form.</p>
<p>When I run the code, I always get a segmentation fault, which valgrind suggests occurs in the mlpack::regression::LogisticRegressionFunction::Evaluate function, though I don't know where as the library is stripped of debugging information</p>
<p>==5679== Invalid read of size 8<br>
==5679== at 0x4EE7702: mlpack::regression::LogisticRegressionFunction::Evaluate(arma::Mat const&) const (in /usr/local/lib/libmlpack.so.1.0)<br>
==5679== by 0x439D09: mlpack::optimization::L_BFGSmlpack::regression::LogisticRegressionFunction::Evaluate(arma::Mat const&) (lbfgs_impl.hpp:83)<br>
==5679== by 0x437C26: mlpack::optimization::L_BFGSmlpack::regression::LogisticRegressionFunction::Optimize(arma::Mat&, unsigned long) (lbfgs_impl.hpp:364)<br>
==5679== by 0x435CAF: mlpack::optimization::L_BFGSmlpack::regression::LogisticRegressionFunction::Optimize(arma::Mat&) (lbfgs_impl.hpp:331)<br>
==5679== by 0x434A5A: mlpack::regression::LogisticRegressionmlpack::optimization::L_BFGS::LogisticRegression(arma::Mat const&, arma::Col const&, double) (logistic_regression_impl.hpp:37)<br>
==5679== by 0x431DE5: logisticTest(Kmer&, arma::Col const&) (pangwasAssoc.cpp:17)<br>
==5679== by 0x419FB5: main (pangwasMain.cpp:109)<br>
==5679== Address 0xfff001000 is not stack'd, malloc'd or (recently) free'd<br>
==5679== <br>
==5679== <br>
==5679== Process terminating with default action of signal 11 (SIGSEGV)<br>
==5679== Access not within mapped region at address 0xFFF001000<br>
==5679== at 0x4EE7702: mlpack::regression::LogisticRegressionFunction::Evaluate(arma::Mat const&) const (in /usr/local/lib/libmlpack.so.1.0)<br>
==5679== by 0x439D09: mlpack::optimization::L_BFGSmlpack::regression::LogisticRegressionFunction::Evaluate(arma::Mat const&) (lbfgs_impl.hpp:83)<br>
==5679== by 0x437C26: mlpack::optimization::L_BFGSmlpack::regression::LogisticRegressionFunction::Optimize(arma::Mat&, unsigned long) (lbfgs_impl.hpp:364)<br>
==5679== by 0x435CAF: mlpack::optimization::L_BFGSmlpack::regression::LogisticRegressionFunction::Optimize(arma::Mat&) (lbfgs_impl.hpp:331)<br>
==5679== by 0x434A5A: mlpack::regression::LogisticRegressionmlpack::optimization::L_BFGS::LogisticRegression(arma::Mat const&, arma::Col const&, double) (logistic_regression_impl.hpp:37)<br>
==5679== by 0x431DE5: logisticTest(Kmer&, arma::Col const&) (Assoc.cpp:17)<br>
==5679== by 0x419FB5: main (Main.cpp:109)</p>
<p>Before this error, I also get a few of the form:<br>
==5679== Conditional jump or move depends on uninitialised value(s)<br>
==5679== at 0x58B68EF: log (w_log.c:30)<br>
==5679== by 0x4EE770B: mlpack::regression::LogisticRegressionFunction::Evaluate(arma::Mat const&) const (in /usr/local/lib/libmlpack.so.1.0)</p>
<p>However, when I run the LogisticRegression binary from mlpack using the same x and y vectors printed as csv files it works just fine:<br>
logistic_regression --input_file x.vec.csv --input_responses y.vec.csv --output_file logit.txt -v<br>
[INFO ] Loading 'x.vec.csv' as CSV data. Size is 1 x 3069.<br>
[INFO ] Loading 'y.vec.csv' as CSV data. Size is 1 x 3069.<br>
[INFO ] Training model with L-BFGS optimizer.<br>
[INFO ] LogisticRegression::LogisticRegression(): final objective of trained model is 2030.33.<br>
[INFO ] Saving model to 'logit.txt'.<br>
[INFO ] Saving raw ASCII formatted data to 'logit.txt'.<br>
[INFO ] <br>
[INFO ] Execution parameters:<br>
[INFO ] decision_boundary: 0.5<br>
[INFO ] help: false<br>
[INFO ] info: ""<br>
[INFO ] input_file: x.vec.csv<br>
[INFO ] input_responses: y.vec.csv<br>
[INFO ] lambda: 0<br>
[INFO ] max_iterations: 0<br>
[INFO ] model_file: ""<br>
[INFO ] optimizer: lbfgs<br>
[INFO ] output_file: logit.txt<br>
[INFO ] output_predictions: predictions.csv<br>
[INFO ] step_size: 0.01<br>
[INFO ] test_file: ""<br>
[INFO ] tolerance: 1e-10<br>
[INFO ] verbose: true<br>
[INFO ] version: false<br>
[INFO ] <br>
[INFO ] Program timers:<br>
[INFO ] loading_data: 0.006700s<br>
[INFO ] logistic_regression_optimization: 0.067037s<br>
[INFO ] saving_data: 0.010786s<br>
[INFO ] total_time: 0.088893s</p>
<p>Could anyone help me debug this? Have I used the API/some pointers incorrectly, or perhaps compiled incorrectly? This seems more likely than a bug in the function, given that the binary works ok<br>
Apologies if this is the wrong forum for this problem</p>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br>Reply to this email directly or <a href="https://github.com/mlpack/mlpack/issues/428">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFOXm53M-5AzelVttAwBN1zHAJoHdks5n6cQngaJpZM4D3Y7n.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
<link itemprop="url" href="https://github.com/mlpack/mlpack/issues/428"></link>
<meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>