<commit_before>/**
 * @file logistic_regression_function.hpp
 * @author <NAME>
 *
 * Implementation of the logistic regression function, which is meant to be
 * optimized by a separate optimizer class that takes LogisticRegressionFunction
 * as its FunctionType class.
 */
#ifndef __MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_FUNCTION_HPP
#define __MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_FUNCTION_HPP

#include <mlpack/core.hpp>

namespace mlpack {
namespace regression {

/**
 * The log-likelihood function for the logistic regression objective function.
 * This is used by various mlpack optimizers to train a logistic regression
 * model.
 */
class LogisticRegressionFunction
{
 public:
  LogisticRegressionFunction(const arma::mat& predictors,
                             const arma::vec& responses,
                             const double lambda = 0);

  LogisticRegressionFunction(const arma::mat& predictors,
                             const arma::vec& responses,
                             const arma::mat& initialPoint,
                             const double lambda = 0);

  //! Return the initial point for the optimization.
  const arma::mat& InitialPoint() const { return initialPoint; }
  //! Modify the initial point for the optimization.
  arma::mat& InitialPoint() { return initialPoint; }

  //! Return the regularization parameter (lambda).
  const double& Lambda() const { return lambda; }
  //! Modify the regularization parameter (lambda).
  double& Lambda() { return lambda; }

  /**
   * Evaluate the logistic regression log-likelihood function with the given
   * parameters.  Note that if a point has 0 probability of being classified
   * directly with the given parameters, then Evaluate() will return nan (this
   * is kind of a corner case and should not happen for reasonable models).
   *
   * The optimum (minimum) of this function is 0.0, and occurs when each point
   * is classified correctly with very high probability.
   *
   * @param parameters Vector of logistic regression parameters.
   */
  double Evaluate(const arma::mat& parameters) const;

  /**
   * Evaluate the logistic regression log-likelihood function with the given
   * parameters, but using only one data point.  This is useful for optimizers
   * such as SGD, which require a separable objective function.  Note that if
   * the point has 0 probability of being classified correctly with the given
   * parameters, then Evaluate() will return nan (this is kind of a corner case
   * and should not happen for reasonable models).
   *
   * The optimum (minimum) of this function is 0.0, and occurs when the point is
   * classified correctly with very high probability.
   *
   * @param parameters Vector of logistic regression parameters.<commit_msg>Add function to get predictors and responses.<commit_after>/**
 * @file logistic_regression_function.hpp
 * @author <NAME>
 *
 * Implementation of the logistic regression function, which is meant to be
 * optimized by a separate optimizer class that takes LogisticRegressionFunction
 * as its FunctionType class.
 */
#ifndef __MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_FUNCTION_HPP
#define __MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_FUNCTION_HPP

#include <mlpack/core.hpp>

namespace mlpack {
namespace regression {

/**
 * The log-likelihood function for the logistic regression objective function.
 * This is used by various mlpack optimizers to train a logistic regression
 * model.
 */
class LogisticRegressionFunction
{
 public:
  LogisticRegressionFunction(const arma::mat& predictors,
                             const arma::vec& responses,
                             const double lambda = 0);

  LogisticRegressionFunction(const arma::mat& predictors,
                             const arma::vec& responses,
                             const arma::mat& initialPoint,
                             const double lambda = 0);

  //! Return the initial point for the optimization.
  const arma::mat& InitialPoint() const { return initialPoint; }
  //! Modify the initial point for the optimization.
  arma::mat& InitialPoint() { return initialPoint; }

  //! Return the regularization parameter (lambda).
  const double& Lambda() const { return lambda; }
  //! Modify the regularization parameter (lambda).
  double& Lambda() { return lambda; }

  //! Return the matrix of predictors.
  const arma::mat& Predictors() const { return predictors; }
  //! Return the vector of responses.
  const arma::vec& Responses() const { return responses; }

  /**
   * Evaluate the logistic regression log-likelihood function with the given
   * parameters.  Note that if a point has 0 probability of being classified
   * directly with the given parameters, then Evaluate() will return nan (this
   * is kind of a corner case and should not happen for reasonable models).
   *
   * The optimum (minimum) of this function is 0.0, and occurs when each point
   * is classified correctly with very high probability.
   *
   * @param parameters Vector of logistic regression parameters.
   */
  double Evaluate(const arma::mat& parameters) const;

  /**
   * Evaluate the logistic regression log-likelihood function with the given
   * parameters, but using only one data point.  This is useful for optimizers
   * such as SGD, which require a separable objective function.  Note that if
   * the point has 0 probability of being classified correctly with the given
   * parameters, then Evaluate() will return nan (this is kind of a corner case
   * and should not happen for reasonable models).
   *
   * The optimum (minimum) of this function is 0.0, and occurs when the point is
   * classified correctly with very high probability.
   *
   * @param parameters Vector of logistic regression parameters.
{'fraction_non_alphanumeric': 0.06821305841924398, 'fraction_numerical': 0.0027491408934707906, 'mean_word_length': 3.3278810408921933, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6722018', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1421, 'n_words': 627}