Skip to content

Commit

Permalink
full rework (#14)
Browse files Browse the repository at this point in the history
* add osqp based backend

* fix osqp dep

* update osqp

* ditto

* ditto

* wrap unittests

* fix 32bit osqp usage

* add boxcqp

* fix imports

* fix boxcqp

* wrap unittests

* fix imports

* remove C support

* update deps

* update mir-optim

* wip

* fix meson

* remove osqp wrap

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* add debug commit

* wip

* cleanup

* clean readme

* wip

* wrap debug code
  • Loading branch information
9il authored Mar 21, 2020
1 parent db7fed7 commit e0186f2
Show file tree
Hide file tree
Showing 9 changed files with 1,046 additions and 1,276 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ build/lapack/
build/mir-random/
*.dll
x.txt
subprojects/*/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ branches:

script:
- dub test -c unittest-blas
- if [ "$DC" = "ldc2" ]; then rm -rf .dub && dub build -c blas --compiler=ldmd2 --build-mode=singleFile --build=better-c-release --force && g++ -std=c++1y -pthread -I./include examples/least_squares.cpp -L./ -lmir-optim -llapack -lblas && ./a.out; fi
# - if [ "$DC" = "ldc2" ]; then rm -rf .dub && dub build -c blas --compiler=ldmd2 --build-mode=singleFile --build=better-c-release --force && g++ -std=c++1y -pthread -I./include examples/least_squares.cpp -L./ -lmir-optim -llapack -lblas && ./a.out; fi
# - meson build -D with_test=true && cd build && ninja -j4 && ninja test -v && cd ..

addons:
Expand Down
78 changes: 5 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[![Gitter](https://img.shields.io/gitter/room/libmir/public.svg)](https://gitter.im/libmir/public)
[![Build Status](https://travis-ci.org/libmir/mir-optim.svg?branch=master)](https://travis-ci.org/libmir/mir-optim)
[![Dub downloads](https://img.shields.io/dub/dt/mir-optim.svg)](http://code.dlang.org/packages/mir-optim)
[![Dub downloads](https://img.shields.io/dub/dm/mir-optim.svg)](http://code.dlang.org/packages/mir-optim)
Expand All @@ -7,28 +6,22 @@

# mir-optim

Dlang Nonlinear Optimisers with external C API.

### Konwn bugs

- Random wrong results when `taskPool` is passed.
Dlang BetterC Nonlinear Optimisers.

### Algorithms

- Modified Levenberg-Marquardt Algorithm (Nonlinear Least Squares).
- Boxed Constrained Quadratic Problem Solver

See also [online documentation](https://mir-optim.dpldocs.info/mir.html).
See also [online documentation](https://mir-optim.dpldocs.info/mir.html) (deprecated?).

### Features

- Idiomatic BetterC library. See `examples/least_squares.cpp` for compilation details.
- C/C++ header
- Multithread C++ examples
- Tiny BetterC library size, <38KB
- Tiny BetterC library size
- Based on LAPACK
- Fast compilaiton speed. There are two (for `float` and `double`) precompiled algorithm instatiations. Generic API is a thin wrappers around them.
- Four APIs for any purpose:
* Extern C/C++ API
* Extern C API
* Powerfull high level generic D API
* Nothrow middle level generic D API
* Low level nongeneric D API
Expand All @@ -37,67 +30,6 @@ See also [online documentation](https://mir-optim.dpldocs.info/mir.html).

See [wiki: Link with CBLAS & LAPACK](https://github.com/libmir/mir-lapack/wiki/Link-with-CBLAS-&-LAPACK).

# Examples

### Least Squares. Analytical Jacobian.

```d
unittest
{
import mir.optim.least_squares;
import mir.ndslice.allocation: slice;
import mir.ndslice.slice: sliced;
import mir.blas: nrm2;
auto lm = LeastSquaresLM!double(2, 2);
lm.x[] = [100, 100]; // initial X
// argmin_x f_0(x)^^2 + f_1(x)^^2
lm.optimize!(
(x, y) // f(x)
{
y[0] = x[0];
y[1] = 2 - x[1];
},
(x, J) // J(x)
{
J[0, 0] = 1;
J[0, 1] = 0;
J[1, 0] = 0;
J[1, 1] = -1;
},
);
assert(nrm2((lm.x - [0, 2].sliced).slice) < 1e-8);
}
```

### Least Squares. Multithreaded Jacobian approximation.

Jacobian finite difference approximation computed in multiple threads.

```d
unittest
{
import mir.optim.least_squares;
import mir.ndslice.allocation: slice;
import mir.ndslice.slice: sliced;
import mir.blas: nrm2;
import std.parallelism: taskPool;
auto lm = LeastSquaresLM!double(2, 2);
lm.x[] = [-1.2, 1];
lm.optimize!(
(x, y) // Rosenbrock function
{
y[0] = 10 * (x[1] - x[0]^^2);
y[1] = 1 - x[0];
},
)(taskPool);
assert(nrm2((lm.x - [1, 1].sliced).slice) < 1e-8);
}
```

### Our sponsors

[<img src="https://raw.githubusercontent.com/libmir/mir-algorithm/master/images/symmetry.png" height="80" />](http://symmetryinvestments.com/) &nbsp; &nbsp; &nbsp; &nbsp;
Expand Down
9 changes: 8 additions & 1 deletion dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ description "Optimisation Framework"
copyright "Copyright © 2018, Kaleidic Associates and Symmetry Investments"
targetType "library"
license "BSL-1.0"
dependency "mir-lapack" version=">=1.0.3 <1.3.0"
dependency "mir-lapack" version="~>1.2.3"
dependency "mir-algorithm" version=">=3.7.19"

buildType "better-c-release" {
buildOptions "releaseMode" "inline" "noBoundsCheck"
Expand Down Expand Up @@ -79,31 +80,37 @@ configuration "zerolib" {
}

configuration "unittest-openblas" {
versions "mir_optim_test"
dependency "mir-random" version=">=1.0.0-beta"
subConfiguration "mir-lapack" "openblas"
}

configuration "unittest-threelib" {
versions "mir_optim_test"
dependency "mir-random" version=">=1.0.0-beta"
subConfiguration "mir-lapack" "threelib"
}

configuration "unittest-cblas" {
versions "mir_optim_test"
dependency "mir-random" version=">=1.0.0-beta"
subConfiguration "mir-lapack" "cblas"
}

configuration "unittest-blas" {
versions "mir_optim_test"
dependency "mir-random" version=">=1.0.0-beta"
subConfiguration "mir-lapack" "blas"
}

configuration "unittest-lapack" {
versions "mir_optim_test"
dependency "mir-random" version=">=1.0.0-beta"
subConfiguration "mir-lapack" "lapack"
}

configuration "unittest-mkl-sequential" {
versions "mir_optim_test"
dependency "mir-random" version=">=1.0.0-beta"
subConfiguration "mir-lapack" "mkl-sequential"
}
151 changes: 0 additions & 151 deletions examples/least_squares.cpp

This file was deleted.

Loading

0 comments on commit e0186f2

Please sign in to comment.