本文整理汇总了Java中com.joptimizer.optimizers.OptimizationResponse类的典型用法代码示例。如果您正苦于以下问题:Java OptimizationResponse类的具体用法?Java OptimizationResponse怎么用?Java OptimizationResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OptimizationResponse类属于com.joptimizer.optimizers包,在下文中一共展示了OptimizationResponse类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: solve
import com.joptimizer.optimizers.OptimizationResponse; //导入依赖的package包/类
public Result solve(final Result kickStarter) {
// myOptimizationRequest.setInitialPoint(new double[] { 0.2, 0.2 });
final OptimizationRequestHandler tmpHandler = myRequest instanceof LPOptimizationRequest ? new LPPrimalDualMethod() : null;
if (myRequest instanceof LPOptimizationRequest) {
((LPOptimizationRequest) myRequest).setPresolvingDisabled(true);
}
DEFAULT.configure(myRequest, tmpHandler, myOptions);
final Optional<Configurator> optional = myOptions.getConfigurator(Configurator.class);
if (optional.isPresent()) {
optional.get().configure(myRequest, tmpHandler, myOptions);
}
// myOptimizer.setOptimizationRequest(myOptimizationRequest);
tmpHandler.setOptimizationRequest(myRequest);
try {
tmpHandler.optimize();
} catch (final JOptimizerException exception) {
exception.printStackTrace();
}
final OptimizationResponse response = tmpHandler.getOptimizationResponse();
final State retState = Optimisation.State.OPTIMAL;
// final double retValue = response.getValue();
final Access1D<Double> retSolution = Access1D.wrap(response.getSolution());
return new Optimisation.Result(retState, retSolution);
}
示例2: solveFeatureWeights
import com.joptimizer.optimizers.OptimizationResponse; //导入依赖的package包/类
/**
* FeatureWeight factory which solves the best weights given Feature Expectations calculated from
* the expert demonstrations and a history of Feature Expectations.
* @param expertExpectations Feature Expectations calculated from the expert demonstrations
* @param featureExpectations Feature History of feature expectations generated from past policies
* @return the best feature weights
*/
private static FeatureWeights solveFeatureWeights(
double[] expertExpectations, List<double[]> featureExpectations) {
// We are solving a Quadratic Programming Problem here, yay!
// Solve equation of form xT * P * x + qT * x + r
// Let x = {w0, w1, ... , wn, t}
int weightsSize = expertExpectations.length;
// The objective is to maximize t, or minimize -t
double[] qObjective = new double[weightsSize + 1];
qObjective[weightsSize] = -1;
LinearMultivariateRealFunction objectiveFunction =
new LinearMultivariateRealFunction( qObjective, 0);
// We set the requirement that all feature expectations generated have to be less than the expert
List<ConvexMultivariateRealFunction> expertBasedWeightConstraints =
new ArrayList<ConvexMultivariateRealFunction>();
// (1/2)xT * Pi * x + qiT + ri <= 0
// Equation (11) wT * uE >= wT * u(j) + t ===> (u(j) - uE)T * w + t <= 0
// Because x = {w0, w1, ... , wn, t}, we can set
// qi = {u(j)_1 - uE_1, ... , u(j)_n - uE_n, 1}
for (double[] expectations : featureExpectations) {
double[] difference = new double[weightsSize + 1];
for (int i = 0; i < expectations.length; ++i) {
difference[i] = expectations[i] - expertExpectations[i];
}
difference[weightsSize] = 1;
expertBasedWeightConstraints.add(new LinearMultivariateRealFunction(difference, 1));
}
// L2 norm of weights must be less than or equal to 1. So
// P = Identity, except for the last entry (which cancels t).
double[][] identityMatrix = Utils.createConstantDiagonalMatrix(weightsSize + 1, 1);
identityMatrix[weightsSize][weightsSize] = 0;
expertBasedWeightConstraints.add(new PSDQuadraticMultivariateRealFunction(identityMatrix, null, -0.5));
OptimizationRequest optimizationRequest = new OptimizationRequest();
optimizationRequest.setF0(objectiveFunction);
optimizationRequest.setFi(expertBasedWeightConstraints.toArray(
new ConvexMultivariateRealFunction[expertBasedWeightConstraints.size()]));
optimizationRequest.setCheckKKTSolutionAccuracy(false);
optimizationRequest.setTolerance(1.E-12);
optimizationRequest.setToleranceFeas(1.E-12);
JOptimizer optimizer = new JOptimizer();
optimizer.setOptimizationRequest(optimizationRequest);
try {
optimizer.optimize();
} catch (Exception e) {
System.out.println(e);
return null;
}
OptimizationResponse optimizationResponse = optimizer.getOptimizationResponse();
double[] solution = optimizationResponse.getSolution();
double[] weights = Arrays.copyOfRange(solution, 0, weightsSize);
double score = solution[weightsSize];
return new FeatureWeights(weights, score);
}