Commit Graph

37 Commits

Author SHA1 Message Date
Roman Donchenko
f68b73f831 Merge pull request #1521 from nailbiter:optimCG 2013-10-29 16:14:32 +04:00
Ilya Lavrenov
35d9ce0c0c fixed warnings 2013-10-08 12:46:43 +04:00
Alex Leontiev
0324932fb3 Added the copyright statements
Added the copyrights missing in all files that required so.
2013-09-30 18:53:32 +08:00
Alex Leontiev
3ac3ba0415 Minor fixes
Fix failed builds that opencv's buildbot has got.
2013-09-28 22:33:13 +08:00
Alex Leontiev
891bcd8491 Finish implementing the Nonlinear Conjugate Gradient
Now everything is prepared for the pull request.
2013-09-28 15:20:45 +08:00
Alex Leontiev
581d454536 Refined interface for Conjugate Gradient
Some interface was refined (most notably, the method for returning
Hessian was removed and the method for getting gradient was added as
optional to base Solver::Function class) and basic code for
setters/getters was added. Now is the time for the real work on an
algorithm.
2013-09-22 00:27:00 +08:00
Alex Leontiev
eb1333d0a8 Initial commit for Conjugate Gradient method
Implementation is based on
http://www.cs.cmu.edu/~quake-papers/painless-conjugate-gradient.pdf

So far we only have basic interface and empty test. But it compiles at
least.
2013-09-20 15:12:48 +08:00
Alexander Alekhin
81ac97c6bd fix for broken debug builds (MSVS2010/2012) 2013-09-18 16:05:21 +04:00
Alex Leontiev
a29863ee7b Eliminate use of 32-bit floating pt type
Replace all "float" by "double" (64-bit) to avoid "lose precision"
warnings.
2013-09-10 13:53:26 +08:00
Alex Leontiev
1207cd132b Minor fixes
Fixed integer vs unsigned integer comparison in .cpp test source and
trailing whitespaces in source code
2013-09-10 13:53:26 +08:00
Alex Leontiev
11fa0651c6 Minor fixes
As the opencv's build-bot did not want to compile this revision, I had
to do some changes. In particular,
1) Removed unsigned int vs int comparisons, that were treated as errors
2) Removed unused variables and functions
3) Removed functions without previous declaration
4) Fixed whitespaces
2013-09-10 13:53:26 +08:00
Alex Leontiev
ccc71ac190 Primal-dual algorithm
This is an implementation of primal-dual algorithm, based on the C++
source code by Vadim Pisarevsky. It was extended to handle the denoising
based on multiple observations. It also contains documentation and
tests.
2013-09-10 13:53:26 +08:00
Roman Donchenko
d5aaab745f Merge pull request #1282 from nailbiter:optimDS 2013-09-09 18:10:13 +04:00
Roman Donchenko
18bb951574 Nuked the rest of the precomp.cpp files.
Consider this a part of merging #1357.
2013-09-02 19:53:45 +04:00
Alex Leontiev
af74ec6044 Minor fixes
In response to the pull request comments by Vadim Pisarevsky. In
particular, the following was done:
    *)cv::reduce use instead of custom code for calculating
per-coordinate sum
    *) naming style of private methods is made consisted with overall --
mixed-case style
    *) irrelevant create()'s were removed -- I did not know that copyTo()
method itself calls create
2013-08-30 21:37:27 +08:00
Alex Leontiev
f2fd0ad153 Fixed .rst indentation
This caused warnings.
2013-08-30 21:37:27 +08:00
Alex Leontiev
b92c88ddd1 Removed trailing spaces
Continuation of work done in previous commit.
2013-08-30 21:35:47 +08:00
Alex Leontiev
b1f029ccc5 Removed trailing spaces
This caused warnings.
2013-08-30 21:35:47 +08:00
Alex Leontiev
554e002747 Prepare Downhill Simplex for pull request
This is an implementation of so-called downhill simplex method
(https://en.wikipedia.org/wiki/Nelder%E2%80%93Mead_method)

Please, let me know if you have any comments, whoever you'd be.
2013-08-30 21:35:47 +08:00
Roman Donchenko
9b92545ce6 War on Whitespace, master edition: trailing spaces. 2013-08-27 13:57:24 +04:00
Alex Leontiev
3013ad6624 Minor fixes
Request to comments on pull request for simplex method. In particular
*) while(1) is replaced with for(;;)
*) if(true){...} constructions in tests are replaced with #if 1 ...
 #endif
2013-07-30 04:14:36 +03:00
Alex Leontiev
52b250f466 Minor fixes
Fixing failed build.
2013-07-25 14:30:20 +03:00
Alex Leontiev
c123974f42 Eliminated all the calls to std::find()
This is done by keeping indexToRow vector, that keeps the information,
opposite to those kept by N and B. That is, while N and B help to
determine which variable corresponds to given column in column-vector c
or row in matrix b, indexToRow helps to determine the corresponding
row/column for a given variable.

At this point, I'm waiting for comments from pull request reviewer and
not working on any upgrades. Comments are appreciated, as usual.
2013-07-20 15:14:02 +03:00
Alex Leontiev
33e7640fb0 Simplify printing procedures
Use opencv's print() procedure in place of my own procedures to output
matrices and std::vectors.

Interestingly enough, operator<< does not work for matrices, when called
from my .cpp files in src/ subfolder of the optim module, although it
works when called from tests and stand-alone programs, compiled with
opencv. I think, this requires investigation and, maybe, bug report.
2013-07-19 12:34:33 +03:00
Alex Leontiev
459c16ca99 Minor fixes
In request to the comments for the pull request.
2013-07-19 03:09:39 +03:00
Alex Leontiev
6db2596ca9 Convenience fixes
Attempting to fix issues pointed out by Vadim Pisarevsky during the pull
request review. In particular, the following things are done:
*) The mechanism of debug info printing is changed and made more
procedure-style than the previous macro-style
*) z in solveLP() is now returned as a column-vector
*) Func parameter of solveLP() is now allowed to be column-vector, in
which case it is understood to be the transpose of what we need
*) Func and Constr now can contain floats, not only doubles (in the
former case the conversion is done via convertTo())
*)different constructor to allocate space for z in solveLP() is used,
making the size of z more explicit (this is just a notation change, not
functional, both constructors are achieving the same goal)
*) (big) mat.hpp and iostream headers are moved to precomp-headers from
optim.hpp
2013-07-11 22:05:14 +03:00
Alex Leontiev
e9b432b1d9 Fixing the warnings
Fixed all of the warnings.
2013-07-11 14:43:48 +03:00
Alex Leontiev
6c9ae1100b Fixed the warnings
Fixed the code so to eliminate warnings related to shadowing and unused
parameters. In some settings, these warnings may be treated as an errors
and lead to failed build.

Suggested by Nikita Manovich.
2013-07-11 12:29:55 +03:00
Alex Leontiev
fe6a7e935d Fix qualifiers on aux functions for solveLP()
Change qualifiers on auxiliary functions (for solveLP() procedure) from
const (that does not have much sense) to static (that makes them
invisible for outside world and hopefully exacerbates optimization).
2013-07-11 09:52:13 +03:00
Alex Leontiev
ba537a95db Preparation for pull request
Additional cleaning for simplex method, removing the parts that are
currently unused. Removing developer's notes. Trying to reach production
level.
2013-07-11 09:31:10 +03:00
Alex Leontiev
a95650111f Cleaning the code of simplex method
In particular, the following things are done:
*) Consistent tabulation of 4 spaces is ensured
*) New function dprintf() is introduced, so now printing of the debug
information can be turned on/off via the ALEX_DEBUG macro
*) Removed solveLP_aux namespace
*) All auxiliary functions are declared as static
*) The return codes of solveLP() are encapsulated in enum.
2013-07-10 20:11:52 +03:00
Alex Leontiev
a4a5e98cc0 Non-optimized simplex algorithm.
This version is supposed to work on all problems (please, let me know if
this is not so), but is not optimized yet in terms of numerical
stability and performance. Bland's rule is implemented as well, so
algorithm is supposed to allow no cycling. Additional check for multiple
solutions is added (in case of multiple solutions algorithm returns an
appropriate return code of 1 and returns arbitrary optimal solution).
Finally, now we have 5 tests.

Before Thursday we have 4 directions that can be tackled in parallel:
*) Prepare the pull request!
*) Make the code more clear and readable (refactoring)
*) Wrap the core solveLP() procedure in OOP-style interface
*) Test solveLP on non-trivial tests (possibly test against
http://www.coin-or.org/Clp/)
2013-07-03 13:54:23 +03:00
Alex Leontiev
ddc0010e7d The first draft of simplex algorithm, simple tests.
What we have now corresponds to "formal simplex algorithm", described in
Cormen's "Intro to Algorithms". It will work *only* if the initial
problem has (0,0,0,...,0) as feasible solution (consequently, it will
work unpredictably if problem was unfeasible or did not have zero-vector as
feasible solution). Moreover, it might cycle.

TODO (first priority)
1. Implement initialize_simplex() procedure, that shall check for
feasibility and generate initial feasible solution. (in particular, code
should pass all 4 tests implemented at the moment)
2. Implement Bland's rule to avoid cycling.
3. Make the code more clear.
4. Implement several non-trivial tests (??) and check algorithm against
them. Debug if necessary.

TODO (second priority)
1. Concentrate on stability and speed (make difficult tests)
2013-06-28 15:28:57 +03:00
Alex Leontiev
b216c0940c Created skeleton for simplex method.
Added LPSolver class together with two nested classes: LPFunction and
LPConstraints. These represent function to be maximized and constraints
imposed respectively. They are implementations of interfaces Function
and Constraints respectively (latter ones are nested classes of Solver
interface, which is generic interface for all optimization algorithms to
be implemented within this project).

The next step is to implement the simplex algorithm! First, we shall
implement it for the case of constraints of the form Ax<=b and x>=0.
Then, we shall extend the sets of problems that can be handled by the
conversion to the one we've handled already. Finally, we shale
concentrate on numerical stability and efficiency.
2013-06-24 20:27:11 +03:00
Alex Leontiev
f41b8b90ff Blank module and first draft of solver API.
At this point we have a skeleton of a new module (optim) which can
barely compile properly (unlike previous commit). Besides, there is a
first draft of solver and lpsolver (linear optimization solver) in this
commit.
2013-06-20 14:54:09 +03:00
Alex Leontiev
f2afe64521 Starting implement simplex algorithm. 2013-06-17 18:16:30 +03:00
Alex Leontiev
47ce461d97 The initial commit for generic optimization
Generic optimization package for openCV project, will be developed
between the June and September of 2013. This work is funded by Google
Summer of Code 2013 project. This project is about
implementing several algorithms, that will find global maxima/minima of a
given function on a given domain subject to a given constraints.

All comments/suggestions are warmly appreciated and to be sent to
alozz1991@gmail.com (please, mention the word "openCV" in topic of
message, for I'm using the spam-filters)
2013-05-31 07:39:15 +03:00