Commit a0bf244a authored by Jason Rhinelander's avatar Jason Rhinelander

Added eris.algorithms

This maps eris::single_peak_search, and also provides a std::nextafter
wrapper (since python's math class doesn't have one).
parent 0462706d
......@@ -81,6 +81,7 @@ endfunction()
add_pyeris_module(core)
add_pyeris_module(position)
add_pyeris_module(learning)
add_pyeris_module(algorithms)
# We configure setup.py twice: the first during cmake configuration, which handles things like the version,
......
#include "pyeris/common.hpp"
#include <cmath>
#include <pybind11/functional.h>
#include <eris/algorithms.hpp>
// Utility functions.The core eris classes: Simulation, SharedMember, Member, Agent, Good, Market, Bundle, Optimize
namespace pyeris {
PYBIND11_PLUGIN(algorithms) {
py::module m("eris.algorithms", "eris interface for Python -- various algorithms and utilities");
m.def("nextafter", (double (*)(double,double)) &std::nextafter, "from"_a, "to"_a, "Returns the next representable value of `from` in the direction of `to`");
m.def("single_peak_search", &eris::single_peak_search,
"f"_a, "left"_a, "right"_a, "tol_rel"_a = 1e-10, "tol_abs"_a = 1e-20,
"Performs a \"golden section search\" to find the maximum of a single-peaked function, "
"`f`, between two limits. `f` should be a function that takes a float and returns a "
"float. `left` and `right` should points on either side of the maximum of `f`. "
"`tol_rel` is the relative size of the search domain (i.e. `right-left`) at which to stop "
"iterating (iteration stops when either or these tolerances are met)");
return m.ptr();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment