Class QNMinimizer
- java.lang.Object
-
- opennlp.tools.ml.maxent.quasinewton.QNMinimizer
-
public class QNMinimizer extends Object
Implementation of L-BFGS which supports L1-, L2-regularization and Elastic Net for solving convex optimization problems.Usage example:
// Quadratic function f(x) = (x-1)^2 + 10 // f obtains its minimum value 10 at x = 1 Function f = new Function() { @Override public int getDimension() { return 1; } @Override public double valueAt(double[] x) { return StrictMath.pow(x[0]-1, 2) + 10; } @Override public double[] gradientAt(double[] x) { return new double[] { 2*(x[0]-1) }; } }; QNMinimizer minimizer = new QNMinimizer(); double[] x = minimizer.minimize(f); double min = f.valueAt(x);
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
QNMinimizer.Evaluator
Evaluate quality of training parameters.static class
QNMinimizer.L2RegFunction
L2-regularized objectiveFunction
.
-
Field Summary
Fields Modifier and Type Field Description static double
CONVERGE_TOLERANCE
static double
INITIAL_STEP_SIZE
static double
L1COST_DEFAULT
static double
L2COST_DEFAULT
static int
M_DEFAULT
static int
MAX_FCT_EVAL_DEFAULT
static double
MIN_STEP_SIZE
static int
NUM_ITERATIONS_DEFAULT
static double
REL_GRAD_NORM_TOL
-
Constructor Summary
Constructors Constructor Description QNMinimizer()
Initializes aQNMinimizer
with default parameters.QNMinimizer(double l1Cost, double l2Cost)
Initializes aQNMinimizer
.QNMinimizer(double l1Cost, double l2Cost, int iterations)
Initializes aQNMinimizer
.QNMinimizer(double l1Cost, double l2Cost, int iterations, int m, int maxFctEval)
Initializes aQNMinimizer
.QNMinimizer(double l1Cost, double l2Cost, int iterations, int m, int maxFctEval, boolean verbose)
Initializes aQNMinimizer
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description QNMinimizer.Evaluator
getEvaluator()
double[]
minimize(Function function)
Finds the parameters that minimize the objective function.void
setEvaluator(QNMinimizer.Evaluator evaluator)
-
-
-
Field Detail
-
CONVERGE_TOLERANCE
public static final double CONVERGE_TOLERANCE
- See Also:
- Constant Field Values
-
REL_GRAD_NORM_TOL
public static final double REL_GRAD_NORM_TOL
- See Also:
- Constant Field Values
-
INITIAL_STEP_SIZE
public static final double INITIAL_STEP_SIZE
- See Also:
- Constant Field Values
-
MIN_STEP_SIZE
public static final double MIN_STEP_SIZE
- See Also:
- Constant Field Values
-
L1COST_DEFAULT
public static final double L1COST_DEFAULT
- See Also:
- Constant Field Values
-
L2COST_DEFAULT
public static final double L2COST_DEFAULT
- See Also:
- Constant Field Values
-
NUM_ITERATIONS_DEFAULT
public static final int NUM_ITERATIONS_DEFAULT
- See Also:
- Constant Field Values
-
M_DEFAULT
public static final int M_DEFAULT
- See Also:
- Constant Field Values
-
MAX_FCT_EVAL_DEFAULT
public static final int MAX_FCT_EVAL_DEFAULT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
QNMinimizer
public QNMinimizer()
Initializes aQNMinimizer
with default parameters.
-
QNMinimizer
public QNMinimizer(double l1Cost, double l2Cost)
Initializes aQNMinimizer
.- Parameters:
l1Cost
- The L1-regularization cost.l2Cost
- The L2-regularization cost.
-
QNMinimizer
public QNMinimizer(double l1Cost, double l2Cost, int iterations)
Initializes aQNMinimizer
.- Parameters:
l1Cost
- The L1-regularization cost.l2Cost
- The L2-regularization cost.iterations
- The maximum number of iterations.
-
QNMinimizer
public QNMinimizer(double l1Cost, double l2Cost, int iterations, int m, int maxFctEval)
Initializes aQNMinimizer
.- Parameters:
l1Cost
- The L1-regularization cost.l2Cost
- The L2-regularization cost.iterations
- The maximum number of iterations.m
- The number of Hessian updates to store.maxFctEval
- The maximum number of function evaluations.
-
QNMinimizer
public QNMinimizer(double l1Cost, double l2Cost, int iterations, int m, int maxFctEval, boolean verbose)
Initializes aQNMinimizer
.- Parameters:
l1Cost
- The L1-regularization cost.l2Cost
- The L2-regularization cost.iterations
- The maximum number of iterations.m
- The number of Hessian updates to store.maxFctEval
- The maximum number of function evaluations.verbose
- Whether verbose output is printed, or not.
-
-
Method Detail
-
getEvaluator
public QNMinimizer.Evaluator getEvaluator()
-
setEvaluator
public void setEvaluator(QNMinimizer.Evaluator evaluator)
-
-