• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LearnLib / learnlib / 20198569605

13 Dec 2025 10:10PM UTC coverage: 94.914% (+0.4%) from 94.471%
20198569605

Pull #153

github

web-flow
Merge 6a71fc929 into 879958926
Pull Request #153: Implementation for learning MMLTs, new model for collecting statistics

1823 of 1873 new or added lines in 77 files covered. (97.33%)

1 existing line in 1 file now uncovered.

14258 of 15022 relevant lines covered (94.91%)

1.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/filters/symbol-filters/src/main/java/de/learnlib/filter/symbol/AbstractRandomSymbolFilter.java
1
/* Copyright (C) 2013-2025 TU Dortmund University
2
 * This file is part of LearnLib <https://learnlib.de>.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package de.learnlib.filter.symbol;
17

18
import java.util.Random;
19

20
import de.learnlib.filter.FilterResponse;
21
import de.learnlib.filter.SymbolFilter;
22
import net.automatalib.word.Word;
23

24
/**
25
 * A symbol filter that falsely answers a query with a specified probability.
26
 *
27
 * @param <U>
28
 *         input symbol type of the prefix
29
 * @param <V>
30
 *         input symbol type of the transition label
31
 */
32
public abstract class AbstractRandomSymbolFilter<U, V> extends AbstractTruthfulSymbolFilter<U, V> implements SymbolFilter<U, V> {
33

34
    private final double inaccurateProb;
35
    private final Random random;
36

37
    public AbstractRandomSymbolFilter(double inaccurateProb, Random random) {
38
        this(inaccurateProb, random, valideProbability(inaccurateProb));
1✔
39
    }
1✔
40

41
    // utility constructor to prevent finalizer attacks, see SEI CERT Rule OBJ-11
42
    @SuppressWarnings("PMD.UnusedFormalParameter")
43
    private AbstractRandomSymbolFilter(double inaccurateProb, Random random, boolean validated) {
1✔
44
        this.inaccurateProb = inaccurateProb;
1✔
45
        this.random = random;
1✔
46
    }
1✔
47

48
    private static boolean valideProbability(double inaccurateProb) {
49
        if (inaccurateProb > 1 || inaccurateProb < 0) {
1✔
NEW
50
            throw new IllegalArgumentException("Ratios must be between zero and 1 (inclusive).");
×
51
        }
52
        return true;
1✔
53
    }
54

55
    @Override
56
    public FilterResponse query(Word<U> prefix, V symbol) {
57
        boolean ignorable = isIgnorable(prefix, symbol) == FilterResponse.IGNORE;
1✔
58

59
        // Randomly misclassify:
60
        if (this.random.nextDouble() <= this.inaccurateProb) {
1✔
61
            ignorable = !ignorable;
1✔
62
        }
63

64
        if (ignorable) {
1✔
65
            return FilterResponse.IGNORE;
1✔
66
        } else {
67
            return FilterResponse.ACCEPT;
1✔
68
        }
69
    }
70
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc