Simple Minimizer
This minimizer was designed to be brutally simple and extremely robust. The original aim was primarily multi-model image registration during the development of the pseudo-correlation image registration algorithm for online portal imaging and other applications. This means it works best on systems with clearly defined ("anatomical") axes that are largely independent of each other.
It uses a combination of bracketing and parabolic interpolation to get the job done. It is not designed for speed.
An understanding of the shape of your objective function is desirable. It is useful to map it on various sets of axes.
The axes you use to represent your problem are not in general independent: your objective will have diagonal "troughs" due to the ability of one axis to trade off against another.
In general you are not minimizing in a vector space, and if you are the scales on different axes are often wildly different. Scales on each axis can be set via setScale(nAxis, fScale) prior to minimization.
The value of the objective function should be strictly positive over the domain, and ideally around 1.0 near the minimum, where "around" means 1E-4 => 1E4 or so.
If local minima are a problem call .reseed() on your minimizer object
after recording the current minimum, set new starting points (or use
the one you've just found) and re-run. For very hard problems with a
lot of local minimia I've sometimes run this three or five times and looked
for a majority vote on the true minimum or a lowest value (which works
best depends on the scale of the noise on the objective function: if the
noise is smooth on the scale of the minimum lowest value works well, if
the noise is rough on the scale of the minimum majority of minima within
a small region works well.)
Version 2 has an alternative algorithm implemented in the adaptiveMinimize() method, which will try to work out what is the best ordering of axes to minimize on by looking at the depth of the bracketed minimum. It is still largely experimental.
Simple usage example:
from math import sqrt
from simple_minimizer import *
nDimension = 3
# objective function is a callable
class Test(object):
def __init__(self):
# place we are looking for
self.lstOrigin = [nI for nI in range(0,nDimension)]
def __call__(self, lstVertex):
# lstVertex is a list of floats giving location on axes
fSum = 0.0
for nI in range(0, nDimension):
fSum += (self.lstOrigin[nI]-lstVertex[nI])**2
fSum += 1.0 # keeping it positive and ~ 1
return sqrt(fSum/nDimension)
minimizer = SimpleMinimizer(nDimension)
test = Test()
minimizer.setObjective(test)
# nReason = -1 => failed to converge, 1 => best/second-best equal, 2 => ratio < 0.001, 3 => minimum scale
(nCount, vertex, nReason) = minimizer.minimize()
lstVertex = vertex.getVertex() # extract the list of floats from the vertex object
fValue = vertex.getValue() # the value of the objective function at the minimum
fError = sqrt(sum([(nI-lstVertex[nI])**2 for nI in range(0,nDimension)])/nDimension)
print(fError < 0.001)
print(nCount < 10)
print(lstVertex)
In a realistic cases the objective function will be ferociously complex. Some of mine have involved computing DRRs (digitially reconstructed radiograms from CT or MR data) on each call.
Release files for simple-minimizer 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| simple_minimizer-2.0.0.tar.gz | 9.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| simple_minimizer-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.7 kB
Release files / simple_minimizer-2.0.0.tar.gz
| Download URL | simple_minimizer-2.0.0.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f29b2cff8ed677a907d65b7e6ba9644a2b676f2d428530f02e7917de6df4e46
|
|
BLAKE2b-256 checksum How to use checksums |
046f751492da6494cb0c86d93dde62691a76a20096b04a4af69e8fa1b89be09b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.0
|
Release files / simple_minimizer-2.0.0-py3-none-any.whl
| Download URL | simple_minimizer-2.0.0-py3-none-any.whl |
|---|---|
| Size | 10.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cbc20b43a0643d1ffa6e1f044b5af1f3c566190904b7f5df535f7f2c82d0f5ad
|
|
BLAKE2b-256 checksum How to use checksums |
f5dad77e775de174f70f1856d9ade61030a62031d0f39d33da2f0e96832f8023
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.0
|