Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/erikerlandson/gibbous
Convex optimization for java and scala, built on Apache Commons Math
https://github.com/erikerlandson/gibbous
commons-math constraint-programming convex-optimization convex-programming java linear-programming optimization optimization-algorithms quadratic-programming scala
Last synced: 3 months ago
JSON representation
Convex optimization for java and scala, built on Apache Commons Math
- Host: GitHub
- URL: https://github.com/erikerlandson/gibbous
- Owner: erikerlandson
- License: apache-2.0
- Created: 2018-05-02T14:18:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-07-16T23:33:44.000Z (over 3 years ago)
- Last Synced: 2024-07-01T17:13:53.814Z (7 months ago)
- Topics: commons-math, constraint-programming, convex-optimization, convex-programming, java, linear-programming, optimization, optimization-algorithms, quadratic-programming, scala
- Language: Java
- Homepage:
- Size: 5.49 MB
- Stars: 20
- Watchers: 4
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gibbous
Convex optimization built on Apache Commons MathImplementation 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.```scala
libraryDependencies ++= "com.manyangled" % "gibbous" % "0.3.0"
```### Examples
##### Minimize a convex function under constraints
```java
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
```java
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
```