org.apache.ignite.ml.composition.bagging

## Class BaggedTrainer<L>

- java.lang.Object
- - org.apache.ignite.ml.trainers.DatasetTrainer<BaggedModel,L>
  - - org.apache.ignite.ml.composition.bagging.BaggedTrainer<L>

- Type Parameters:
    `L` - Type of labels.

      public class BaggedTrainer<L>
      extends DatasetTrainer<BaggedModel,L>

  Trainer encapsulating logic of bootstrap aggregating (bagging). This trainer accepts some other trainer and returns bagged version of it. Resulting model consists of submodels results of which are aggregated by a specified aggregator.

  Bagging is done on both samples and features (Samples bagging, Features bagging).

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.ignite.ml.trainers.DatasetTrainer

      `DatasetTrainer.EmptyDatasetException`

  - ### Field Summary

    - ### Fields inherited from class org.apache.ignite.ml.trainers.DatasetTrainer

      `envBuilder, environment`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BaggedTrainer(DatasetTrainer<? extends IgniteModel,L> tr, PredictionsAggregator aggregator, int ensembleSize, double subsampleRatio, int featuresVectorSize, int featureSubspaceDim)` Construct instance of this class with given parameters.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `<K,V> BaggedModel` | `fitWithInitializedDeployingContext(DatasetBuilder<K,V> datasetBuilder, Preprocessor<K,V> preprocessor)` Trains model based on the specified data.
    `static int[]` | `getMapping(int featuresVectorSize, int maximumFeaturesCntPerMdl, long seed)` Get mapping R^featuresVectorSize -> R^maximumFeaturesCntPerMdl.
    `boolean` | `isUpdateable(BaggedModel mdl)` This method is never called, instead of constructing logic of update from `DatasetTrainer.updateModel(M, org.apache.ignite.ml.dataset.DatasetBuilder<K, V>, org.apache.ignite.ml.preprocessing.Preprocessor<K, V>)` in this class we explicitly override update method.
    `<K,V> BaggedModel` | `update(BaggedModel mdl, DatasetBuilder<K,V> datasetBuilder, Preprocessor<K,V> preprocessor)` Gets state of model in arguments, compare it with training parameters of trainer and if they are fit then trainer updates model in according to new data and return new model.
    `protected <K,V> BaggedModel` | `updateModel(BaggedModel mdl, DatasetBuilder<K,V> datasetBuilder, Preprocessor<K,V> preprocessor)` This method is never called, instead of constructing logic of update from `DatasetTrainer.isUpdateable(M)` and `DatasetTrainer.updateModel(M, org.apache.ignite.ml.dataset.DatasetBuilder<K, V>, org.apache.ignite.ml.preprocessing.Preprocessor<K, V>)` in this class we explicitly override update method.
    `BaggedTrainer<L>` | `withEnvironmentBuilder(LearningEnvironmentBuilder envBuilder)` Changes learning Environment.

    - ### Methods inherited from class org.apache.ignite.ml.trainers.DatasetTrainer

      `fit, fit, fit, fit, fit, fit, getLastTrainedModelOrThrowEmptyDatasetException, identityTrainer, learningEnvironment, update, update, update, update, withConvertedLabels`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### BaggedTrainer

          public BaggedTrainer(DatasetTrainer<? extends IgniteModel,L> tr,
                               PredictionsAggregator aggregator,
                               int ensembleSize,
                               double subsampleRatio,
                               int featuresVectorSize,
                               int featureSubspaceDim)

      Construct instance of this class with given parameters.
      Parameters:
        `tr` - Trainer for making bagged.
        `aggregator` - Aggregator of models.
        `ensembleSize` - Size of ensemble.
        `subsampleRatio` - Ratio (subsample size) / (initial dataset size).
        `featuresVectorSize` - Dimensionality of feature vector.
        `featureSubspaceDim` - Dimensionality of feature subspace.

  - ### Method Detail

    - #### getMapping

          public static int[] getMapping(int featuresVectorSize,
                                         int maximumFeaturesCntPerMdl,
                                         long seed)

      Get mapping R^featuresVectorSize -> R^maximumFeaturesCntPerMdl.
      Parameters:
        `featuresVectorSize` - Features vector size (Dimension of initial space).
        `maximumFeaturesCntPerMdl` - Dimension of target space.
        `seed` - Seed.
      Returns:
        Mapping R^featuresVectorSize -> R^maximumFeaturesCntPerMdl.

    - #### fitWithInitializedDeployingContext

          public <K,V> BaggedModel fitWithInitializedDeployingContext(DatasetBuilder<K,V> datasetBuilder,
                                                                      Preprocessor<K,V> preprocessor)

      Trains model based on the specified data.
      Specified by:
        `fitWithInitializedDeployingContext` in class `DatasetTrainer<BaggedModel,L>`
      Type Parameters:
        `K` - Type of a key in `upstream` data.
        `V` - Type of a value in `upstream` data.
      Parameters:
        `datasetBuilder` - Dataset builder.
        `preprocessor` - Extractor of `UpstreamEntry` into `LabeledVector`.
      Returns:
        Model.

    - #### update

          public <K,V> BaggedModel update(BaggedModel mdl,
                                          DatasetBuilder<K,V> datasetBuilder,
                                          Preprocessor<K,V> preprocessor)

      Gets state of model in arguments, compare it with training parameters of trainer and if they are fit then trainer updates model in according to new data and return new model. In other case trains new model.
      Overrides:
        `update` in class `DatasetTrainer<BaggedModel,L>`
      Type Parameters:
        `K` - Type of a key in `upstream` data.
        `V` - Type of a value in `upstream` data.
      Parameters:
        `mdl` - Learned model.
        `datasetBuilder` - Dataset builder.
        `preprocessor` - Extractor of `UpstreamEntry` into `LabeledVector`.
      Returns:
        Updated model.

    - #### withEnvironmentBuilder

          public BaggedTrainer<L> withEnvironmentBuilder(LearningEnvironmentBuilder envBuilder)

      Changes learning Environment.
      Overrides:
        `withEnvironmentBuilder` in class `DatasetTrainer<BaggedModel,L>`
      Parameters:
        `envBuilder` - Learning environment builder.

    - #### isUpdateable

          public boolean isUpdateable(BaggedModel mdl)

      This method is never called, instead of constructing logic of update from `DatasetTrainer.updateModel(M, org.apache.ignite.ml.dataset.DatasetBuilder<K, V>, org.apache.ignite.ml.preprocessing.Preprocessor<K, V>)` in this class we explicitly override update method.
      Specified by:
        `isUpdateable` in class `DatasetTrainer<BaggedModel,L>`
      Parameters:
        `mdl` - Model.
      Returns:
        True if current critical for training parameters correspond to parameters from last training.

    - #### updateModel

          protected <K,V> BaggedModel updateModel(BaggedModel mdl,
                                                  DatasetBuilder<K,V> datasetBuilder,
                                                  Preprocessor<K,V> preprocessor)

      This method is never called, instead of constructing logic of update from `DatasetTrainer.isUpdateable(M)` and `DatasetTrainer.updateModel(M, org.apache.ignite.ml.dataset.DatasetBuilder<K, V>, org.apache.ignite.ml.preprocessing.Preprocessor<K, V>)` in this class we explicitly override update method.
      Specified by:
        `updateModel` in class `DatasetTrainer<BaggedModel,L>`
      Type Parameters:
        `K` - Type of a key in `upstream` data.
        `V` - Type of a value in `upstream` data.
      Parameters:
        `mdl` - Model.
        `datasetBuilder` - Dataset builder.
        `preprocessor` - Extractor of `UpstreamEntry` into `LabeledVector`.
      Returns:
        Updated model.

2022 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.12.0
Release Date | : January 10 2022