17 vector<char> dtypes = {
'f',
'f'};
19 MatrixXf data(value.size(), 2);
25 n.fit_normalize(data, dtypes);
31 float prob_change = std::abs(
slope(data.col(0).array() ,
32 data.col(1).array() ));
35 if (std::abs(prob_change)<1
e-4)
40 if (std::isnan(prob_change))
59 using T = std::decay_t<
decltype(
arg)>;
60 using Scalar =
typename T::Scalar;
61 constexpr bool weighted = std::is_same_v<Scalar, float>;
70 float prob_change = 1.0;
75 if (std::holds_alternative<ArrayXf>(value) &&
d.y.size()>0)
79 else if (std::holds_alternative<ArrayXi>(value))
84 auto tmp = std::get<ArrayXi>(value);
88 for(
int i = 0;
i <
tmp.size();
i++)
100 prob_change =
slopes.mean();
102 else if (std::holds_alternative<ArrayXb>(value))
109 auto msg = fmt::format(
"Brush coudn't calculate the initial weight of variable {}\n",
feature_name);
114 n.set_prob_change( prob_change );
129 if (
n.ret_type == ret_type) {
130 sum +=
n.get_prob_change();
160std::unordered_map<std::size_t, std::string>
ArgsName;
163 std::cout << fmt::format(
"{}\n", *
this) << std::flush;
176 bool use_all = user_ops.size() == 0;
198 if (
d.classification)
201 std::vector<float>
vec(
d.y.data(),
d.y.data() +
d.y.size());
219 std::make_index_sequence<NodeTypes::OpCount>());
258 auto spot = Tree.insert(Tree.begin(),
root);
269 tree<Node>::iterator
spot,
int max_d,
int max_size)
const
280 vector<tuple<TreeIter, DataType, int>> queue;
295 if (
root.get_is_weighted()==
true
300 for (
auto a :
root.arg_types)
311 while ( queue.size() +
s < max_size && queue.size() > 0)
326 if (
d >=
max_d ||
s >= max_size)
350 auto msg = fmt::format(
"Failed to sample operator AND terminal of data type {} during PTC2.\n",
DataTypeName[
t]);
362 for (
auto a :
n.arg_types)
378 if (
n.get_is_weighted()==
true
383 while (queue.size() > 0)
385 if (queue.size() == 0)
void bind_engine(py::module &m, string name)
holds variable type data.
#define HANDLE_ERROR_THROW(err)
float slope(const ArrayXf &x, const ArrayXf &y)
slope of x/y
< nsga2 selection operator for getting the front
Eigen::Array< bool, Eigen::Dynamic, 1 > ArrayXb
std::unordered_map< std::size_t, std::string > ArgsName
vector< Node > generate_terminals(const Dataset &d, const bool weights_init)
generate terminals from the dataset features and random constants.
T RandomDequeue(std::vector< T > &Q)
queue for make program
map< DataType, string > DataTypeName
Eigen::Array< int, Eigen::Dynamic, 1 > ArrayXi
float calc_initial_weight(const ArrayXf &value, const ArrayXf &y)
class holding the data for a node in a tree.
void set_prob_change(float w)
An individual program, a.k.a. model.
void print() const
prints the search space map.
Map< Node > node_map
Maps return types to argument types to node types.
unordered_map< DataType, vector< Node > > terminal_map
Maps return types to terminals.
void init(const Dataset &d, const unordered_map< string, float > &user_ops={}, bool weights_init=true)
Called by the constructor to initialize the search space.
RegressorProgram make_regressor(int max_d=0, int max_size=0, const Parameters ¶ms=Parameters())
Makes a random regressor program. Convenience wrapper for make_program.
unordered_map< DataType, vector< float > > terminal_weights
A map of weights corresponding to elements in terminal_map, used to weight probabilities of each term...
vector< float > get_weights() const
get weights of the return types
void GenerateNodeMap(const unordered_map< string, float > &user_ops, const vector< DataType > &unique_data_types, std::index_sequence< Is... >)
tree< Node > & PTC2(tree< Node > &Tree, tree< Node >::iterator root, int max_d, int max_size) const
std::optional< Node > sample_op(DataType ret) const
get an operator matching return type ret.
RepresenterProgram make_representer(int max_d=0, int max_size=0, const Parameters ¶ms=Parameters())
Makes a random representer program. Convenience wrapper for make_program.
Map< float > node_map_weights
A map of weights corresponding to elements in node_map, used to weight probabilities of each node bei...
MulticlassClassifierProgram make_multiclass_classifier(int max_d=0, int max_size=0, const Parameters ¶ms=Parameters())
Makes a random multiclass classifier program. Convenience wrapper for make_program.
std::optional< tree< Node > > sample_subtree(Node root, int max_d, int max_size) const
create a subtree with maximum size and depth restrictions and root of type root_type
vector< DataType > terminal_types
A vector storing the available return types of terminals.
bool has_solution_space(Iter start, Iter end) const
Takes iterators to weight vectors and checks if they have a non-empty solution space....
ClassifierProgram make_classifier(int max_d=0, int max_size=0, const Parameters ¶ms=Parameters())
Makes a random classifier program. Convenience wrapper for make_program.
std::optional< Node > sample_terminal(bool force_return=false) const
Get a random terminal.
normalizes a matrix to unit variance, 0 mean centered.