57 opt.reset(
new T(
j.get<T>()));
68struct std::hash<
std::vector<float>> {
70 std::size_t
seed =
v.size();
71 for (
const auto&
elem :
v) {
126 seed ^= std::hash<T>()(
v) + 0x9e3779b9 + (
seed<<6) + (
seed>>2);
135 HashValueImpl<Tuple, Index-1>::apply(
seed, tuple);
140 template <
class Tuple>
141 struct HashValueImpl<
Tuple,0>
150 template <
typename ...
TT>
151 struct hash<
std::tuple<TT...>>
157 HashValueImpl<std::tuple<
TT...> >::apply(
seed,
tt);
183std::string
ltrim(std::string
str,
const std::string&
chars =
"\t\n\v\f\r ");
185std::string
rtrim(std::string
str,
const std::string&
chars =
"\t\n\v\f\r ");
187std::string
trim(std::string
str,
const std::string&
chars =
"\t\n\v\f\r ");
190template<
typename V,
typename T>
194 return std::find(
v.begin(),
v.end(),
i) !=
v.end();
201template<
typename T,
typename Scalar=T::Scalar>
205 vector<Scalar>
x(
v.size());
206 x.assign(
v.data(),
v.data()+
v.size());
208 size_t n =
x.size()/2;
212 if (
x.size() % 2 == 0) {
228float skew(
const ArrayXf&
v);
234float covariance(
const ArrayXf&
x,
const ArrayXf& y);
237float slope(
const ArrayXf&
x,
const ArrayXf& y);
243float mad(
const ArrayXf&
x);
250 vector<size_t>
idx(
v.size());
251 std::iota(
idx.begin(),
idx.end(), 0);
257 [&
v](
size_t i1,
size_t i2) {return v[i1] < v[i2];});
262 [&
v](
size_t i1,
size_t i2) {return v[i1] > v[i2];});
276 explicit Timer(
bool run =
false);
280 std::chrono::duration<float>
Elapsed()
const;
282 template <
typename T,
typename Traits>
283 friend std::basic_ostream<T, Traits>&
operator<<(std::basic_ostream<T, Traits>&
out,
290 high_resolution_clock::time_point
_start;
302 for(
x = 0;
x <
w.size(); ++
x)
305 for(
x = 0;
x <
w.size(); ++
x)
306 w_new.push_back(exp(
w[
x])/sum);
321 void fit(MatrixXf&
X,
const vector<char>&
dt);
336 std::sort(
w.begin(),
w.end());
337 typename vector<T>::iterator
it;
338 it = std::unique(
w.begin(),
w.end());
339 w.resize(std::distance(
w.begin(),
it));
347 vector<T>
wv(
w.data(),
w.data()+
w.size());
355 vector<T>
wv(
w.data(),
w.data()+
w.size());
363 vector<T>
wv(
w.data(),
w.data()+
w.rows()*
w.cols());
371 std::stringstream ss;
446std::enable_if_t<std::is_scalar_v<T>, T>
460std::enable_if_t<std::is_base_of_v<Eigen::ArrayBase<T>, T>, T>
472 for (
int s = 1;
s <
order.size(); ++
s )
505 for (
int i = 0;
i <
mask.size(); ++
i)
522template<std::ranges::range T>
669template <
class Vector,
class T>
672 typename Vector::iterator
i = std::lower_bound(
v.begin(),
v.end(),
t);
673 if (
i ==
v.end() ||
t < *
i)
679template <
typename T, std::size_t... Indices>
681 return std::make_tuple(
v[Indices]...);
684template <std::
size_t N,
typename T>
690template<
typename R,
typename Arg,
typename...
Args>
694 switch (inputs.size())
698 std::execution::par_unseq,
699 inputs.at(0).begin(),
707 std::execution::par_unseq,
708 inputs.at(0).begin(),
710 inputs.at(1).begin(),
725template<
class T,
class U>
729 for (
const auto&
i :
idx)
737template<
typename K,
typename V>
740 for (
const auto&
kv : m)
741 r[
kv.second] =
kv.first;
749 size_t len =
v.size();
750 for (
const auto&
i :
v)
void bind_engine(py::module &m, string name)
std::chrono::duration< float > Elapsed() const
std::chrono::seconds seconds
std::chrono::high_resolution_clock high_resolution_clock
friend std::basic_ostream< T, Traits > & operator<<(std::basic_ostream< T, Traits > &out, const Timer &timer)
high_resolution_clock::time_point _start
#define HANDLE_ERROR_THROW(err)
float mean_square_corrcoef(const MatrixXf &X)
std::string ReplaceString(std::string subject, const std::string &search, const std::string &replace)
find and replace string
void print(T t)
prints comma delimited container contents.
static map< V, K > reverse_map(const map< K, V > &m)
Given a map from keys to values, creates a new map from values to keys.
R apply(const std::function< R(Args...)> &f, const vector< Arg > &inputs)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Log_Stats, generation, time, best_score, best_score_v, med_score, med_score_v, med_size, med_complexity, max_size, max_complexity)
MatrixXf corrcoef(const MatrixXf &X)
returns the pearson correlation coefficients of matrix.
vector< type_index > get_dtypes(MatrixXf &X)
calculates data types for each column of X
void reorder(vector< T > &v, vector< int > const &order)
float slope(const ArrayXf &x, const ArrayXf &y)
slope of x/y
float mad(const ArrayXf &x)
median absolute deviation
float condition_number(const MatrixXf &X)
returns true for elements of x that are infinite
std::string ltrim(std::string str, const std::string &chars)
vector< size_t > argsort(const vector< T > &v, bool ascending=true)
return indices that sort a vector
float skew(const ArrayXf &v)
calculate skew
float pearson_correlation(const ArrayXf &x, const ArrayXf &y)
the normalized covariance of x and y
tuple< vector< size_t >, vector< size_t > > mask_to_indices(const ArrayXb &mask)
returns 2 indices: first where mask is true, and second where mask is false.
vector< T > softmax(const vector< T > &w)
return the softmax transformation of a vector.
Scalar median(const T &v)
calculate median
void clean(ArrayXf &x)
limits node output to be between MIN_FLT and MAX_FLT
float kurtosis(const ArrayXf &v)
calculate kurtosis
TypeMap< std::string > type_names
std::enable_if_t< std::is_scalar_v< T >, T > limited(T x)
limits the output to finite real numbers
auto vectorToTupleHelper(const std::vector< T > &v, std::index_sequence< Indices... >)
auto vectorToTuple(const std::vector< T > &v)
std::string rtrim(std::string str, const std::string &chars)
array< Array< T,-1, 1 >, 2 > split(const Array< T,-1, 1 > &v, const ArrayXb &mask)
split Eigen matrix or array into two by mask
string to_string(const T &value)
template function to convert objects to string for logging
void ReplaceStringInPlace(std::string &subject, const std::string &search, const std::string &replace)
string find and replace in place
bool in(const V &v, const T &i)
check if element is in vector.
vector< T > unique(vector< T > w)
returns unique elements in vector
std::vector< T > slice(const vector< T > &v, const U &idx)
void unique_insert(Vector &v, const T &t)
unique insertion into a vector. allows a vector to be used like a set. source: http://www....
std::string trim(std::string str, const std::string &chars)
float variance(const ArrayXf &v)
calculate variance
std::map< std::type_index, T > TypeMap
float covariance(const ArrayXf &x, const ArrayXf &y)
covariance of x and y
ostream & operator<<(ostream &os, const vector< T > &v)
int argmiddle(vector< float > &v)
returns the (first) index of the element with the middlest value in v
vector< size_t > mask_to_index(const ArrayXb &mask)
convert a boolean mask to an index array
< nsga2 selection operator for getting the front
Eigen::Array< bool, Eigen::Dynamic, 1 > ArrayXb
vector< unsigned > max_size
void update(int index, float timer_count, float bst_score, float bst_score_v, float md_score, float md_score_v, unsigned md_size, unsigned md_complexity, unsigned mx_size, unsigned mx_complexity)
vector< unsigned > max_complexity
vector< float > med_score_v
vector< unsigned > med_size
vector< float > med_score
vector< float > best_score_v
vector< unsigned > med_complexity
vector< float > best_score
normalizes a matrix to unit variance, 0 mean centered.
void fit(MatrixXf &X, const vector< char > &dt)
fit the scale and offset of data.
void fit_normalize(MatrixXf &X, const vector< char > &dtypes)
void normalize(MatrixXf &X)
normalize matrix.
static void to_json(json &j, const std::shared_ptr< T > &opt)
static void from_json(const json &j, std::shared_ptr< T > &opt)
size_t operator()(std::tuple< TT... > const &tt) const
std::size_t operator()(const std::vector< float > &v) const