bootstrap.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_RANDOM_FOREST_BOOTSTRAP_HPP
14 #define MLPACK_METHODS_RANDOM_FOREST_BOOTSTRAP_HPP
15 
16 namespace mlpack {
17 namespace tree {
18 
22 template<bool UseWeights,
23  typename MatType,
24  typename LabelsType,
25  typename WeightsType>
26 void Bootstrap(const MatType& dataset,
27  const LabelsType& labels,
28  const WeightsType& weights,
29  MatType& bootstrapDataset,
30  LabelsType& bootstrapLabels,
31  WeightsType& bootstrapWeights)
32 {
33  bootstrapDataset.set_size(dataset.n_rows, dataset.n_cols);
34  bootstrapLabels.set_size(labels.n_elem);
35  if (UseWeights)
36  bootstrapWeights.set_size(weights.n_elem);
37 
38  // Random sampling with replacement.
39  arma::uvec indices = arma::randi<arma::uvec>(dataset.n_cols,
40  arma::distr_param(0, dataset.n_cols - 1));
41  bootstrapDataset = dataset.cols(indices);
42  bootstrapLabels = labels.cols(indices);
43  if (UseWeights)
44  bootstrapWeights = weights.cols(indices);
45 }
46 
47 } // namespace tree
48 } // namespace mlpack
49 
50 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
void Bootstrap(const MatType &dataset, const LabelsType &labels, const WeightsType &weights, MatType &bootstrapDataset, LabelsType &bootstrapLabels, WeightsType &bootstrapWeights)
Given a dataset, create another dataset via bootstrap sampling, with labels.
Definition: bootstrap.hpp:26