ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 20 Nov 2017 14:09:04 -0600Scatter search optimisationhttp://ask.sagemath.org/question/39655/scatter-search-optimisation/Hi all,
Does Sage offer something similar to the scatter search algorithms (Global Optimisation Toolbox) in Matlab? I looked through Sage documentation and through this forum but couldn't find a comprehensive answer.
Bit of background: I have a model with 6 parameters that together govern two probability distributions, looking to minimise error between calculated output and a target consisting of 4 variables. The probability distribution interacts with 1,000 - 100,000 data points to give a yes/no decision for each so they can be included/excluded in a sub-sample of data.
Excel (Evolutionary Solver) runs this in 1 - 24hr (admittedly on a 64Gb ram/12 core work station) so understandably I would like to speed this up. Python looks a sensible way to go, which brought me to Sage, but I got stuck trying to find out what optimisation algorithms are available.
Sat, 18 Nov 2017 16:46:44 -0600http://ask.sagemath.org/question/39655/scatter-search-optimisation/Answer by SloopJohnB for <p>Hi all, </p>
<p>Does Sage offer something similar to the scatter search algorithms (Global Optimisation Toolbox) in Matlab? I looked through Sage documentation and through this forum but couldn't find a comprehensive answer. </p>
<p>Bit of background: I have a model with 6 parameters that together govern two probability distributions, looking to minimise error between calculated output and a target consisting of 4 variables. The probability distribution interacts with 1,000 - 100,000 data points to give a yes/no decision for each so they can be included/excluded in a sub-sample of data. </p>
<p>Excel (Evolutionary Solver) runs this in 1 - 24hr (admittedly on a 64Gb ram/12 core work station) so understandably I would like to speed this up. Python looks a sensible way to go, which brought me to Sage, but I got stuck trying to find out what optimisation algorithms are available. </p>
http://ask.sagemath.org/question/39655/scatter-search-optimisation/?answer=39680#post-id-39680Thanks, exactly what I was hoping for! I thought there must be loads of optimisation programmes but clearly looked in the wrong place.Mon, 20 Nov 2017 14:09:04 -0600http://ask.sagemath.org/question/39655/scatter-search-optimisation/?answer=39680#post-id-39680Answer by mforets for <p>Hi all, </p>
<p>Does Sage offer something similar to the scatter search algorithms (Global Optimisation Toolbox) in Matlab? I looked through Sage documentation and through this forum but couldn't find a comprehensive answer. </p>
<p>Bit of background: I have a model with 6 parameters that together govern two probability distributions, looking to minimise error between calculated output and a target consisting of 4 variables. The probability distribution interacts with 1,000 - 100,000 data points to give a yes/no decision for each so they can be included/excluded in a sub-sample of data. </p>
<p>Excel (Evolutionary Solver) runs this in 1 - 24hr (admittedly on a 64Gb ram/12 core work station) so understandably I would like to speed this up. Python looks a sensible way to go, which brought me to Sage, but I got stuck trying to find out what optimisation algorithms are available. </p>
http://ask.sagemath.org/question/39655/scatter-search-optimisation/?answer=39666#post-id-39666> what optimisation algorithms are available.
Check those provided by [SciPy's optimization and root finding library](https://docs.scipy.org/doc/scipy/reference/optimize.html). All of them are available through the Sage interpreter by calling the appropriate `scipy.optimize` function. For example, the [basin-hopping algorithm](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.basinhopping.html#scipy.optimize.basinhopping) finds the global minimum of a scalar function:
sage: import numpy as np
sage: from scipy.optimize import basinhopping
sage: func = lambda x: np.cos(14.5 * x - 0.3) + (x + 0.2) * x
sage: x0=[1.]
sage: minimizer_kwargs = {"method": "BFGS"}
sage: ret = basinhopping(func, x0, minimizer_kwargs=minimizer_kwargs, niter=200)
fun: -1.0008761844426548
lowest_optimization_result: fun: -1.0008761844426548
...
In some (but not all) cases, Sage provides an interface to these algorithms, so that you can directly use Sage symbolic functions as arguments.
It is worth mentioning that "out there" you'll find dozens of Python libraries for mathematical optimization (*). Notice that standard Python packages can be installed with the terminal command
`$ sage --pip install --user package_name`
and if the installation goes well, it is available the next time you start Sage via `import package_name`.
---
(*) See eg.:
- [pymeigo](https://pypi.python.org/pypi/pymeigo), [docs](http://pythonhosted.org/pymeigo/)Sun, 19 Nov 2017 17:44:52 -0600http://ask.sagemath.org/question/39655/scatter-search-optimisation/?answer=39666#post-id-39666