Temporal fuzzy sets
Expansion of the base fuzzy sets, adding temporal fuzzy sets.
Contains functions to model the temporal fuzzy sets, temporal fuzzy variables and temporal rule bases. It also contains functions to evaluate the fuzzy rulebases obtained.
- ex_fuzzy.temporal.NEW_FUZZY_SETS
alias of
FUZZY_SETS
- ex_fuzzy.temporal.TMP_FUZZY_SETS
alias of
NEW_FUZZY_SETS
- class ex_fuzzy.temporal.TemporalFuzzyRulesClassifier(nRules: int = 30, nAnts: int = 4, fuzzy_type: FUZZY_SETS = None, tolerance: float = 0.0, n_linguistic_variables: int = 0, verbose=False, linguistic_variables: list[fuzzyVariable] = None, domain: list[float] = None, n_class: int = None, precomputed_rules: MasterRuleBase = None, runner: int = 1)[source]
Bases:
BaseFuzzyRulesClassifier
Class that is used as a classifier for a fuzzy rule based system with time dependencies. Supports precomputed and optimization of the linguistic variables.
- fit(X: array, y: array, n_gen: int = 50, pop_size: int = 10, time_moments: array = None, checkpoints: int = 0)[source]
Fits a fuzzy rule based classifier using a genetic algorithm to the given data.
- Parameters:
X – numpy array samples x features
y – labels. integer array samples (x 1)
n_gen – integer. Number of generations to run the genetic algorithm.
pop_size – integer. Population size for each gneration.
time_moments – array of integers. Time moments associated to each sample (when temporal dependencies are present)
- Returns:
None. The classifier is fitted to the data.
- forward(X: array, time_moments: list[int] = None) array [source]
Returns the predicted class for each sample.
- Parameters:
X – np array samples x features.
time_moments – list of integers. Time moments associated to each sample (when temporal dependencies are present)
- Returns:
np array samples (x 1) with the predicted class.
- ex_fuzzy.temporal.eval_temporal_fuzzy_model(fl_classifier: BaseFuzzyRulesClassifier, X_train: array, y_train: array, X_test: array, y_test: array, time_moments: list[int] = None, test_time_moments: list[int] = None, plot_rules=True, print_rules=True, plot_partitions=True, return_rules=False, print_accuracy=True, print_matthew=True) None [source]
Function that evaluates a fuzzy rule based model. It also plots the rules and the fuzzy partitions.
- Parameters:
fl_classifier – Fuzzy rule based model.
X_train – Training data.
y_train – Training labels.
X_test – Test data.
y_test – Test labels.
plot_rules – If True, it plots the rules.
print_rules – If True, it prints the rules.
plot_partitions – If True, it plots the fuzzy partitions.
- Returns:
None
- class ex_fuzzy.temporal.temporalFS(std_fuzzy_set: FS, conditional_variable: array)[source]
Bases:
FS
Class to implement temporal fuzzy sets.
- fix_time(time: int) None [source]
Fixes the time of the temporal fuzzy set.
- Parameters:
time – int. Time moment to fix.
- Returns:
FS. Fuzzy set with the fixed time.
- inside_type() FUZZY_SETS [source]
Returns the type of the og fuzzy set computed before the time dependency.
- class ex_fuzzy.temporal.temporalFuzzyVariable(name: str, fuzzy_sets: list[temporalFS])[source]
Bases:
fuzzyVariable
Class to implement a temporal fuzzy variable.
- compute_memberships(x: array, time: int = None) dict [source]
Computes the membership to each of the FS in the fuzzy variables.
- Parameters:
x – numeric value or array. Computes the membership to each of the IVFS in the fuzzy variables.
time – int. Time moment to compute the membership.
- Returns:
list of floats. Membership to each of the FS in the fuzzy variables.
- class ex_fuzzy.temporal.temporalMasterRuleBase(rule_base: list[MasterRuleBase], time_step_names: list[str] = None)[source]
Bases:
MasterRuleBase
This class is a temporal extension of the MasterRuleBase class. It includes a list of rule bases for each time step.
- add_rule(rule: RuleSimple, consequent: int, time_step: int) None [source]
Adds a rule to the rule base of the given consequent.
- Parameters:
rule – rule to add.
consequent – index of the rule base to add the rule.
time_step – time step of the rule base to add the rule.
- add_rule_base(rule_base: RuleBase, time: int) None [source]
Adds a rule base to the list of rule bases.
- Parameters:
rule_base – rule base to add.
- compute_firing_strenghts(X: array, time_moments: list[int], precomputed_truth=None) array [source]
Computes the firing strength of each rule for each sample.
- Parameters:
X – array with the values of the inputs.
- Returns:
array with the firing strength of each rule for each sample.
- fuzzy_type() FUZZY_SETS [source]
Returns the correspoing type of the RuleBase using the enum type in the fuzzy_sets module.
- Returns:
the corresponding fuzzy set type of the RuleBase.
- get_consequents() list[int] [source]
Returns a list with the consequents of each rule base.
- Returns:
list with the consequents of each rule base.
- get_rulebase_matrix() list[array] [source]
Returns a list with the rulebases for each antecedent in matrix format.
- Returns:
list with the rulebases for each antecedent in matrix format.
- get_rules() list[RuleSimple] [source]
Returns a list with all the rules.
- Returns:
list with all the rules.
- get_scores() array [source]
Returns the dominance score for each rule in all the rulebases.
- Returns:
array with the dominance score for each rule in all the rulebases.