Brush C++ API
A flexible interpretable machine learning framework
Loading...
Searching...
No Matches
Brush::Engine< T > Class Template Reference

The Engine class represents the core engine of the brush library. More...

#include <engine.h>

Collaboration diagram for Brush::Engine< T >:

Public Member Functions

 Engine ()
 
 Engine (Parameters &p, SearchSpace &s)
 
 ~Engine ()
 
void print_progress (float percentage)
 
void calculate_stats ()
 
void print_stats (std::ofstream &log, float fraction)
 
void log_stats (std::ofstream &log)
 
Parametersget_params ()
 
void set_params (Parameters &p)
 
SearchSpaceget_search_space ()
 
void set_search_space (SearchSpace &space)
 
bool get_is_fitted ()
 
bool update_best ()
 updates best score by searching in the population for the individual that best fits the given data
 
Individual< T > & get_best_ind ()
 
Engine< T > & fit (Dataset &data)
 
Engine< T > & fit (const Ref< const ArrayXXf > &X, const Ref< const ArrayXf > &y)
 
auto predict (const Dataset &data)
 
auto predict (const Ref< const ArrayXXf > &X)
 
template<ProgramType P = T>
requires ((P == PT::BinaryClassifier) || (P == PT::MulticlassClassifier))
auto predict_proba (const Dataset &d)
 
template<ProgramType P = T>
requires ((P == PT::BinaryClassifier) || (P == PT::MulticlassClassifier))
auto predict_proba (const Ref< const ArrayXXf > &X)
 
int get_archive_size ()
 return archive size
 
vector< json > get_archive (bool front)
 return archive/population as string
 
vector< json > get_population ()
 
void set_population (vector< json > pop_vector)
 
void lock_nodes (int end_depth=0, bool skip_leaves=true)
 
void unlock_nodes (int start_depth=0)
 
auto predict_archive (int id, const Dataset &data)
 predict on unseen data from the archive
 
auto predict_archive (int id, const Ref< const ArrayXXf > &X)
 
template<ProgramType P = T>
requires ((P == PT::BinaryClassifier) || (P == PT::MulticlassClassifier))
auto predict_proba_archive (int id, const Dataset &data)
 
template<ProgramType P = T>
requires ((P == PT::BinaryClassifier) || (P == PT::MulticlassClassifier))
auto predict_proba_archive (int id, const Ref< const ArrayXXf > &X)
 
void run (Dataset &d)
 train the model
 

Public Attributes

Parameters params
 hyperparameters of brush, which the user can interact
 
SearchSpace ss
 
Individual< T > best_ind
 best individual found during training
 
Archive< T > archive
 pareto front archive
 
Population< T > pop
 population of programs
 
bool is_fitted = false
 keeps track of whether fit was called
 

Private Member Functions

void init ()
 initialize Feat object for fitting.
 
void set_is_fitted (bool f)
 set flag indicating whether fit has been called
 

Private Attributes

Selection< T > selector
 selection algorithm
 
Evaluation< T > evaluator
 evaluation code
 
Selection< T > survivor
 survival algorithm
 
Log_Stats stats
 runtime stats
 
Timer timer
 start time of training
 

Detailed Description

template<ProgramType T>
class Brush::Engine< T >

The Engine class represents the core engine of the brush library.

It encapsulates the functionality for training and predicting with programs in a genetic programming framework. The Engine class manages the population of programs, selection algorithms, evaluation code, variation operators, and survival algorithms. It also provides methods for training the model, making predictions, and accessing runtime statistics.

The Engine class is parameterized by the program type T, which determines the type of programs that can be evolved and evaluated by the engine.

Definition at line 43 of file engine.h.

Constructor & Destructor Documentation

◆ Engine() [1/2]

template<ProgramType T>
Brush::Engine< T >::Engine ( )
inline

Definition at line 45 of file engine.h.

◆ Engine() [2/2]

template<ProgramType T>
Brush::Engine< T >::Engine ( Parameters & p,
SearchSpace & s )
inline

Definition at line 51 of file engine.h.

◆ ~Engine()

template<ProgramType T>
Brush::Engine< T >::~Engine ( )
inline

Definition at line 59 of file engine.h.

Member Function Documentation

◆ calculate_stats()

template<ProgramType T>
void Brush::Engine< T >::calculate_stats ( )

Definition at line 52 of file engine.cpp.

Here is the caller graph for this function:

◆ fit() [1/2]

template<ProgramType T>
Engine< T > & Brush::Engine< T >::fit ( const Ref< const ArrayXXf > & X,
const Ref< const ArrayXf > & y )
inline

Definition at line 85 of file engine.h.

◆ fit() [2/2]

template<ProgramType T>
Engine< T > & Brush::Engine< T >::fit ( Dataset & data)
inline

Definition at line 81 of file engine.h.

Here is the caller graph for this function:

◆ get_archive()

template<ProgramType T>
vector< json > Brush::Engine< T >::get_archive ( bool front)

return archive/population as string

Definition at line 182 of file engine.cpp.

Here is the call graph for this function:

◆ get_archive_size()

template<ProgramType T>
int Brush::Engine< T >::get_archive_size ( )
inline

return archive size

Definition at line 113 of file engine.h.

◆ get_best_ind()

template<ProgramType T>
Individual< T > & Brush::Engine< T >::get_best_ind ( )
inline

Definition at line 79 of file engine.h.

◆ get_is_fitted()

template<ProgramType T>
bool Brush::Engine< T >::get_is_fitted ( )
inline

Definition at line 74 of file engine.h.

◆ get_params()

template<ProgramType T>
Parameters & Brush::Engine< T >::get_params ( )
inline

Definition at line 68 of file engine.h.

◆ get_population()

template<ProgramType T>
vector< json > Brush::Engine< T >::get_population ( )

Definition at line 197 of file engine.cpp.

Here is the call graph for this function:

◆ get_search_space()

template<ProgramType T>
SearchSpace & Brush::Engine< T >::get_search_space ( )
inline

Definition at line 71 of file engine.h.

◆ init()

template<ProgramType T>
void Brush::Engine< T >::init ( )
private

initialize Feat object for fitting.

Definition at line 16 of file engine.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lock_nodes()

template<ProgramType T>
void Brush::Engine< T >::lock_nodes ( int end_depth = 0,
bool skip_leaves = true )

Definition at line 326 of file engine.cpp.

◆ log_stats()

template<ProgramType T>
void Brush::Engine< T >::log_stats ( std::ofstream & log)

Definition at line 119 of file engine.cpp.

Here is the caller graph for this function:

◆ predict() [1/2]

template<ProgramType T>
auto Brush::Engine< T >::predict ( const Dataset & data)
inline

Definition at line 94 of file engine.h.

Here is the caller graph for this function:

◆ predict() [2/2]

template<ProgramType T>
auto Brush::Engine< T >::predict ( const Ref< const ArrayXXf > & X)
inline

Definition at line 95 of file engine.h.

◆ predict_archive() [1/2]

template<ProgramType T>
auto Brush::Engine< T >::predict_archive ( int id,
const Dataset & data )

predict on unseen data from the archive

Definition at line 246 of file engine.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ predict_archive() [2/2]

template<ProgramType T>
auto Brush::Engine< T >::predict_archive ( int id,
const Ref< const ArrayXXf > & X )

Definition at line 277 of file engine.cpp.

Here is the call graph for this function:

◆ predict_proba() [1/2]

template<ProgramType T>
template<ProgramType P = T>
requires ((P == PT::BinaryClassifier) || (P == PT::MulticlassClassifier))
auto Brush::Engine< T >::predict_proba ( const Dataset & d)
inline

Definition at line 103 of file engine.h.

Here is the caller graph for this function:

◆ predict_proba() [2/2]

template<ProgramType T>
template<ProgramType P = T>
requires ((P == PT::BinaryClassifier) || (P == PT::MulticlassClassifier))
auto Brush::Engine< T >::predict_proba ( const Ref< const ArrayXXf > & X)
inline

Definition at line 106 of file engine.h.

◆ predict_proba_archive() [1/2]

template<ProgramType T>
requires ((P == PT::BinaryClassifier) || (P == PT::MulticlassClassifier))
template<ProgramType P>
requires ((P == PT::BinaryClassifier) || (P == PT::MulticlassClassifier))
auto Brush::Engine< T >::predict_proba_archive ( int id,
const Dataset & data )

Definition at line 286 of file engine.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ predict_proba_archive() [2/2]

template<ProgramType T>
requires ((P == PT::BinaryClassifier) || (P == PT::MulticlassClassifier))
template<ProgramType P>
requires ((P == PT::BinaryClassifier) || (P == PT::MulticlassClassifier))
auto Brush::Engine< T >::predict_proba_archive ( int id,
const Ref< const ArrayXXf > & X )

Definition at line 319 of file engine.cpp.

Here is the call graph for this function:

◆ print_progress()

template<ProgramType T>
void Brush::Engine< T >::print_progress ( float percentage)

Definition at line 36 of file engine.cpp.

Here is the caller graph for this function:

◆ print_stats()

template<ProgramType T>
void Brush::Engine< T >::print_stats ( std::ofstream & log,
float fraction )

Definition at line 149 of file engine.cpp.

Here is the caller graph for this function:

◆ run()

template<ProgramType T>
void Brush::Engine< T >::run ( Dataset & d)

train the model

Definition at line 403 of file engine.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_is_fitted()

template<ProgramType T>
void Brush::Engine< T >::set_is_fitted ( bool f)
inlineprivate

set flag indicating whether fit has been called

Definition at line 162 of file engine.h.

Here is the caller graph for this function:

◆ set_params()

template<ProgramType T>
void Brush::Engine< T >::set_params ( Parameters & p)
inline

Definition at line 69 of file engine.h.

◆ set_population()

template<ProgramType T>
void Brush::Engine< T >::set_population ( vector< json > pop_vector)

Definition at line 217 of file engine.cpp.

Here is the call graph for this function:

◆ set_search_space()

template<ProgramType T>
void Brush::Engine< T >::set_search_space ( SearchSpace & space)
inline

Definition at line 72 of file engine.h.

◆ unlock_nodes()

template<ProgramType T>
void Brush::Engine< T >::unlock_nodes ( int start_depth = 0)

Definition at line 341 of file engine.cpp.

◆ update_best()

template<ProgramType T>
bool Brush::Engine< T >::update_best ( )

updates best score by searching in the population for the individual that best fits the given data

Definition at line 357 of file engine.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ archive

template<ProgramType T>
Archive<T> Brush::Engine< T >::archive

pareto front archive

Definition at line 146 of file engine.h.

◆ best_ind

template<ProgramType T>
Individual<T> Brush::Engine< T >::best_ind

best individual found during training

Definition at line 145 of file engine.h.

◆ evaluator

template<ProgramType T>
Evaluation<T> Brush::Engine< T >::evaluator
private

evaluation code

Definition at line 152 of file engine.h.

◆ is_fitted

template<ProgramType T>
bool Brush::Engine< T >::is_fitted = false

keeps track of whether fit was called

Definition at line 149 of file engine.h.

◆ params

template<ProgramType T>
Parameters Brush::Engine< T >::params

hyperparameters of brush, which the user can interact

Definition at line 142 of file engine.h.

◆ pop

template<ProgramType T>
Population<T> Brush::Engine< T >::pop

population of programs

Definition at line 147 of file engine.h.

◆ selector

template<ProgramType T>
Selection<T> Brush::Engine< T >::selector
private

selection algorithm

Definition at line 151 of file engine.h.

◆ ss

template<ProgramType T>
SearchSpace Brush::Engine< T >::ss

Definition at line 143 of file engine.h.

◆ stats

template<ProgramType T>
Log_Stats Brush::Engine< T >::stats
private

runtime stats

Definition at line 155 of file engine.h.

◆ survivor

template<ProgramType T>
Selection<T> Brush::Engine< T >::survivor
private

survival algorithm

Definition at line 153 of file engine.h.

◆ timer

template<ProgramType T>
Timer Brush::Engine< T >::timer
private

start time of training

Definition at line 157 of file engine.h.


The documentation for this class was generated from the following files: