2.3.3 solver.optimize()
optimezie()方法首先需要判断solver类中的optimizer
字段是否为空。
public void optimize() {
if (optimizer == null)
optimizer = getOptimizer();
optimizer.optimize();
}
如果为空则需要调用getOptimizer()
方法获取实例。
public ConvexOptimizer getOptimizer() {
if (optimizer != null)
return optimizer;
switch (conf.getOptimizationAlgo()) {
case LBFGS:
optimizer = new LBFGS(conf, stepFunction, listeners, model);
break;
case LINE_GRADIENT_DESCENT:
optimizer = new LineGradientDescent(conf, stepFunction, listeners, model);
break;
case CONJUGATE_GRADIENT:
optimizer = new ConjugateGradient(conf, stepFunction, listeners, model);
break;
case STOCHASTIC_GRADIENT_DESCENT:
optimizer = new StochasticGradientDescent(conf, stepFunction, listeners, model);
break;
default:
throw new IllegalStateException("No optimizer found");
}
return optimizer;
}
我们这里使用的优化算法是STOCHASTIC_GRADIENT_DESCENT
,StochasticGradientDescent
这个类继承自BaseOptimizer
。
构造方法的实例