Brush C++ API
A flexible interpretable machine learning framework
Loading...
Searching...
No Matches
Brush::Program< PType > Struct Template Reference

An individual program, a.k.a. model. More...

#include <program.h>

Public Types

using RetType
 the return type of the tree when calling :func:predict.
 
using TreeType
 the type of output from the tree object
 

Public Member Functions

 Program ()=default
 
 Program (const std::reference_wrapper< SearchSpace > s, const tree< Node > t)
 
Program< PTypecopy ()
 
void set_search_space (const std::reference_wrapper< SearchSpace > s)
 
int complexity () const
 count the complexity of the program.
 
int size (bool include_weight=true) const
 count the tree size of the program, including the weights in weighted nodes.
 
int size_at (Iter &top, bool include_weight=true) const
 count the size of a given subtree, optionally including the weights in weighted nodes. This function is not exposed to the python wrapper.
 
int depth () const
 count the tree depth of the program. The depth is not influenced by weighted nodes.
 
int depth_at (Iter &top) const
 count the depth of a given subtree. The depth is not influenced by weighted nodes. This function is not exposed to the python wrapper.
 
int depth_to_reach (Iter &top) const
 count the depth until reaching the given subtree. The depth is not influenced by weighted nodes. This function is not exposed to the python wrapper.
 
Program< PType > & fit (const Dataset &d)
 
template<typename R , typename W >
R predict_with_weights (const Dataset &d, const W **weights)
 
auto predict_with_weights (const Dataset &d, const ArrayXf &weights)
 
template<typename R = RetType>
requires (is_same_v<R, TreeType>)
TreeType predict (const Dataset &d)
 the standard predict function. Returns the output of the Tree directly.
 
template<typename R = RetType>
requires (is_same_v<R, ArrayXb>)
ArrayXb predict (const Dataset &d)
 Specialized predict function for binary classification.
 
template<typename R = RetType>
requires (is_same_v<R, ArrayXi>)
ArrayXi predict (const Dataset &d)
 Specialized predict function for multiclass classification.
 
template<PT P = PType>
requires ((P == PT::BinaryClassifier) || (P == PT::MulticlassClassifier))
TreeType predict_proba (const Dataset &d)
 
Program< PType > & fit (const Ref< const ArrayXXf > &X, const Ref< const ArrayXf > &y)
 Convenience function to call fit directly from X,y data.
 
RetType predict (const Ref< const ArrayXXf > &X)
 Convenience function to call predict directly from X data.
 
template<PT P = PType>
requires ((P == PT::BinaryClassifier) || (P == PT::MulticlassClassifier))
TreeType predict_proba (const Ref< const ArrayXXf > &X)
 Predict probabilities from X.
 
void update_weights (const Dataset &d)
 Updates the program's weights using non-linear least squares.
 
int get_n_weights () const
 returns the number of weights in the program.
 
ArrayXf get_weights ()
 Get the weights of the tree as an array.
 
void set_weights (const ArrayXf &weights)
 Set the weights in the tree from an array of weights.
 
string get_model (string fmt="compact", bool pretty=false) const
 Get the model as a string.
 
string get_dot_model (string extras="") const
 Get the model as a dot object.
 
vector< Nodelinearize () const
 turns program tree into a linear program.
 

Public Attributes

bool is_fitted_
 whether fit has been called
 
tree< NodeTree
 fitness
 
std::optional< std::reference_wrapper< SearchSpace > > SSref
 reference to search space
 

Static Public Attributes

static constexpr PT program_type = PType
 an enum storing the program type.
 

Detailed Description

template<PT PType>
struct Brush::Program< PType >

An individual program, a.k.a. model.

Template Parameters
PTypeone of the ProgramType enum values.

Definition at line 49 of file program.h.

Member Typedef Documentation

◆ RetType

template<PT PType>
using Brush::Program< PType >::RetType
Initial value:
typename std::conditional_t<PType == PT::Regressor, ArrayXf,
std::conditional_t<PType == PT::BinaryClassifier, ArrayXb,
std::conditional_t<PType == PT::MulticlassClassifier, ArrayXi,
std::conditional_t<PType == PT::Representer, ArrayXXf, ArrayXf
>>>>
void bind_engine(py::module &m, string name)
Eigen::Array< bool, Eigen::Dynamic, 1 > ArrayXb
Definition types.h:39
Eigen::Array< int, Eigen::Dynamic, 1 > ArrayXi
Definition types.h:40

the return type of the tree when calling :func:predict.

Definition at line 55 of file program.h.

◆ TreeType

template<PT PType>
using Brush::Program< PType >::TreeType
Initial value:
std::conditional_t<PType == PT::BinaryClassifier, ArrayXf,
std::conditional_t<PType == PT::MulticlassClassifier, ArrayXXf,
typename std::conditional_t< PType==PT::Regressor, ArrayXf, std::conditional_t< PType==PT::BinaryClassifier, ArrayXb, std::conditional_t< PType==PT::MulticlassClassifier, ArrayXi, std::conditional_t< PType==PT::Representer, ArrayXXf, ArrayXf > > > > RetType
the return type of the tree when calling :func:predict.
Definition program.h:55

the type of output from the tree object

Definition at line 62 of file program.h.

Constructor & Destructor Documentation

◆ Program() [1/2]

template<PT PType>
Brush::Program< PType >::Program ( )
default

◆ Program() [2/2]

template<PT PType>
Brush::Program< PType >::Program ( const std::reference_wrapper< SearchSpace > s,
const tree< Node > t )
inline

Definition at line 78 of file program.h.

Here is the call graph for this function:

Member Function Documentation

◆ complexity()

template<PT PType>
int Brush::Program< PType >::complexity ( ) const
inline

count the complexity of the program.

Returns
int complexity.

Definition at line 93 of file program.h.

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

◆ copy()

template<PT PType>
Program< PType > Brush::Program< PType >::copy ( )
inline

Definition at line 84 of file program.h.

Here is the call graph for this function:

◆ depth()

template<PT PType>
int Brush::Program< PType >::depth ( ) const
inline

count the tree depth of the program. The depth is not influenced by weighted nodes.

Returns
int tree depth.

Definition at line 120 of file program.h.

Here is the caller graph for this function:

◆ depth_at()

template<PT PType>
int Brush::Program< PType >::depth_at ( Iter & top) const
inline

count the depth of a given subtree. The depth is not influenced by weighted nodes. This function is not exposed to the python wrapper.

Parameters
toproot node of the subtree.
Returns
int tree depth.

Definition at line 130 of file program.h.

Here is the call graph for this function:

◆ depth_to_reach()

template<PT PType>
int Brush::Program< PType >::depth_to_reach ( Iter & top) const
inline

count the depth until reaching the given subtree. The depth is not influenced by weighted nodes. This function is not exposed to the python wrapper.

Parameters
toproot node of the subtree.
Returns
int tree depth.

Definition at line 138 of file program.h.

Here is the call graph for this function:

◆ fit() [1/2]

template<PT PType>
Program< PType > & Brush::Program< PType >::fit ( const Dataset & d)
inline

Definition at line 142 of file program.h.

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

◆ fit() [2/2]

template<PT PType>
Program< PType > & Brush::Program< PType >::fit ( const Ref< const ArrayXXf > & X,
const Ref< const ArrayXf > & y )
inline

Convenience function to call fit directly from X,y data.

Parameters
X: Input features
y: Labels
Returns
: reference to program

Definition at line 221 of file program.h.

Here is the call graph for this function:

◆ get_dot_model()

template<PT PType>
string Brush::Program< PType >::get_dot_model ( string extras = "") const
inline

Get the model as a dot object.

Parameters
extrasextra code passed to the beginning of the dot code.
Returns
string the model in dot language.

Definition at line 344 of file program.h.

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

◆ get_model()

template<PT PType>
string Brush::Program< PType >::get_model ( string fmt = "compact",
bool pretty = false ) const
inline

Get the model as a string.

Parameters
fmtone of "compact", "tree", or "dot". Default "compact".
  • compact : the program as an equation.
  • tree : the program as a (small batch, artisinal) tree.
  • dot : the program in the dot language for downstream visualization.
Parameters
prettycurrently unused.
Returns
string the model in string form.

Definition at line 328 of file program.h.

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

◆ get_n_weights()

template<PT PType>
int Brush::Program< PType >::get_n_weights ( ) const
inline

returns the number of weights in the program.

Definition at line 259 of file program.h.

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

◆ get_weights()

template<PT PType>
ArrayXf Brush::Program< PType >::get_weights ( )
inline

Get the weights of the tree as an array.

Returns
ArrayXf of weights in the program, encoded in post-fix order.

Definition at line 277 of file program.h.

Here is the call graph for this function:

◆ linearize()

template<PT PType>
vector< Node > Brush::Program< PType >::linearize ( ) const
inline

turns program tree into a linear program.

Returns
a vector of nodes encoding the program in reverse polish notation

Definition at line 479 of file program.h.

Here is the call graph for this function:

◆ predict() [1/4]

template<PT PType>
template<typename R = RetType>
requires (is_same_v<R, TreeType>)
TreeType Brush::Program< PType >::predict ( const Dataset & d)
inline

the standard predict function. Returns the output of the Tree directly.

Template Parameters
Rreturn type, default
Parameters
ddataset
Returns

Definition at line 175 of file program.h.

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

◆ predict() [2/4]

template<PT PType>
template<typename R = RetType>
requires (is_same_v<R, ArrayXb>)
ArrayXb Brush::Program< PType >::predict ( const Dataset & d)
inline

Specialized predict function for binary classification.

Template Parameters
Rreturn type, typically left blank
Parameters
d: data
Returns
out: binary labels

Definition at line 188 of file program.h.

Here is the call graph for this function:

◆ predict() [3/4]

template<PT PType>
template<typename R = RetType>
requires (is_same_v<R, ArrayXi>)
ArrayXi Brush::Program< PType >::predict ( const Dataset & d)
inline

Specialized predict function for multiclass classification.

Template Parameters
Rreturn type, typically left blank
Parameters
d: data
Returns
out: integer labels

Definition at line 200 of file program.h.

Here is the call graph for this function:

◆ predict() [4/4]

template<PT PType>
RetType Brush::Program< PType >::predict ( const Ref< const ArrayXXf > & X)
inline

Convenience function to call predict directly from X data.

Parameters
X: Input features
Returns
: predictions

Definition at line 230 of file program.h.

Here is the call graph for this function:

◆ predict_proba() [1/2]

template<PT PType>
template<PT P = PType>
requires ((P == PT::BinaryClassifier) || (P == PT::MulticlassClassifier))
TreeType Brush::Program< PType >::predict_proba ( const Dataset & d)
inline

Definition at line 212 of file program.h.

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

◆ predict_proba() [2/2]

template<PT PType>
template<PT P = PType>
requires ((P == PT::BinaryClassifier) || (P == PT::MulticlassClassifier))
TreeType Brush::Program< PType >::predict_proba ( const Ref< const ArrayXXf > & X)
inline

Predict probabilities from X.

Requires a BinaryClassifier or MulticlassClassifier.

Template Parameters
Pparameter for type checking, typically left blank.

Definition at line 245 of file program.h.

Here is the call graph for this function:

◆ predict_with_weights() [1/2]

template<PT PType>
auto Brush::Program< PType >::predict_with_weights ( const Dataset & d,
const ArrayXf & weights )
inline

Definition at line 160 of file program.h.

Here is the call graph for this function:

◆ predict_with_weights() [2/2]

template<PT PType>
template<typename R , typename W >
R Brush::Program< PType >::predict_with_weights ( const Dataset & d,
const W ** weights )
inline

Definition at line 152 of file program.h.

Here is the call graph for this function:

◆ set_search_space()

template<PT PType>
void Brush::Program< PType >::set_search_space ( const std::reference_wrapper< SearchSpace > s)
inline

Definition at line 86 of file program.h.

Here is the call graph for this function:

◆ set_weights()

template<PT PType>
void Brush::Program< PType >::set_weights ( const ArrayXf & weights)
inline

Set the weights in the tree from an array of weights.

Parameters
weightsan array of weights. The number of the weights in the tree must match the length of weights.

Definition at line 299 of file program.h.

Here is the call graph for this function:

◆ size()

template<PT PType>
int Brush::Program< PType >::size ( bool include_weight = true) const
inline

count the tree size of the program, including the weights in weighted nodes.

Parameters
include_weightwhether to include the node's weight in the count.
Returns
int number of nodes.

Definition at line 102 of file program.h.

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

◆ size_at()

template<PT PType>
int Brush::Program< PType >::size_at ( Iter & top,
bool include_weight = true ) const
inline

count the size of a given subtree, optionally including the weights in weighted nodes. This function is not exposed to the python wrapper.

Parameters
toproot node of the subtree.
include_weightwhether to include the node's weight in the count.
Returns
int number of nodes.

Definition at line 113 of file program.h.

Here is the call graph for this function:

◆ update_weights()

template<ProgramType PType>
void Brush::Program< PType >::update_weights ( const Dataset & d)

Updates the program's weights using non-linear least squares.

Parameters
dthe dataset

Definition at line 495 of file program.h.

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

Member Data Documentation

◆ is_fitted_

template<PT PType>
bool Brush::Program< PType >::is_fitted_

whether fit has been called

Definition at line 67 of file program.h.

◆ program_type

template<PT PType>
constexpr PT Brush::Program< PType >::program_type = PType
staticconstexpr

an enum storing the program type.

Definition at line 52 of file program.h.

◆ SSref

template<PT PType>
std::optional<std::reference_wrapper<SearchSpace> > Brush::Program< PType >::SSref

reference to search space

Definition at line 75 of file program.h.

◆ Tree

template<PT PType>
tree<Node> Brush::Program< PType >::Tree

fitness

the underlying tree

Definition at line 73 of file program.h.


The documentation for this struct was generated from the following file: