ex_fuzzy.rules.RuleBase#
- class ex_fuzzy.rules.RuleBase(antecedents, rules, consequent=None, tnorm=<function prod>)[source]#
Bases:
object
Class optimized to work with multiple rules at the same time. Right now supports only one consequent. (Solution: use one rulebase per consequent to study)
- __init__(antecedents, rules, consequent=None, tnorm=<function prod>)[source]#
Creates a rulebase with the given antecedents, rules and consequent.
- Parameters:
antecedents (list[fuzzyVariable]) – list of fuzzy sets.
rules (list[RuleSimple]) – list of rules.
consequent (fuzzyVariable) – fuzzy set.
tnorm – t-norm to use in the inference process.
fuzzy_modifiers – array with the fuzzy modifiers for each rule. If None, no modifiers are used. (Fuzzy modifiers are modifiers to the antecedent memberships, also known as linguistic hedges). Only exponentiation is supported. (x**a, being a the modifier in the matrix). Defaults to None. They can also be specified in the RuleSimple list of rules.
Methods
__init__
(antecedents, rules[, consequent, tnorm])Creates a rulebase with the given antecedents, rules and consequent.
add_rule
(new_rule)Adds a new rule to the rulebase.
add_rules
(new_rules)Adds a list of new rules to the rulebase.
Returns a list of of dictionaries that contains the memberships for each x value to the ith antecedents, nth linguistic variable.
compute_rule_antecedent_memberships
(x[, ...])Computes the antecedent truth value of an input array.
copy
()Creates a copy of the RuleBase.
delete_rule_duplicates
(list_rules)forward
(x)Computes the deffuzified output of the fl inference system.
Returns the corresponding type of the RuleBase using the enum type in the fuzzy_sets module.
Returns a matrix with the antecedents values for each rule.
Returns the list of rules in the rulebase.
Returns an array with the dominance score for each rule.
Returns an array with the weights for each rule.
inference
(x)Computes the fuzzy output of the fl inference system.
Returns the number of linguistic variables in the rule base.
Prints the bootstrap results for each rule.
print_rules
([return_rules, bootstrap_results])Print the rules from the rule base.
prune_bad_rules
([tolerance])Delete the rules from the rule base that do not have a dominance score superior to the threshold or have 0 accuracy in the training set.
remove_rule
(ix)Removes the rule in the given index.
remove_rules
(delete_list)Removes the rules in the given list of indexes.
scores
()Returns the dominance score for each rule.
- __init__(antecedents, rules, consequent=None, tnorm=<function prod>)[source]#
Creates a rulebase with the given antecedents, rules and consequent.
- Parameters:
antecedents (list[fuzzyVariable]) – list of fuzzy sets.
rules (list[RuleSimple]) – list of rules.
consequent (fuzzyVariable) – fuzzy set.
tnorm – t-norm to use in the inference process.
fuzzy_modifiers – array with the fuzzy modifiers for each rule. If None, no modifiers are used. (Fuzzy modifiers are modifiers to the antecedent memberships, also known as linguistic hedges). Only exponentiation is supported. (x**a, being a the modifier in the matrix). Defaults to None. They can also be specified in the RuleSimple list of rules.
- add_rules(new_rules)[source]#
Adds a list of new rules to the rulebase.
- Parameters:
new_rules (list[RuleSimple]) – list of rules to add.
- remove_rule(ix)[source]#
Removes the rule in the given index. :param ix: index of the rule to remove.
- get_scores()[source]#
Returns an array with the dominance score for each rule. (Must been already computed by an evalRule object)
- get_weights()[source]#
Returns an array with the weights for each rule. (Different from dominance scores: must been already computed by an optimization algorithm)
- compute_antecedents_memberships(x)[source]#
Returns a list of of dictionaries that contains the memberships for each x value to the ith antecedents, nth linguistic variable. x must be a vector (only one sample)
- compute_rule_antecedent_memberships(x, scaled=False, antecedents_memberships=None)[source]#
Computes the antecedent truth value of an input array.
Return an array in shape samples x rules (x 2) (last is iv dimension)
- Parameters:
x (array) – array with the values of the inputs.
scaled – if True, the memberships are scaled according to their sums for each sample.
- Returns:
array with the memberships of the antecedents for each rule.
- Return type:
array
- print_rules(return_rules=False, bootstrap_results=True)[source]#
Print the rules from the rule base.
- Parameters:
return_rules (bool) – if True, the rules are returned as a string.
- abstract inference(x)[source]#
Computes the fuzzy output of the fl inference system.
Return an array in shape samples x 2 (last is iv dimension)
- Parameters:
x (array) – array with the values of the inputs.
- Returns:
array with the memberships of the consequents for each rule.
- Return type:
array
- abstract forward(x)[source]#
Computes the deffuzified output of the fl inference system.
Return a vector of size (samples, )
- Parameters:
x (array) – array with the values of the inputs.
- Returns:
array with the deffuzified output.
- Return type:
array
- abstract fuzzy_type()[source]#
Returns the corresponding type of the RuleBase using the enum type in the fuzzy_sets module.
- Returns:
the type of fuzzy set used in the RuleBase.
- Return type:
- prune_bad_rules(tolerance=0.01)[source]#
Delete the rules from the rule base that do not have a dominance score superior to the threshold or have 0 accuracy in the training set.
- Parameters:
tolerance – threshold for the dominance score.
- scores()[source]#
Returns the dominance score for each rule.
- Returns:
array with the dominance score for each rule.
- Return type:
array
- __getitem__(item)[source]#
Returns the corresponding rulebase.
- Parameters:
item (int) – index of the rule.
- Returns:
the corresponding rule.
- Return type:
- __setitem__(key, value)[source]#
Set the corresponding rule.
- Parameters:
key (int) – index of the rule.
value (RuleSimple) – new rule.