Brush C++ API
A flexible interpretable machine learning framework
Loading...
Searching...
No Matches
bind_fitness.cpp
Go to the documentation of this file.
1#include "module.h"
2
3#include "../ind/fitness.h"
4
5namespace nl = nlohmann;
6namespace br = Brush;
7
8using stream_redirect = py::call_guard<py::scoped_ostream_redirect, py::scoped_estream_redirect>;
9
10void bind_fitness(py::module& m)
11{
12 py::class_<br::Fitness>(m, "Fitness", py::dynamic_attr())
13 .def(py::init<>())
14 .def(py::init<const std::vector<float>&>(), "Constructor with weights")
15 .def_property("values", &br::Fitness::get_values, &br::Fitness::set_values)
16 .def_property_readonly("weights", &br::Fitness::get_weights)
17 .def_property_readonly("wvalues", &br::Fitness::get_wvalues)
18 .def("dominates", &br::Fitness::dominates)
19 .def("clearValues", &br::Fitness::clearValues, "Clear the weighted values vector")
20 .def_property("rank", &br::Fitness::get_rank, &br::Fitness::set_rank)
21 .def_property("loss", &br::Fitness::get_loss, &br::Fitness::set_loss)
22 .def_property("loss_v", &br::Fitness::get_loss_v, &br::Fitness::set_loss_v)
23 .def_property("crowding_dist", &br::Fitness::get_crowding_dist, &br::Fitness::set_crowding_dist)
24
25 .def("valid", &br::Fitness::valid, "Check if the fitness is valid")
26 .def("__hash__", &br::Fitness::hash, py::is_operator())
27 .def("__eq__", &br::Fitness::operator==, py::is_operator())
28 .def("__ne__", &br::Fitness::operator!=, py::is_operator())
29 .def("__lt__", &br::Fitness::operator<, py::is_operator())
30 .def("__gt__", &br::Fitness::operator>, py::is_operator())
31 .def("__le__", &br::Fitness::operator<=, py::is_operator())
32 .def("__ge__", &br::Fitness::operator>=, py::is_operator())
33 .def("__str__", &br::Fitness::toString, "String representation of the Fitness object")
34 .def("__repr__", &br::Fitness::repr, "Representation for debugging the Fitness object")
35 .def(py::pickle(
36 [](const br::Fitness &f) { // __getstate__
37 /* Return a tuple that fully encodes the state of the object */
38 // return py::make_tuple(p.value(), p.extra());
39 nl::json j = f;
40 return j;
41 },
42 [](nl::json j) { // __setstate__
43 br::Fitness f = j;
44 return f;
45 }
46 )
47 )
48 ;
49
50}
void bind_engine(py::module &m, string name)
py::call_guard< py::scoped_ostream_redirect, py::scoped_estream_redirect > stream_redirect
void bind_fitness(py::module &m)
< nsga2 selection operator for getting the front
Definition data.cpp:12
Represents the fitness of an individual in the Brush namespace.
Definition fitness.h:25