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 >:

Classes

struct  PopSummary
 summary statistics of a subset of the population (e.g. an island) More...

Public Member Functions

 Engine ()
 Engine (Parameters &p, SearchSpace &s)
 ~Engine ()
void print_progress (float percentage)
void calculate_stats ()
void print_stats (float fraction)
Parameters & get_params ()
void set_params (Parameters &p)
SearchSpace & get_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_as_json ()
 return archive/population as strings
vector< json > get_population_as_json ()
void set_population_from_json (vector< json > pop_vector)
vector< Individual< T > > get_archive ()
 return archive/popularion as individuals ready to use
vector< Individual< T > > get_population ()
void set_population (vector< Individual< T > > pop_vector)
void lock_nodes (int end_depth=0, bool keep_leaves_unlocked=true, bool keep_current_weights=false)
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

PopSummary summarize (const vector< size_t > &indices) const
void open_logs ()
void log_stats (unsigned stall_count, const SimplificationRecords &simplifications)
void close_logs ()
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
string run_id
 identifies the rows of one call to fit
Util::CsvWriter log_generations
 <logfile>
Util::CsvWriter log_islands
 <logfile>_islands.csv
Util::CsvWriter log_simplifications
 <logfile>_simplifications.csv

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 44 of file engine.h.

Constructor & Destructor Documentation

◆ Engine() [1/2]

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

Definition at line 46 of file engine.h.

◆ Engine() [2/2]

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

Definition at line 52 of file engine.h.

◆ ~Engine()

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

Definition at line 60 of file engine.h.

Member Function Documentation

◆ calculate_stats()

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

Definition at line 147 of file engine.cpp.

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

◆ close_logs()

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

Definition at line 307 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.

◆ get_archive()

template<ProgramType T>
vector< Individual< T > > Brush::Engine< T >::get_archive ( )

return archive/popularion as individuals ready to use

Definition at line 385 of file engine.cpp.

◆ get_archive_as_json()

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

return archive/population as strings

Definition at line 348 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 118 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< Individual< T > > Brush::Engine< T >::get_population ( )

Definition at line 396 of file engine.cpp.

◆ get_population_as_json()

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

Definition at line 363 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 21 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 keep_leaves_unlocked = true,
bool keep_current_weights = false )

Definition at line 459 of file engine.cpp.

◆ log_stats()

template<ProgramType T>
void Brush::Engine< T >::log_stats ( unsigned stall_count,
const SimplificationRecords & simplifications )
private

Definition at line 247 of file engine.cpp.

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

◆ open_logs()

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

Definition at line 211 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 99 of file engine.h.

◆ predict() [2/2]

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

Definition at line 100 of file engine.h.

◆ 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 108 of file engine.h.

◆ 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 111 of file engine.h.

◆ print_progress()

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

Definition at line 41 of file engine.cpp.

Here is the caller graph for this function:

◆ print_stats()

template<ProgramType T>
void Brush::Engine< T >::print_stats ( float fraction)

Definition at line 315 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 531 of file engine.cpp.

Here is the call 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 182 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< Individual< T > > pop_vector)

Definition at line 440 of file engine.cpp.

Here is the call graph for this function:

◆ set_population_from_json()

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

Definition at line 414 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.

◆ summarize()

template<ProgramType T>
Engine< T >::PopSummary Brush::Engine< T >::summarize ( const vector< size_t > & indices) const
private

Definition at line 57 of file engine.cpp.

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

◆ 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 479 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 142 of file engine.h.

◆ best_ind

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

best individual found during training

Definition at line 141 of file engine.h.

◆ evaluator

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

evaluation code

Definition at line 148 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 145 of file engine.h.

◆ log_generations

template<ProgramType T>
Util::CsvWriter Brush::Engine< T >::log_generations
private

<logfile>

Definition at line 171 of file engine.h.

◆ log_islands

template<ProgramType T>
Util::CsvWriter Brush::Engine< T >::log_islands
private

<logfile>_islands.csv

Definition at line 172 of file engine.h.

◆ log_simplifications

template<ProgramType T>
Util::CsvWriter Brush::Engine< T >::log_simplifications
private

<logfile>_simplifications.csv

Definition at line 173 of file engine.h.

◆ params

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

hyperparameters of brush, which the user can interact

Definition at line 138 of file engine.h.

◆ pop

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

population of programs

Definition at line 143 of file engine.h.

◆ run_id

template<ProgramType T>
string Brush::Engine< T >::run_id
private

identifies the rows of one call to fit

Definition at line 170 of file engine.h.

◆ selector

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

selection algorithm

Definition at line 147 of file engine.h.

◆ ss

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

Definition at line 139 of file engine.h.

◆ stats

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

runtime stats

Definition at line 151 of file engine.h.

◆ survivor

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

survival algorithm

Definition at line 149 of file engine.h.

◆ timer

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

start time of training

Definition at line 153 of file engine.h.


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