Adding callback parameters for Logistic Regression
This commit is contained in:
@@ -123,13 +123,16 @@ class LogisticRegression
|
||||
* parameters vector directly with Parameters() and modify it as desired.
|
||||
*
|
||||
* @tparam OptimizerType Type of optimizer to use to train the model.
|
||||
* @tparam CallbackTypes Types of Callback Functions.
|
||||
* @param predictors Input training variables.
|
||||
* @param responses Outputs results from input training variables.
|
||||
* @param callbacks Callback Functions.
|
||||
* @return The final objective of the trained model (NaN or Inf on error)
|
||||
*/
|
||||
template<typename OptimizerType = ens::L_BFGS>
|
||||
template<typename OptimizerType = ens::L_BFGS, typename... CallbackTypes>
|
||||
double Train(const MatType& predictors,
|
||||
const arma::Row<size_t>& responses);
|
||||
const arma::Row<size_t>& responses,
|
||||
CallbackTypes&&... callbacks);
|
||||
|
||||
/**
|
||||
* Train the LogisticRegression model with the given instantiated optimizer.
|
||||
@@ -143,15 +146,19 @@ class LogisticRegression
|
||||
* optimizer.Function().GetInitialPoint() to the current parameters vector,
|
||||
* accessible via Parameters().
|
||||
*
|
||||
* @tparam OptimizerType Type of optimizer to use to train the model.
|
||||
* @tparam CallbackTypes Types of Callback Functions.
|
||||
* @param predictors Input training variables.
|
||||
* @param responses Outputs results from input training variables.
|
||||
* @param optimizer Instantiated optimizer with instantiated error function.
|
||||
* @param callbacks Callback Functions.
|
||||
* @return The final objective of the trained model (NaN or Inf on error)
|
||||
*/
|
||||
template<typename OptimizerType>
|
||||
template<typename OptimizerType, typename... CallbackTypes>
|
||||
double Train(const MatType& predictors,
|
||||
const arma::Row<size_t>& responses,
|
||||
OptimizerType& optimizer);
|
||||
OptimizerType& optimizer,
|
||||
CallbackTypes&&... callbacks);
|
||||
|
||||
//! Return the parameters (the b vector).
|
||||
const arma::rowvec& Parameters() const { return parameters; }
|
||||
|
||||
@@ -67,20 +67,23 @@ LogisticRegression<MatType>::LogisticRegression(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
template<typename OptimizerType>
|
||||
double LogisticRegression<MatType>::Train(const MatType& predictors,
|
||||
const arma::Row<size_t>& responses)
|
||||
template<typename OptimizerType, typename... CallbackTypes>
|
||||
double LogisticRegression<MatType>::Train(
|
||||
const MatType& predictors,
|
||||
const arma::Row<size_t>& responses,
|
||||
CallbackTypes&&... callbacks)
|
||||
{
|
||||
OptimizerType optimizer;
|
||||
return Train(predictors, responses, optimizer);
|
||||
return Train(predictors, responses, optimizer, callbacks...);
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
template<typename OptimizerType>
|
||||
template<typename OptimizerType, typename... CallbackTypes>
|
||||
double LogisticRegression<MatType>::Train(
|
||||
const MatType& predictors,
|
||||
const arma::Row<size_t>& responses,
|
||||
OptimizerType& optimizer)
|
||||
OptimizerType& optimizer,
|
||||
CallbackTypes&&... callbacks)
|
||||
{
|
||||
LogisticRegressionFunction<MatType> errorFunction(predictors,
|
||||
responses,
|
||||
@@ -88,7 +91,7 @@ double LogisticRegression<MatType>::Train(
|
||||
errorFunction.InitialPoint() = parameters;
|
||||
|
||||
Timer::Start("logistic_regression_optimization");
|
||||
const double out = optimizer.Optimize(errorFunction, parameters);
|
||||
const double out = optimizer.Optimize(errorFunction, parameters, callbacks...);
|
||||
Timer::Stop("logistic_regression_optimization");
|
||||
|
||||
Log::Info << "LogisticRegression::LogisticRegression(): final objective of "
|
||||
|
||||
Reference in New Issue
Block a user