Brush C++ API
A flexible interpretable machine learning framework
Toggle main menu visibility
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
5
namespace
nl
=
nlohmann
;
6
namespace
br
=
Brush
;
7
8
using
stream_redirect
= py::call_guard<py::scoped_ostream_redirect, py::scoped_estream_redirect>;
9
10
void
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
)
27
.def_property(
"linear_complexity"
, &
br::Fitness::get_linear_complexity
, &
br::Fitness::set_linear_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
}
stream_redirect
py::call_guard< py::scoped_ostream_redirect, py::scoped_estream_redirect > stream_redirect
Definition
bind_engines.h:31
bind_fitness
void bind_fitness(py::module &m)
Definition
bind_fitness.cpp:10
fitness.h
module.h
Brush
< nsga2 selection operator for getting the front
Definition
bandit.cpp:3
nlohmann
Definition
utils.h:30
Brush::Fitness
Represents the fitness of an individual in the Brush namespace.
Definition
fitness.h:25
Brush::Fitness::clearValues
void clearValues()
Definition
fitness.h:151
Brush::Fitness::get_crowding_dist
float get_crowding_dist() const
Definition
fitness.h:98
Brush::Fitness::get_loss
float get_loss() const
Definition
fitness.h:64
Brush::Fitness::repr
std::string repr() const
Definition
fitness.h:212
Brush::Fitness::get_values
vector< float > get_values() const
Definition
fitness.h:121
Brush::Fitness::valid
bool valid() const
Definition
fitness.h:155
Brush::Fitness::set_linear_complexity
void set_linear_complexity(unsigned int new_lc)
Definition
fitness.h:80
Brush::Fitness::toString
std::string toString() const
Definition
fitness.h:199
Brush::Fitness::set_complexity
void set_complexity(unsigned int new_c)
Definition
fitness.h:75
Brush::Fitness::get_loss_v
float get_loss_v() const
Definition
fitness.h:68
Brush::Fitness::hash
size_t hash() const
Definition
fitness.h:110
Brush::Fitness::set_loss_v
void set_loss_v(float f_v)
Definition
fitness.h:67
Brush::Fitness::set_depth
void set_depth(unsigned int new_d)
Definition
fitness.h:85
Brush::Fitness::get_complexity
unsigned int get_complexity() const
Definition
fitness.h:77
Brush::Fitness::get_rank
size_t get_rank() const
Definition
fitness.h:95
Brush::Fitness::get_wvalues
vector< float > get_wvalues() const
Definition
fitness.h:124
Brush::Fitness::set_values
void set_values(vector< float > &v)
Definition
fitness.h:129
Brush::Fitness::set_rank
void set_rank(unsigned r)
Definition
fitness.h:94
Brush::Fitness::set_size
void set_size(unsigned int new_s)
Definition
fitness.h:71
Brush::Fitness::get_depth
unsigned int get_depth() const
Definition
fitness.h:86
Brush::Fitness::set_crowding_dist
void set_crowding_dist(float cd)
Definition
fitness.h:97
Brush::Fitness::dominates
int dominates(const Fitness &b) const
set obj vector given a string of objective names
Definition
fitness.cpp:55
Brush::Fitness::get_linear_complexity
unsigned int get_linear_complexity() const
Definition
fitness.h:82
Brush::Fitness::get_size
unsigned int get_size() const
Definition
fitness.h:72
Brush::Fitness::get_weights
vector< float > get_weights() const
Definition
fitness.h:118
Brush::Fitness::set_loss
void set_loss(float f)
Definition
fitness.h:63
src
bindings
bind_fitness.cpp
Generated by
1.17.0