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("crowding_dist", &br::Fitness::get_crowding_dist, &br::Fitness::set_crowding_dist)
22
23 .def_property("loss", &br::Fitness::get_loss, &br::Fitness::set_loss)
24 .def_property("loss_v", &br::Fitness::get_loss_v, &br::Fitness::set_loss_v)
25 .def_property("size", &br::Fitness::get_size, &br::Fitness::set_size)
26 .def_property("complexity", &br::Fitness::get_complexity, &br::Fitness::set_complexity)
28 .def_property("depth", &br::Fitness::get_depth, &br::Fitness::set_depth)
29
30 .def_property_readonly("prev_loss", &br::Fitness::get_loss)
31 .def_property_readonly("prev_loss_v", &br::Fitness::get_loss_v)
32 .def_property_readonly("prev_size", &br::Fitness::get_size)
33 .def_property_readonly("prev_complexity", &br::Fitness::get_complexity)
34 .def_property_readonly("prev_linear_complexity", &br::Fitness::get_linear_complexity)
35 .def_property_readonly("prev_depth", &br::Fitness::get_depth)
36
37 .def("valid", &br::Fitness::valid, "Check if the fitness is valid")
38 .def("__hash__", &br::Fitness::hash, py::is_operator())
39 .def("__eq__", &br::Fitness::operator==, py::is_operator())
40 .def("__ne__", &br::Fitness::operator!=, py::is_operator())
41 .def("__lt__", &br::Fitness::operator<, py::is_operator())
42 .def("__gt__", &br::Fitness::operator>, py::is_operator())
43 .def("__le__", &br::Fitness::operator<=, py::is_operator())
44 .def("__ge__", &br::Fitness::operator>=, py::is_operator())
45 .def("__str__", &br::Fitness::toString, "String representation of the Fitness object")
46 .def("__repr__", &br::Fitness::repr, "Representation for debugging the Fitness object")
47 .def(py::pickle(
48 [](const br::Fitness &f) { // __getstate__
49 /* Return a tuple that fully encodes the state of the object */
50 // return py::make_tuple(p.value(), p.extra());
51 nl::json j = f;
52 return j;
53 },
54 [](nl::json j) { // __setstate__
55 br::Fitness f = j;
56 return f;
57 }
58 )
59 )
60 ;
61
62}
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 bandit.cpp:4
Represents the fitness of an individual in the Brush namespace.
Definition fitness.h:25
void clearValues()
Definition fitness.h:156
float get_crowding_dist() const
Definition fitness.h:103
float get_loss() const
Definition fitness.h:65
std::string repr() const
Definition fitness.h:217
vector< float > get_values() const
Definition fitness.h:126
bool valid() const
Definition fitness.h:160
void set_linear_complexity(unsigned int new_lc)
Definition fitness.h:84
std::string toString() const
Definition fitness.h:204
void set_complexity(unsigned int new_c)
Definition fitness.h:78
float get_loss_v() const
Definition fitness.h:70
size_t hash() const
Definition fitness.h:115
void set_loss_v(float f_v)
Definition fitness.h:68
void set_depth(unsigned int new_d)
Definition fitness.h:90
unsigned int get_complexity() const
Definition fitness.h:81
size_t get_rank() const
Definition fitness.h:100
vector< float > get_wvalues() const
Definition fitness.h:129
void set_values(vector< float > &v)
Definition fitness.h:134
void set_rank(unsigned r)
Definition fitness.h:99
void set_size(unsigned int new_s)
Definition fitness.h:73
unsigned int get_depth() const
Definition fitness.h:92
void set_crowding_dist(float cd)
Definition fitness.h:102
int dominates(const Fitness &b) const
set obj vector given a string of objective names
Definition fitness.cpp:43
unsigned int get_linear_complexity() const
Definition fitness.h:87
unsigned int get_size() const
Definition fitness.h:75
vector< float > get_weights() const
Definition fitness.h:123
void set_loss(float f)
Definition fitness.h:63