Giter Club home page Giter Club logo

gibbous's Introduction

gibbous

Convex optimization built on Apache Commons Math

Implementation of the Barrier Method from §11.3 of Convex Optimization, Boyd and Vandenberghe, Cambridge University Press, 2004

Documentation

Full API javadoc is available at: https://erikerlandson.github.io/gibbous/java/api/

Some examples are included below.

How to include gibbous in your project

gibbous is a java project, and so can be used either with java or scala.

Versions prior to gibbous 0.3.0 were published to bintray, which is no longer operative. It is now available through oss.sonatype.org

gibbous 0.3.0 is equivalent to 0.2.x, with the exception of now including "org.apache.commons" % "commons-math3" % "3.6.1" as an explicit dependency.

libraryDependencies ++= "com.manyangled" % "gibbous" % "0.3.0"

Examples

Minimize a convex function under constraints
import org.apache.commons.math3.optim.PointValuePair;
import org.apache.commons.math3.optim.InitialGuess;
import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction;

import com.manyangled.gibbous.optim.convex.*;

// create a convex objective function
QuadraticFunction q = new QuadraticFunction(
    new double[][] { { 1.0, 0.0 }, { 0.0, 1.0 } },
    new double[] { 0.0, 0.0 },
    0.0);

// optimize function q with an inequality constraint and an equality constraint,
// using the barrier method
BarrierOptimizer barrier = new BarrierOptimizer();
PointValuePair pvp = barrier.optimize(
    new ObjectiveFunction(q),
    new LinearInequalityConstraint(
        new double[][] { { -1.0, 0.0 } }, // constraint x > 1,
        new double[] { -1.0 }),
    new LinearEqualityConstraint(
        new double[][] { { 0.0, 1.0 } },  // constraint y = 1,
        new double[] { 1.0 }),
    new InitialGuess(new double[] { 10.0, 10.0 }));

double[] xmin = pvp.getFirst();  // { 1.0, 1.0 }
double vmin = pvp.getSecond();   // 1.0
Using a feasible point solver to get a feasible initial guess
import org.apache.commons.math3.optim.PointValuePair;
import org.apache.commons.math3.optim.InitialGuess;
import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction;

import com.manyangled.gibbous.optim.convex.*;

// create a convex objective function
QuadraticFunction q = new QuadraticFunction(
    new double[][] { { 1.0, 0.0 }, { 0.0, 1.0 } },
    new double[] { 0.0, 0.0 },
    0.0);

// Declare constraints separately to use for solving a feasible point
LinearInequalityConstraint ineqc = new LinearInequalityConstraint(
    new double[][] { { -1.0, 0.0 } }, // constraint x > 1,
    new double[] { -1.0 });
LinearEqualityConstraint eqc = new LinearEqualityConstraint(
    new double[][] { { 0.0, 1.0 } },  // constraint y = 1,
    new double[] { 1.0 });

// solve for a feasible point that satisfies the constraints
PointValuePair fpvp = ConvexOptimizer.feasiblePoint(ineqc, eqc);
// if not < 0, there is no feasible point
assert fpvp.getSecond() < 0.0;
double[] ig = fpvp.getFirst();

// optimize function q with the same contraints, using the feasible point
// for the initial guess
BarrierOptimizer barrier = new BarrierOptimizer();
PointValuePair pvp = barrier.optimize(
    new ObjectiveFunction(q),
    ineqc,
    eqc,
    new InitialGuess(ig));

double[] xmin = pvp.getFirst();  // { 1.0, 1.0 }
double vmin = pvp.getSecond();   // 1.0

gibbous's People

Contributors

erikerlandson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gibbous's Issues

make SVDSchurKKTSolver the default KKTSolver

This isn't urgent, but the SVD solver seems to work in more use cases than the Cholesky one, due to its robustness for singular or near-singular matrices. It ought to be the default.

Intermittent appearance of infinite loop

I think I have this localized to the delta-x vector becoming zero (the dual delta-nu vector is not converging to zero). I had convinced myself that this case should be handled by current logic in backtracking but it isn't.

LOL, another intermittent infinite loop

PR #6 fixed a bunch of infinite looping cases but I still managed to trigger some. It turns out that the delta-x vector can go arbitrarily long without ever converging in magnitude. I suspect these behaviors are specific to the code path for equality constraints, where the dual solution space allows for more unintuitive behaviors. However I'm installing convergence checks for both code paths.

Checking for converging objective function seems to be fixing this, but I am going to add some more brute-force randomized testing to try and smoke these out. If it's the solution I think it subsumes the delta-x check, and if so I am going to remove that.

feasible point solving has a logic error w.r.t. properties of smooth-max

Attempting to add some new constraints for erikerlandson/snowball#1 has turned up a bug in my feasible point algorithm. Specifically, the problem is that I designed this algorithm assuming that smooth-max preserved the location of minima over convex functions. That is to say, if you find the minimum of the maximum over some convex functions, and then find the minimum of the smooth-max over those functions, those two minima will have the same location. This isn't true, as this example with simple 1D functions shows (the green smooth-max curve has its minimum to the right of the corresponding minimum over the true max):
image

Under some circumstances, this discrepancy will cause the current algorithm to find its minimum outside the actual feasible region and so it will report failure on constraints that actually have a non-empty feasible region.

I have to re-think the way that the alpha parameter for smooth-max is currently being used, and update the feasible point algorithm.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.