[mlpack-git] [mlpack] segmentation fault with LogisticRegression API (#428)

ttuethao notifications at github.com
Sun Jun 14 07:45:20 EDT 2015


I think the problem may be more complicated. I am using c++/g++ of mac (which actually mean clang). 

Consider the code:
<code>
cout<< X.n_cols<< "\t"<< Y.n_elem<< endl;
mlpack::regression::LogisticRegression<mlpack::optimization::L_BFGS> LG(X,Y,w,0.0001);
</code>
I also modified lmpack bound check in 'two' places:

1. In logistic_regression_impl.hpp:
<code>
template<template<typename> class OptimizerType>
LogisticRegression<OptimizerType>::LogisticRegression(
    const arma::mat& predictors,
    const arma::vec& responses,
    const arma::mat& initialPoint,
    const double lambda) :
    parameters(arma::zeros<arma::vec>(predictors.n_rows + 1)),
    lambda(lambda)
{
	//std::cout<< "Here OK!"<< std::endl;
	if (responses.n_elem != predictors.n_cols)
	Log::Fatal 	<< "LogisticRegression::LogisticRegression(): "
     			<< "predictors matrix has " << predictors.n_cols << " points, but "
        		<< "responses vector has " << responses.n_elem << " elements (should be"
        		<< " " << predictors.n_cols << ")!" << std::endl;
        		
  LogisticRegressionFunction errorFunction(predictors, responses, lambda);
  errorFunction.InitialPoint() = initialPoint;
  OptimizerType<LogisticRegressionFunction> optimizer(errorFunction);

  // Train the model.
  Timer::Start("logistic_regression_optimization");
  const double out = optimizer.Optimize(parameters);
  Timer::Stop("logistic_regression_optimization");

  Log::Info << "LogisticRegression::LogisticRegression(): final objective of "
      << "trained model is " << out << "." << std::endl;
}
</code>

And in logistic_regression_function.cpp (I added bound-check and renamed variables because I was thinking missing (*this) may be a problem for some compilers.)

<code>
LogisticRegressionFunction::LogisticRegressionFunction(
    const arma::mat& predictors_,
    const arma::vec& responses_,
    const double lambda_) :
    predictors(predictors_),
    responses(responses_),
    lambda(lambda_)
{
	std::cout<< responses_.n_elem <<"\t"<< predictors_.n_cols<< std::endl;
  initialPoint = arma::zeros<arma::mat>(predictors.n_rows + 1, 1);
  // Sanity check.
  if (responses.n_elem != predictors.n_cols)
	Log::Fatal 	<< "LogisticRegressionFunction::LogisticRegressionFunction(): "
     			<< "predictors matrix has " << predictors.n_cols << " points, but "
        		<< "responses vector has " << responses.n_elem << " elements (should be"
        		<< " " << predictors.n_cols << ")!" << std::endl;
}
</code>

The output reads:
<code>
5000	5000
1	0
</code>
Which means X, Y are passed to LogisticRegression properly, by not properly passed to LogisticRegressionFunction. I have not idea that can happen. Do you see any reason? (I ran the similar code in linux yesterday and found no problem, so it is likely because of the compiler clang?).


---
Reply to this email directly or view it on GitHub:
https://github.com/mlpack/mlpack/issues/428#issuecomment-111815633
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack-git/attachments/20150614/b8b69dc7/attachment.html>


More information about the mlpack-git mailing list