Skip to content

incremental

learn_incremental(environment, learner, inputs, outputs, input_transform=None)

Learn from a incremental environment.

Learn from a incremental environment by incrementally learning from the input-output pairs. The learning process stops when the environment ends.

Parameters:

Name Type Description Default
environment IncrementalEnvironment

The incremental environment.

required
learner SupervisedIncrementalLearner

The supervised incremental learner.

required
inputs list[str]

The input feature names.

required
outputs list[str]

The output feature names.

required
input_transform Transform | None

The transform to apply to the input features.

None

Returns:

Type Description
Model

The model learned from the environment.

Source code in src/flowcean/strategies/incremental.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def learn_incremental(
    environment: IncrementalEnvironment,
    learner: SupervisedIncrementalLearner,
    inputs: list[str],
    outputs: list[str],
    input_transform: Transform | None = None,
) -> Model:
    """Learn from a incremental environment.

    Learn from a incremental environment by incrementally learning from
    the input-output pairs. The learning process stops when the environment
    ends.

    Args:
        environment: The incremental environment.
        learner: The supervised incremental learner.
        inputs: The input feature names.
        outputs: The output feature names.
        input_transform: The transform to apply to the input features.

    Returns:
        The model learned from the environment.
    """
    model = None
    for data in environment:
        input_features = data.select(inputs)
        output_features = data.select(outputs)

        if input_transform is not None:
            if isinstance(input_transform, FitIncremetally):
                input_transform.fit_incremental(input_features)
            input_features = input_transform.apply(input_features)

        model = learner.learn_incremental(input_features, output_features)

    if model is None:
        message = "No data found in environment."
        raise ValueError(message)
    if input_transform is not None:
        return ModelWithTransform(model=model, transform=input_transform)
    return model