The class NewtonUnconstrained implements an unconstrained Newton optimizer (see S.Boyd and L.Vandenberghe, "Convex Optimization", p. 487 for more details), and can be used to solve the following problem:

minimize x f ( x )

where f :  R n  R is convex and twice differentiable.

Code example

Consider the following quadratic problem:

minimize x 1 2 x T Px + q T x + r
where P = 0.01522 2 1.68 0.34 0.38 0.34 3.09 - 1.59 0.38 - 1.59 1.54 , q = - 0.018 - 0.025 - 0.01 and r = 0

It can be solved like this:
		
		RealMatrix PMatrix = new Array2DRowRealMatrix(new double[][] {
				{ 1.68, 0.34, 0.38 },
				{ 0.34, 3.09, -1.59 }, 
				{ 0.38, -1.59, 1.54 } });
		RealVector qVector = new ArrayRealVector(new double[] { 0.018, 0.025, 0.01 });

	    // Objective function.
		double theta = 0.01522;
		RealMatrix P = PMatrix.scalarMultiply(theta);
		RealVector q = qVector.mapMultiply(-1);
		PDQuadraticMultivariateRealFunction objectiveFunction = new PDQuadraticMultivariateRealFunction(P.getData(), q.toArray(), 0);
		
		OptimizationRequest or = new OptimizationRequest();
		or.setF0(objectiveFunction);
		or.setInitialPoint(new double[] {0.04, 0.50, 0.46});
		or.setTolerance(1.e-8);
		
	    //optimization
		NewtonUnconstrained opt = new NewtonUnconstrained();
		opt.setOptimizationRequest(or);
		opt.optimize(); 
		
This will give the solution (that we expect):
			    sol =  -  P  - 1     q   
				

Download test source bundle

Download the entire test source bundle from here.

Back to top

Reflow Maven skin maintained by Olivier Lamy.