org.apache.ignite.ml.composition.combinators.sequential

## Class TrainersSequentialComposition<I,O1,O2,L>

- java.lang.Object
- - org.apache.ignite.ml.trainers.DatasetTrainer<ModelsSequentialComposition<I,O1,O2>,L>
  - - org.apache.ignite.ml.composition.combinators.sequential.TrainersSequentialComposition<I,O1,O2,L>

- Type Parameters:
    `I` - Type of input of model produced by first trainer.
    `O1` - Type of output of model produced by first trainer.
    `O2` - Type of output of model produced by second trainer.
    `L` - Type of labels.

      public class TrainersSequentialComposition<I,O1,O2,L>
      extends DatasetTrainer<ModelsSequentialComposition<I,O1,O2>,L>

  Sequential composition of trainers. Sequential composition of trainers is itself trainer which produces `ModelsSequentialComposition`. Training is done in following fashion:

           1. First trainer is trained and `mdl1` is produced.
           2. From `mdl1` DatasetMapping is constructed. This mapping `dsM` encapsulates dependency between first
           training result and second trainer.
           3. Second trainer is trained using dataset acquired from application `dsM` to original dataset; `mdl2` is produced.
           4. `mdl1` and `mdl2` are composed into ModelsSequentialComposition.

- - ### Nested Class Summary

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

      `DatasetTrainer.EmptyDatasetException`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected IgniteBiFunction<Integer,? super IgniteModel<I,O1>,IgniteFunction<LabeledVector<L>,LabeledVector<L>>>` | `datasetMapping` Dataset mapping.

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

      `envBuilder, environment`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TrainersSequentialComposition(DatasetTrainer<? extends IgniteModel<I,O1>,L> tr1, DatasetTrainer<? extends IgniteModel<O1,O2>,L> tr2, IgniteBiFunction<Integer,? super IgniteModel<I,O1>,IgniteFunction<LabeledVector<L>,LabeledVector<L>>> datasetMapping)` Create sequential composition of two trainers.
    `TrainersSequentialComposition(DatasetTrainer<? extends IgniteModel<I,O1>,L> tr1, DatasetTrainer<? extends IgniteModel<O1,O2>,L> tr2, IgniteFunction<? super IgniteModel<I,O1>,IgniteFunction<LabeledVector<L>,LabeledVector<L>>> datasetMapping)` Construct sequential composition of given two trainers.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `<K,V> ModelsSequentialComposition<I,O1,O2>` | `fitWithInitializedDeployingContext(DatasetBuilder<K,V> datasetBuilder, Preprocessor<K,V> preprocessor)` Trains model based on the specified data.
    `boolean` | `isUpdateable(ModelsSequentialComposition<I,O1,O2> mdl)` 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.
    `static <I,O,L> TrainersSequentialComposition<I,O,O,L>` | `ofSame(DatasetTrainer<? extends IgniteModel<I,O>,L> tr, IgniteBiFunction<Integer,? super IgniteModel<I,O>,IgniteFunction<LabeledVector<L>,LabeledVector<L>>> datasetMapping, IgniteBiPredicate<Integer,IgniteModel<I,O>> shouldStop, IgniteFunction<O,I> out2In)` Construct sequential composition of same trainers.
    `DatasetTrainer<IgniteModel<I,O2>,L>` | `unsafeSimplyTyped()` Performs coersion of this trainer to `DatasetTrainer<IgniteModel<I, O2>, L>`.
    `<K,V> ModelsSequentialComposition<I,O1,O2>` | `update(ModelsSequentialComposition<I,O1,O2> 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> ModelsSequentialComposition<I,O1,O2>` | `updateModel(ModelsSequentialComposition<I,O1,O2> mdl, DatasetBuilder<K,V> datasetBuilder, Preprocessor<K,V> preprocessor)` This method is never called, instead of constructing logic of update from `DatasetTrainer.isUpdateable(IgniteModel)` and `DatasetTrainer.updateModel(IgniteModel, DatasetBuilder, Preprocessor)` in this class we explicitly override update method.

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

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

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

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

- - ### Field Detail

    - #### datasetMapping

          protected IgniteBiFunction<Integer,? super IgniteModel<I,O1>,IgniteFunction<LabeledVector<L>,LabeledVector<L>>> datasetMapping

      Dataset mapping.

  - ### Constructor Detail

    - #### TrainersSequentialComposition

          public TrainersSequentialComposition(DatasetTrainer<? extends IgniteModel<I,O1>,L> tr1,
                                               DatasetTrainer<? extends IgniteModel<O1,O2>,L> tr2,
                                               IgniteFunction<? super IgniteModel<I,O1>,IgniteFunction<LabeledVector<L>,LabeledVector<L>>> datasetMapping)

      Construct sequential composition of given two trainers.
      Parameters:
        `tr1` - First trainer.
        `tr2` - Second trainer.
        `datasetMapping` - Dataset mapping.

    - #### TrainersSequentialComposition

          public TrainersSequentialComposition(DatasetTrainer<? extends IgniteModel<I,O1>,L> tr1,
                                               DatasetTrainer<? extends IgniteModel<O1,O2>,L> tr2,
                                               IgniteBiFunction<Integer,? super IgniteModel<I,O1>,IgniteFunction<LabeledVector<L>,LabeledVector<L>>> datasetMapping)

      Create sequential composition of two trainers.
      Parameters:
        `tr1` - First trainer.
        `tr2` - Second trainer.
        `datasetMapping` - Dataset mapping containing dependence between first and second trainer.

  - ### Method Detail

    - #### ofSame

          public static <I,O,L> TrainersSequentialComposition<I,O,O,L> ofSame(DatasetTrainer<? extends IgniteModel<I,O>,L> tr,
                                                                              IgniteBiFunction<Integer,? super IgniteModel<I,O>,IgniteFunction<LabeledVector<L>,LabeledVector<L>>> datasetMapping,
                                                                              IgniteBiPredicate<Integer,IgniteModel<I,O>> shouldStop,
                                                                              IgniteFunction<O,I> out2In)

      Construct sequential composition of same trainers.
      Type Parameters:
        `I` - Type of input of model produced by trainer.
        `O` - Type of output of model produced by trainer.
        `L` - Type of labels for trainer.
      Parameters:
        `tr` - Trainer used for sequential composition.
        `datasetMapping` - Dataset mapping.
        `shouldStop` - Predicate depending on index and model produced by the last trainer indicating if composition process should stop
        `out2In` - Function for conversion of output of model into input of next model.
      Returns:
        Sequential composition of same trainers.

    - #### fitWithInitializedDeployingContext

          public <K,V> ModelsSequentialComposition<I,O1,O2> fitWithInitializedDeployingContext(DatasetBuilder<K,V> datasetBuilder,
                                                                                               Preprocessor<K,V> preprocessor)

      Trains model based on the specified data.
      Specified by:
        `fitWithInitializedDeployingContext` in class `DatasetTrainer<ModelsSequentialComposition<I,O1,O2>,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.

    - #### updateModel

          protected <K,V> ModelsSequentialComposition<I,O1,O2> updateModel(ModelsSequentialComposition<I,O1,O2> mdl,
                                                                           DatasetBuilder<K,V> datasetBuilder,
                                                                           Preprocessor<K,V> preprocessor)

      This method is never called, instead of constructing logic of update from `DatasetTrainer.isUpdateable(IgniteModel)` and `DatasetTrainer.updateModel(IgniteModel, DatasetBuilder, Preprocessor)` in this class we explicitly override update method.
      Specified by:
        `updateModel` in class `DatasetTrainer<ModelsSequentialComposition<I,O1,O2>,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.

    - #### update

          public <K,V> ModelsSequentialComposition<I,O1,O2> update(ModelsSequentialComposition<I,O1,O2> 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<ModelsSequentialComposition<I,O1,O2>,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.

    - #### isUpdateable

          public boolean isUpdateable(ModelsSequentialComposition<I,O1,O2> mdl)

      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:
        `isUpdateable` in class `DatasetTrainer<ModelsSequentialComposition<I,O1,O2>,L>`
      Parameters:
        `mdl` - Model.
      Returns:
        True if current critical for training parameters correspond to parameters from last training.

    - #### unsafeSimplyTyped

          public DatasetTrainer<IgniteModel<I,O2>,L> unsafeSimplyTyped()

      Performs coersion of this trainer to `DatasetTrainer<IgniteModel<I, O2>, L>`.
      Returns:
        Trainer coerced to `DatasetTrainer<IgniteModel<I, O>, L>`.

2020 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.9.1
Release Date | : December 9 2020