#include <forest.h>
|
| Forest (const uint &n_trees=10, const uint &max_depth=std::numeric_limits< uint >::max(), const uint &min_samples_at_leaf=1, const uint &min_samples_at_node=2, const std::shared_ptr< IDecider > &decider_template=nullptr, const std::shared_ptr< ILeaf > &leaf_manager_template=nullptr, const uint &random_seed=1) |
|
| Forest (std::vector< std::shared_ptr< Tree >> &trees) |
|
| Forest (std::string filename) |
|
Forest * | fit (const Data< MatCRef > &data_v, const Data< MatCRef > &annotation_v, const size_t &num_threads=1, const bool &bootstrap=true, const std::vector< float > &weights=std::vector< float >()) |
|
std::vector< size_t > | get_depths () const |
|
Forest * | fit_dprov (const std::shared_ptr< IDataProvider > &fdata_provider, const bool &bootstrap=true) |
| The fitting function for a forest. More...
|
|
Data< Mat > | predict (const Data< MatCRef > &data_v, const int &num_threads=1, const bool &use_fast_prediction_if_available=true, const bool &predict_proba=false) |
|
Data< Mat > | predict_proba (const Data< MatCRef > &data_v, const int &num_threads=1, const bool &use_fast_prediction_if_available=true) |
|
size_t | get_input_data_dimensions () const |
|
std::shared_ptr< const IDecider > | get_decider () const |
|
std::vector< std::shared_ptr< Tree > > | get_trees () const |
|
void | enable_fast_prediction () |
|
void | disable_fast_prediction () |
|
std::shared_ptr< const ILeaf > | get_leaf_manager () const |
|
std::vector< float > | get_tree_weights () const |
|
void | set_tree_weights (const std::vector< float > &weights) const |
|
void | save (const std::string &filename) const |
|
bool | operator== (const Forest &rhs) const |
|
Standard forest class of the library.
Definition at line 28 of file forest.h.
◆ Forest() [1/3]
forpy::Forest::Forest |
( |
const uint & |
n_trees = 10 , |
|
|
const uint & |
max_depth = std::numeric_limits< uint >::max() , |
|
|
const uint & |
min_samples_at_leaf = 1 , |
|
|
const uint & |
min_samples_at_node = 2 , |
|
|
const std::shared_ptr< IDecider > & |
decider_template = nullptr , |
|
|
const std::shared_ptr< ILeaf > & |
leaf_manager_template = nullptr , |
|
|
const uint & |
random_seed = 1 |
|
) |
| |
- Parameters
-
n_trees | uint>1 The number of trees. |
max_depth | uint > 0 The maximum tree depth, including leafs (up to including). |
min_samples_at_leaf | uint > 0 The minimum number of samples at a leaf (from including). |
min_samples_at_node | uint>=2*min_samples_at_leaf The minimum number of samples at a node (from including). |
decider_template | shared(IDecider) The decider configuration for the trees. |
leaf_manager_template | shared(ILeafManager) The leaf manager template for the trees. |
random_seed | The random seed to use to seed all trees. |
◆ Forest() [2/3]
forpy::Forest::Forest |
( |
std::vector< std::shared_ptr< Tree >> & |
trees | ) |
|
Combines TRAINED trees to a forest. !! Training is not possible any more !!
- Parameters
-
trees | vector(shared(Tree)) The trained trees to combine. |
◆ Forest() [3/3]
forpy::Forest::Forest |
( |
std::string |
filename | ) |
|
Deserializing constructor to load a forest from a file.
- Parameters
-
filename | string The file to load the forest from. |
◆ disable_fast_prediction()
void forpy::Forest::disable_fast_prediction |
( |
| ) |
|
|
inline |
Disable fast prediction for all trees.
Definition at line 183 of file forest.h.
◆ DISALLOW_COPY_AND_ASSIGN()
forpy::Forest::DISALLOW_COPY_AND_ASSIGN |
( |
Forest |
| ) |
|
|
private |
◆ enable_fast_prediction()
void forpy::Forest::enable_fast_prediction |
( |
| ) |
|
|
inline |
Enable fast prediction for all trees.
Definition at line 178 of file forest.h.
◆ fit()
Forest* forpy::Forest::fit |
( |
const Data< MatCRef > & |
data_v, |
|
|
const Data< MatCRef > & |
annotation_v, |
|
|
const size_t & |
num_threads = 1 , |
|
|
const bool & |
bootstrap = true , |
|
|
const std::vector< float > & |
weights = std::vector< float >() |
|
) |
| |
Fit the forest on the given data.
- Parameters
-
data_v | Variant of 2D array, col-major contiguous Col-wise data points. |
annotation_v | Variant of 2D array, row-major contiguous Row-wise annotations. |
num_threads | uint>0 The number of threads to use for fitting. |
bootstrap | bool If set to true, resample the training set for each tree. Default: true. |
weights | vector<float> A vector with positive weights for each sample. |
◆ fit_dprov()
Forest* forpy::Forest::fit_dprov |
( |
const std::shared_ptr< IDataProvider > & |
fdata_provider, |
|
|
const bool & |
bootstrap = true |
|
) |
| |
The fitting function for a forest.
Fits this forest to the data given by the data provider. Releases the GIL in Python!
- Parameters
-
fdata_provider | shared(IDataProvider) The data provider for the fitting process. |
bootstrap | bool Whether to resample the training set for each tree. Default: true. |
◆ get_decider()
std::shared_ptr<const IDecider> forpy::Forest::get_decider |
( |
| ) |
const |
|
inline |
Get the decider of the first tree.
Definition at line 170 of file forest.h.
◆ get_depths()
std::vector<size_t> forpy::Forest::get_depths |
( |
| ) |
const |
|
inline |
Get the depths of all trees.
The depth is defined to be 0 for an "empty" tree (only a leaf/root node) and as the amount of edges on the longest path in the tree otherwise.
Definition at line 94 of file forest.h.
◆ get_input_data_dimensions()
size_t forpy::Forest::get_input_data_dimensions |
( |
| ) |
const |
|
inline |
Get the required input data dimension.
Definition at line 165 of file forest.h.
◆ get_leaf_manager()
std::shared_ptr<const ILeaf> forpy::Forest::get_leaf_manager |
( |
| ) |
const |
|
inline |
Gets the leaf manager of the first tree.
Definition at line 188 of file forest.h.
◆ get_tree_weights()
std::vector<float> forpy::Forest::get_tree_weights |
( |
| ) |
const |
|
inline |
Get all tree weights.
Definition at line 193 of file forest.h.
◆ get_trees()
std::vector<std::shared_ptr<Tree> > forpy::Forest::get_trees |
( |
| ) |
const |
|
inline |
Get the tree vector.
Definition at line 175 of file forest.h.
◆ operator==()
bool forpy::Forest::operator== |
( |
const Forest & |
rhs | ) |
const |
|
inline |
◆ predict()
Data<Mat> forpy::Forest::predict |
( |
const Data< MatCRef > & |
data_v, |
|
|
const int & |
num_threads = 1 , |
|
|
const bool & |
use_fast_prediction_if_available = true , |
|
|
const bool & |
predict_proba = false |
|
) |
| |
|
inline |
Predicts new data points.
- Parameters
-
data_v | Variant of 2D array, col-major contiguous The data predict with one sample per row. |
num_threads | int>=0 The number of threads to use for prediction. The number of samples should be at least three times larger than the number of threads to observe very good parallelization behaviour. If 0, then all available hardware threads are used. Default: 1. |
use_fast_prediction_if_available | bool Use or construct a fast prediction tree (a summarized version of the tree that is particularly fast to index) for making the predictions. Default: true. |
predict_proba | bool Whether or not to provide the distribution of results instead of the mode. Default: false. |
Definition at line 140 of file forest.h.
◆ predict_proba()
Data<Mat> forpy::Forest::predict_proba |
( |
const Data< MatCRef > & |
data_v, |
|
|
const int & |
num_threads = 1 , |
|
|
const bool & |
use_fast_prediction_if_available = true |
|
) |
| |
|
inline |
Predict the distribution of results.
Definition at line 158 of file forest.h.
◆ save()
void forpy::Forest::save |
( |
const std::string & |
filename | ) |
const |
Saves the forest to a file with the specified name.
- Parameters
-
filename | string The filename to use. |
◆ serialize()
template<class Archive >
void forpy::Forest::serialize |
( |
Archive & |
ar, |
|
|
const uint & |
|
|
) |
| |
|
inlineprivate |
◆ set_tree_weights()
void forpy::Forest::set_tree_weights |
( |
const std::vector< float > & |
weights | ) |
const |
|
inline |
Set the tree weights.
Definition at line 202 of file forest.h.
◆ cereal::access
friend class cereal::access |
|
friend |
◆ operator<<
std::ostream& operator<< |
( |
std::ostream & |
stream, |
|
|
const Forest & |
self |
|
) |
| |
|
friend |
◆ random_seed
uint forpy::Forest::random_seed |
|
private |
◆ trees
std::vector<std::shared_ptr<Tree> > forpy::Forest::trees |
|
private |
The documentation for this class was generated from the following file:
- /Users/classner/git/forpy/include/forpy/forest.h