Skip to content

ddti_generator

DDTIGenerator(model, *, n_testinputs, test_coverage_criterium, dataset=None, specs_file=None, classification=False, inverse_alloc=False, epsilon=0.5, performance_threshold=0.3, sample_limit=50000, n_predictions=50, max_depth=5, hoeffding_tree_extra_params=None)

Bases: TestcaseGenerator

Generates test inputs considering decision boundaries.

Methods:

save_hoeffding_tree() Saves the generated Hoeffding tree to a file.

print_eqclasses() Prints the equivalence classes and their test input counts.

print_testplans() Prints the test plans (intervals used to sample test inputs).

print_hoeffding_tree() Prints the Hoeffding tree structure as a PNG.

Initialize the stochastic generator.

Parameters:

Name Type Description Default
model Model

The trained Flowcean model.

required
n_testinputs int

Number of test inputs to generate.

required
test_coverage_criterium str

Test coverage strategy identifier.

required
dataset DataFrame | None

Polars DataFrame containing the original dataset. Either the dataset or the specs_file must be provided.

None
specs_file Path | None

Path to a file containing feature specifications. If you provide a dataset containing system inputs and outputs that already encodes the necessary specifications, then you do not need to supply a separate system specification file.

None
classification bool

Whether the task is a classification problem.

False
inverse_alloc bool

If True, allocate more tests to lower-priority equivalence classes.

False
epsilon float

Interval offset used for boundary value analysis.

0.5
performance_threshold float

Minimum performance needed before exporting the Hoeffding Tree.

0.3
sample_limit int

Maximum number of samples used to train the Hoeffding Tree.

50000
n_predictions int

Number of consecutive correct predictions needed before exporting the Hoeffding Tree.

50
max_depth int

Maximum depth of the Hoeffding Tree.

5
hoeffding_tree_extra_params dict[str, Any] | None

Extra keyword arguments forwarded to the Hoeffding Tree trainer.

None
Source code in src/flowcean/testing/generator/ddti_generator.py
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def __init__(
    self,
    model: Model,
    *,
    n_testinputs: int,
    test_coverage_criterium: str,
    dataset: pl.DataFrame | None = None,
    specs_file: Path | None = None,
    classification: bool = False,
    inverse_alloc: bool = False,
    epsilon: float = 0.5,
    performance_threshold: float = 0.3,
    sample_limit: int = 50000,
    n_predictions: int = 50,
    max_depth: int = 5,
    hoeffding_tree_extra_params: dict[str, Any] | None = None,
) -> None:
    """Initialize the stochastic generator.

    Args:
        model: The trained Flowcean model.
        n_testinputs: Number of test inputs to generate.
        test_coverage_criterium: Test coverage strategy identifier.
        dataset: Polars DataFrame containing the original dataset.
            Either the dataset or the specs_file must be provided.
        specs_file: Path to a file containing feature specifications.
            If you provide a dataset containing system inputs and
            outputs that already encodes the necessary specifications,
            then you do not need to supply a separate system
            specification file.
        classification: Whether the task is a classification problem.
        inverse_alloc: If True, allocate more tests to lower-priority
            equivalence classes.
        epsilon: Interval offset used for boundary value analysis.
        performance_threshold: Minimum performance needed before
            exporting the Hoeffding Tree.
        sample_limit: Maximum number of samples used to train the
            Hoeffding Tree.
        n_predictions: Number of consecutive correct predictions needed
            before exporting the Hoeffding Tree.
        max_depth: Maximum depth of the Hoeffding Tree.
        hoeffding_tree_extra_params: Extra keyword arguments forwarded
            to the Hoeffding Tree trainer.
    """
    super().__init__()
    self.n_testinputs = n_testinputs
    self.seed = get_seed()

    self.test_pipeline = TestPipeline(
        model,
        dataset=dataset,
        specs_file=specs_file,
        classification=classification,
        n_testinputs=self.n_testinputs,
        test_coverage_criterium=test_coverage_criterium,
        inverse_alloc=inverse_alloc,
        epsilon=epsilon,
        seed=self.seed,
        performance_threshold=performance_threshold,
        sample_limit=sample_limit,
        n_predictions=n_predictions,
        max_depth=max_depth,
        hoeffding_tree_extra_params=hoeffding_tree_extra_params,
    )
    self.data = DataFrame(self.test_pipeline.execute())
    self.reset()