Brush C++ API
A flexible interpretable machine learning framework
Loading...
Searching...
No Matches
utils.h File Reference
#include <Eigen/Dense>
#include <vector>
#include <set>
#include <fstream>
#include <chrono>
#include <ostream>
#include <map>
#include "../init.h"
#include "error.h"
#include <typeindex>
#include <iterator>
#include <execution>
#include <tuple>
Include dependency graph for utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  nlohmann::adl_serializer< std::shared_ptr< T > >
 
struct  std::hash< std::vector< float > >
 
struct  std::hash< std::tuple< TT... > >
 
class  Brush::Util::Timer
 class for timing things. More...
 
struct  Brush::Util::Normalizer
 normalizes a matrix to unit variance, 0 mean centered. More...
 
struct  Brush::Util::Log_Stats
 

Namespaces

namespace  Brush::Util
 namespace containing various utility functions
 
namespace  nlohmann
 
namespace  std
 STL namespace.
 
namespace  Brush
 < nsga2 selection operator for getting the front
 

Typedefs

template<typename T >
using Brush::Util::TypeMap = std::map<std::type_index, T>
 
typedef struct Log_Stats Brush::Util::Log_stats
 

Functions

void Brush::Util::clean (ArrayXf &x)
 limits node output to be between MIN_FLT and MAX_FLT
 
std::string Brush::Util::ltrim (std::string str, const std::string &chars)
 
std::string Brush::Util::rtrim (std::string str, const std::string &chars)
 
std::string Brush::Util::trim (std::string str, const std::string &chars)
 
template<typename V , typename T >
bool Brush::Util::in (const V &v, const T &i)
 check if element is in vector.
 
template<typename T , typename Scalar = T::Scalar>
Scalar Brush::Util::median (const T &v)
 calculate median
 
float Brush::Util::variance (const ArrayXf &v, float mean)
 calculate variance when mean provided
 
float Brush::Util::variance (const ArrayXf &v)
 calculate variance
 
float Brush::Util::skew (const ArrayXf &v)
 calculate skew
 
float Brush::Util::kurtosis (const ArrayXf &v)
 calculate kurtosis
 
float Brush::Util::covariance (const ArrayXf &x, const ArrayXf &y)
 covariance of x and y
 
float Brush::Util::slope (const ArrayXf &x, const ArrayXf &y)
 slope of x/y
 
float Brush::Util::pearson_correlation (const ArrayXf &x, const ArrayXf &y)
 the normalized covariance of x and y
 
float Brush::Util::mad (const ArrayXf &x)
 median absolute deviation
 
template<typename T >
vector< size_tBrush::Util::argsort (const vector< T > &v, bool ascending=true)
 return indices that sort a vector
 
template<typename T >
vector< T > Brush::Util::softmax (const vector< T > &w)
 return the softmax transformation of a vector.
 
vector< type_index > Brush::Util::get_dtypes (MatrixXf &X)
 calculates data types for each column of X
 
template<typename T >
vector< T > Brush::Util::unique (vector< T > w)
 returns unique elements in vector
 
template<typename T >
vector< T > Brush::Util::unique (Matrix< T, -1, -1 > w)
 returns unique elements in Eigen matrix of variable rows/cols
 
template<typename T >
vector< T > Brush::Util::unique (Matrix< T, -1, 1 > w)
 returns unique elements in Eigen vector
 
template<typename T >
vector< T > Brush::Util::unique (Array< T, -1, 1 > w)
 returns unique elements in 1d Eigen array
 
template<typename T >
string Brush::Util::to_string (const T &value)
 template function to convert objects to string for logging
 
std::string Brush::Util::ReplaceString (std::string subject, const std::string &search, const std::string &replace)
 find and replace string
 
void Brush::Util::ReplaceStringInPlace (std::string &subject, const std::string &search, const std::string &replace)
 string find and replace in place
 
float Brush::Util::condition_number (const MatrixXf &X)
 returns true for elements of x that are infinite
 
MatrixXf Brush::Util::corrcoef (const MatrixXf &X)
 returns the pearson correlation coefficients of matrix.
 
float Brush::Util::mean_square_corrcoef (const MatrixXf &X)
 
int Brush::Util::argmiddle (vector< float > &v)
 returns the (first) index of the element with the middlest value in v
 
 Brush::Util::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)
 
template<typename T >
std::enable_if_t< std::is_scalar_v< T >, T > Brush::Util::limited (T x)
 limits the output to finite real numbers
 
template<typename T >
std::enable_if_t< std::is_base_of_v< Eigen::ArrayBase< T >, T >, T > Brush::Util::limited (T x)
 
template<typename T >
void Brush::Util::reorder (vector< T > &v, vector< int > const &order)
 
vector< size_tBrush::Util::mask_to_index (const ArrayXb &mask)
 convert a boolean mask to an index array
 
tuple< vector< size_t >, vector< size_t > > Brush::Util::mask_to_indices (const ArrayXb &mask)
 returns 2 indices: first where mask is true, and second where mask is false.
 
template<typename T >
array< Array< T,-1, 1 >, 2 > Brush::Util::split (const Array< T,-1, 1 > &v, const ArrayXb &mask)
 split Eigen matrix or array into two by mask
 
template<std::ranges::range T>
void Brush::Util::print (T t)
 prints comma delimited container contents.
 
template<class Vector , class T >
void Brush::Util::unique_insert (Vector &v, const T &t)
 unique insertion into a vector. allows a vector to be used like a set. source: http://www.lafstern.org/matt/col1.pdf
 
template<typename T , std::size_t... Indices>
auto Brush::Util::vectorToTupleHelper (const std::vector< T > &v, std::index_sequence< Indices... >)
 
template<std::size_t N, typename T >
auto Brush::Util::vectorToTuple (const std::vector< T > &v)
 
template<typename R , typename Arg , typename... Args>
R Brush::Util::apply (const std::function< R(Args...)> &f, const vector< Arg > &inputs)
 
template<class T , class U >
std::vector< T > Brush::Util::slice (const vector< T > &v, const U &idx)
 
template<typename K , typename V >
static map< V, K > Brush::Util::reverse_map (const map< K, V > &m)
 Given a map from keys to values, creates a new map from values to keys.
 
template<typename T >
ostream & Brush::Util::operator<< (ostream &os, const vector< T > &v)