Feat C++ API
A feature engineering automation tool
FT::Util Namespace Reference

namespace containing various utility functions used in Feat More...

Classes

class  Logger
 Defines a multi level static logger for feat. More...
 
class  Rnd
 Defines a multi-core random number generator and its operators. More...
 
class  Timer
 class for timing things. More...
 
struct  Normalizer
 normalizes a matrix to unit variance, 0 mean centered. More...
 
struct  Log_Stats
 

Typedefs

typedef struct Log_Stats Log_stats
 

Functions

void ThrowRuntimeError (string err, const char *file, int line)
 prints error and throws an exception More...
 
void ThrowInvalidArgument (string err, const char *file, int line)
 
void ThrowLengthError (string err, const char *file, int line)
 
void Warn (string err, const char *file, int line)
 prints error to stderr and returns More...
 
void my_handler (int s)
 handle signals (ctr-c etc.) More...
 
void printProgress (float percentage)
 outputs a progress bar, filled according to More...
 
void load_csv (const std::string &path, MatrixXf &X, VectorXf &y, vector< string > &names, vector< char > &dtypes, bool &binary_endpoint, char sep)
 load csv file into matrix. More...
 
void load_longitudinal (const std::string &path, std::map< string, std::pair< vector< ArrayXf >, vector< ArrayXf > > > &Z, char sep)
 load longitudinal csv file into matrix. More...
 
void load_partial_longitudinal (const std::string &path, std::map< string, std::pair< vector< ArrayXf >, vector< ArrayXf > > > &Z, char sep, const vector< int > &idx)
 load partial longitudinal csv file into matrix according to idx vector More...
 
void clean (ArrayXf &x)
 limits node output to be between MIN_FLT and MAX_FLT More...
 
void clean (VectorXf &x)
 
std::string ltrim (std::string str, const std::string &chars)
 
std::string rtrim (std::string str, const std::string &chars)
 
std::string trim (std::string str, const std::string &chars)
 
vector< char > find_dtypes (const MatrixXf &X)
 determines data types of columns of matrix X. More...
 
float median (const ArrayXf &v)
 calculate median More...
 
int argmiddle (vector< float > &v)
 returns the (first) index of the element with the middlest value in v More...
 
float variance (const ArrayXf &v, float mean)
 calculate variance when mean provided More...
 
float variance (const ArrayXf &v)
 calculate variance More...
 
float skew (const ArrayXf &v)
 calculate skew More...
 
float kurtosis (const ArrayXf &v)
 calculate kurtosis More...
 
float covariance (const ArrayXf &x, const ArrayXf &y)
 covariance of x and y More...
 
float slope (const ArrayXf &x, const ArrayXf &y)
 slope of x/y More...
 
float pearson_correlation (const ArrayXf &x, const ArrayXf &y)
 the normalized covariance of x and y More...
 
float mad (const ArrayXf &x)
 median absolute deviation More...
 
ArrayXb isinf (const ArrayXf &x)
 returns true for elements of x that are infinite More...
 
ArrayXb isnan (const ArrayXf &x)
 returns true for elements of x that are NaN More...
 
float condition_number (const MatrixXf &X)
 returns the condition number of a matrix. More...
 
MatrixXf corrcoef (const MatrixXf &X)
 returns the pearson correlation coefficients of matrix. More...
 
float mean_square_corrcoef (const MatrixXf &X)
 
std::string ravel (const vector< string > &v, string sep=",")
 takes a vector string and returns it as a delimited string. More...
 
template<typename T >
bool in (const vector< T > v, const T &i)
 check if element is in vector. More...
 
template<typename T >
vector< size_t > argsort (const vector< T > &v, bool ascending=true)
 return indices that sort a vector More...
 
template<typename T >
vector< T > softmax (const vector< T > &w)
 return the softmax transformation of a vector. More...
 
template<typename T >
vector< T > unique (vector< T > w)
 returns unique elements in vector More...
 
template<typename T >
vector< T > unique (Matrix< T, -1, -1 > w)
 returns unique elements in Eigen matrix of variable rows/cols More...
 
template<typename T >
vector< T > unique (Matrix< T, -1, 1 > w)
 returns unique elements in Eigen vector More...
 
template<typename T >
vector< T > unique (Array< T, -1, 1 > w)
 returns unique elements in 1d Eigen array More...
 
 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE (Log_Stats, generation, time, min_loss, min_loss_v, med_loss, med_loss_v, med_size, med_complexity, med_num_params, med_dim)
 
template<typename T >
std::string to_string (const T &value)
 template function to convert objects to string for logging More...
 
template<typename T >
std::string to_string (const T a_value, const int n)
 

Variables

static Loggerlogger = *Logger::initLogger()
 
static Rndr = *Rnd::initRand()
 
string PBSTR = "===================="
 
int PBWIDTH = 20
 

Detailed Description

namespace containing various utility functions used in Feat

Typedef Documentation

◆ Log_stats

Definition at line 379 of file utils.h.

Function Documentation

◆ argmiddle()

int FT::Util::argmiddle ( vector< float > &  v)

returns the (first) index of the element with the middlest value in v

Definition at line 109 of file utils.cc.

◆ argsort()

template<typename T >
vector<size_t> FT::Util::argsort ( const vector< T > &  v,
bool  ascending = true 
)

return indices that sort a vector

Definition at line 81 of file utils.h.

◆ clean() [1/2]

void FT::Util::clean ( ArrayXf &  x)

limits node output to be between MIN_FLT and MAX_FLT

Definition at line 18 of file utils.cc.

◆ clean() [2/2]

void FT::Util::clean ( VectorXf &  x)

Definition at line 24 of file utils.cc.

◆ condition_number()

float FT::Util::condition_number ( const MatrixXf &  X)

returns the condition number of a matrix.

Definition at line 236 of file utils.cc.

◆ corrcoef()

MatrixXf FT::Util::corrcoef ( const MatrixXf &  X)

returns the pearson correlation coefficients of matrix.

Definition at line 254 of file utils.cc.

◆ covariance()

float FT::Util::covariance ( const ArrayXf &  x,
const ArrayXf &  y 
)

covariance of x and y

Definition at line 164 of file utils.cc.

◆ find_dtypes()

vector< char > FT::Util::find_dtypes ( const MatrixXf &  X)

determines data types of columns of matrix X.

calculates data types for each column of X

Definition at line 49 of file utils.cc.

◆ in()

template<typename T >
bool FT::Util::in ( const vector< T >  v,
const T &  i 
)

check if element is in vector.

Definition at line 47 of file utils.h.

◆ isinf()

ArrayXb FT::Util::isinf ( const ArrayXf &  x)

returns true for elements of x that are infinite

Definition at line 217 of file utils.cc.

◆ isnan()

ArrayXb FT::Util::isnan ( const ArrayXf &  x)

returns true for elements of x that are NaN

Definition at line 226 of file utils.cc.

◆ kurtosis()

float FT::Util::kurtosis ( const ArrayXf &  v)

calculate kurtosis

Definition at line 153 of file utils.cc.

◆ load_csv()

void FT::Util::load_csv ( const std::string &  path,
MatrixXf &  X,
VectorXf &  y,
vector< string > &  names,
vector< char > &  dtypes,
bool &  binary_endpoint,
char  sep 
)

load csv file into matrix.

Definition at line 27 of file io.cc.

◆ load_longitudinal()

void FT::Util::load_longitudinal ( const std::string &  path,
std::map< string, std::pair< vector< ArrayXf >, vector< ArrayXf > > > &  Z,
char  sep 
)

load longitudinal csv file into matrix.

Definition at line 100 of file io.cc.

◆ load_partial_longitudinal()

void FT::Util::load_partial_longitudinal ( const std::string &  path,
std::map< string, std::pair< vector< ArrayXf >, vector< ArrayXf > > > &  Z,
char  sep,
const vector< int > &  idx 
)

load partial longitudinal csv file into matrix according to idx vector

load partial longitudinal csv file into matrix according to idx vector

Definition at line 175 of file io.cc.

◆ ltrim()

std::string FT::Util::ltrim ( std::string  str,
const std::string &  chars 
)

Definition at line 31 of file utils.cc.

◆ mad()

float FT::Util::mad ( const ArrayXf &  x)

median absolute deviation

Definition at line 189 of file utils.cc.

◆ mean_square_corrcoef()

float FT::Util::mean_square_corrcoef ( const MatrixXf &  X)

Definition at line 266 of file utils.cc.

◆ median()

float FT::Util::median ( const ArrayXf &  v)

calculate median

Definition at line 89 of file utils.cc.

◆ my_handler()

void FT::Util::my_handler ( int  s)

handle signals (ctr-c etc.)

Definition at line 43 of file error.cc.

◆ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE()

FT::Util::NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE ( Log_Stats  ,
generation  ,
time  ,
min_loss  ,
min_loss_v  ,
med_loss  ,
med_loss_v  ,
med_size  ,
med_complexity  ,
med_num_params  ,
med_dim   
)

◆ pearson_correlation()

float FT::Util::pearson_correlation ( const ArrayXf &  x,
const ArrayXf &  y 
)

the normalized covariance of x and y

Definition at line 184 of file utils.cc.

◆ printProgress()

void FT::Util::printProgress ( float  percentage)

outputs a progress bar, filled according to

Parameters
percentage.

Definition at line 15 of file io.cc.

◆ ravel()

std::string FT::Util::ravel ( const vector< string > &  v,
string  sep 
)

takes a vector string and returns it as a delimited string.

Definition at line 297 of file utils.cc.

◆ rtrim()

std::string FT::Util::rtrim ( std::string  str,
const std::string &  chars 
)

Definition at line 37 of file utils.cc.

◆ skew()

float FT::Util::skew ( const ArrayXf &  v)

calculate skew

Definition at line 141 of file utils.cc.

◆ slope()

float FT::Util::slope ( const ArrayXf &  x,
const ArrayXf &  y 
)

slope of x/y

Definition at line 177 of file utils.cc.

◆ softmax()

template<typename T >
vector<T> FT::Util::softmax ( const vector< T > &  w)

return the softmax transformation of a vector.

Definition at line 130 of file utils.h.

◆ ThrowInvalidArgument()

void FT::Util::ThrowInvalidArgument ( string  err,
const char *  file,
int  line 
)

Definition at line 22 of file error.cc.

◆ ThrowLengthError()

void FT::Util::ThrowLengthError ( string  err,
const char *  file,
int  line 
)

Definition at line 28 of file error.cc.

◆ ThrowRuntimeError()

void FT::Util::ThrowRuntimeError ( string  err,
const char *  file,
int  line 
)

prints error and throws an exception

Definition at line 16 of file error.cc.

◆ to_string() [1/2]

template<typename T >
std::string FT::Util::to_string ( const T &  value)

template function to convert objects to string for logging

Definition at line 422 of file utils.h.

◆ to_string() [2/2]

template<typename T >
std::string FT::Util::to_string ( const T  a_value,
const int  n 
)

Definition at line 430 of file utils.h.

◆ trim()

std::string FT::Util::trim ( std::string  str,
const std::string &  chars 
)

Definition at line 43 of file utils.cc.

◆ unique() [1/4]

template<typename T >
vector<T> FT::Util::unique ( Array< T, -1, 1 >  w)

returns unique elements in 1d Eigen array

Definition at line 363 of file utils.h.

◆ unique() [2/4]

template<typename T >
vector<T> FT::Util::unique ( Matrix< T, -1, -1 >  w)

returns unique elements in Eigen matrix of variable rows/cols

Definition at line 347 of file utils.h.

◆ unique() [3/4]

template<typename T >
vector<T> FT::Util::unique ( Matrix< T, -1, 1 >  w)

returns unique elements in Eigen vector

Definition at line 355 of file utils.h.

◆ unique() [4/4]

template<typename T >
vector<T> FT::Util::unique ( vector< T >  w)

returns unique elements in vector

Definition at line 336 of file utils.h.

◆ variance() [1/2]

float FT::Util::variance ( const ArrayXf &  v)

calculate variance

Definition at line 134 of file utils.cc.

◆ variance() [2/2]

float FT::Util::variance ( const ArrayXf &  v,
float  mean 
)

calculate variance when mean provided

Definition at line 127 of file utils.cc.

◆ Warn()

void FT::Util::Warn ( string  err,
const char *  file,
int  line 
)

prints error to stderr and returns

prints warning to stdout and returns

Definition at line 35 of file error.cc.

Variable Documentation

◆ logger

Logger& FT::Util::logger = *Logger::initLogger()
static

Definition at line 46 of file logger.h.

◆ PBSTR

string FT::Util::PBSTR = "===================="

Definition at line 14 of file utils.cc.

◆ PBWIDTH

int FT::Util::PBWIDTH = 20

Definition at line 15 of file utils.cc.

◆ r

Rnd& FT::Util::r = *Rnd::initRand()
static

Definition at line 135 of file rnd.h.