Pattern stability analysis#
Pattern Stability Analysis Module for Ex-Fuzzy Library
This module provides comprehensive analysis tools for assessing the stability and consistency of patterns generated by fuzzy classifiers across multiple runs. It evaluates the reliability of rule discovery and the robustness of fuzzy model generation through statistical analysis.
- Main Components:
Pattern frequency analysis: Track occurrence rates of specific rule patterns
Variable usage analysis: Monitor how frequently each variable appears in rules
Stability metrics: Quantitative measures of pattern consistency
Multi-run experiments: Automated execution of multiple classifier runs
Statistical reporting: Comprehensive analysis of pattern stability
- Key Features:
Automated multi-run experiments with configurable parameters
Pattern uniqueness detection and frequency counting
Variable importance analysis across multiple runs
Statistical significance testing for pattern stability
Visualization of pattern occurrence distributions
Integration with multiprocessing for efficient computation
Support for both Type-1 and Type-2 fuzzy systems
The module is essential for validating the reliability of fuzzy rule-based classifiers and ensuring that discovered patterns are consistent and meaningful rather than artifacts of random initialization or data sampling.
- class ex_fuzzy.pattern_stability.pattern_stabilizer(X, y, nRules=30, nAnts=4, fuzzy_type=FUZZY_SETS.t1, tolerance=0.0, class_names=None, n_linguistic_variables=3, verbose=False, linguistic_variables=None, domain=None, n_class=None, runner=1, ds_mode=0, allow_unkown=False, fuzzy_modifiers=False, stratify_by=None)[source]#
Bases:
object
- __init__(X, y, nRules=30, nAnts=4, fuzzy_type=FUZZY_SETS.t1, tolerance=0.0, class_names=None, n_linguistic_variables=3, verbose=False, linguistic_variables=None, domain=None, n_class=None, runner=1, ds_mode=0, allow_unkown=False, fuzzy_modifiers=False, stratify_by=None)[source]#
Inits the optimizer with the corresponding parameters.
- Parameters:
nRules (int) – number of rules to optimize.
nAnts (int) – max number of antecedents to use.
type (fuzzy) – FUZZY_SET enum type in fuzzy_sets module. The kind of fuzzy set used.
tolerance (float) – tolerance for the dominance score of the rules.
n_linguist_variables – number of linguistic variables per antecedent.
verbose – if True, prints the progress of the optimization.
linguistic_variables (list[fuzzyVariable]) – list of fuzzyVariables type. If None (default) the optimization process will init+optimize them.
domain (list[float]) – list of the limits for each variable. If None (default) the classifier will compute them empirically.
n_class (int) – names of the classes in the problem. If None (default) the classifier will compute it empirically.
precomputed_rules – MasterRuleBase object. If not None, the classifier will use the rules in the object and ignore the conflicting parameters.
runner (int) – number of threads to use. If None (default) the classifier will use 1 thread.
stratify_by (str) – string naming additional column to stratify test/train split if desired (e.g. split by participant rather than trial).
- count_unique_patterns(rule_base)[source]#
We will count the number of unique patterns in the rule base. It will also count the number of times each variable is used in the rule base and the record the dominance score of each pattern.
- Parameters:
rule_base (RuleBase) – RuleBase object. The rule base to analyze.
- Return unique_patterns:
dict. The dictionary with the unique patterns and the number of times they appear.
- Return patterns_ds:
dict. The dictionary with the dominance score of each pattern.
- Return var_used:
dict. The dictionary with the number of times each variable is used in the rule base.
- count_unique_patterns_all_classes(mrule_base, class_patterns=None, patterns_dss=None, class_vars=None)[source]#
Counts the number of unique patterns for all classes. It also counts the number of times each variable is used in the rule base and the dominance score of each pattern.
- Parameters:
mrule_base (MasterRuleBase) – MasterRuleBase object. The rule base to analyze.
class_patterns (dict[list]) – dict[list]. The dictionary with the unique patterns for each class. If None, it will be initialized.
patterns_dss (dict[list]) – dict[list]. The dictionary with the dominance score of each pattern for each class. If None, it will be initialized.
class_vars (dict[list]) – dict[list]. The dictionary with the number of times each variable is used in the rule base for each class. If None, it will be initialized.
- Return class_patterns:
dict[list]. The dictionary with the unique patterns for each class.
- Return patterns_dss:
dict[list]. The dictionary with the dominance score of each pattern for each class.
- Return class_vars:
dict[list]. The dictionary with the number of times each variable is used in the rule base for each class.
- get_patterns_scores(n=30, n_gen=10, pop_size=10, test_size=0.33)[source]#
Gets the patterns scores for the generated solutions.
- Parameters:
- Return class_patterns:
dict[list]. The dictionary with the unique patterns for each class.
- Return patterns_dss:
dict[list]. The dictionary with the dominance score of each pattern for each class.
- Return class_vars:
dict[list]. The dictionary with the number of times each variable is used in the rule base for each class.
- Return accuracies:
list. The list with the accuracies of the generated solutions.
- Return rule_bases:
list. The list with the generated rule bases.
- text_report(class_patterns, patterns_dss, class_vars, accuracies, rule_bases, rule_cutoff=5)[source]#
Generates a text report for pattern stability.
- Parameters:
class_patterns (dict) – dict[list]. The dictionary with the unique patterns for each class.
patterns_dss (dict) – dict[list]. The dictionary with the dominance score of each pattern for each class.
class_vars (dict) – dict[list]. The dictionary with the number of times each variable is used in the rule base for each class.
accuracies (list) – list. The list with the accuracies of the generated solutions.
rule_bases (list) – list. The list with the generated rule bases.
rule_cutoff (int) – int. The number of rules to show in the report.
- stability_report(n=10, n_gen=30, pop_size=20, test_size=0.33)[source]#
Generates a stability report for pattern stabilization.
- Parameters:
n (int) – int. The number of solutions to generate.
- Return text_report:
str. The text report for pattern stability.
- pie_chart_basic(var_ix, class_ix)[source]#
Generates a pie chart for the variable usage in the rule bases.
- pie_chart_var(var_ix)[source]#
Generates a pie chart for the variable usage in the rule bases.
- Parameters:
var_ix (int) – int. The index of the variable to analyze.