ex_fuzzy.rules.MasterRuleBase#
- class ex_fuzzy.rules.MasterRuleBase(rule_base, consequent_names=None, ds_mode=0, allow_unknown=False)[source]#
Bases:
object
This Class encompasses a list of rule bases where each one corresponds to a different class.
- __init__(rule_base, consequent_names=None, ds_mode=0, allow_unknown=False)[source]#
Constructor of the MasterRuleBase class.
- add_rule(rule, consequent)[source]#
Adds a rule to the rule base of the given consequent.
- Parameters:
rule (RuleSimple) – rule to add.
consequent (int) – index of the rule base to add the rule.
- get_rulebase_matrix()[source]#
Returns a list with the rulebases for each antecedent in matrix format.
- Returns:
list with the rulebases for each antecedent in matrix format.
- Return type:
list[array]
- get_scores()[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.
- Return type:
array
- get_weights()[source]#
Returns the weights for each rule in all the rulebases.
- Returns:
array with the weights for each rule in all the rulebases.
- Return type:
array
- compute_firing_strenghts(X, precomputed_truth=None)[source]#
Computes the firing strength of each rule for each sample.
- Parameters:
X – array with the values of the inputs.
precomputed_truth – if not None, the antecedent memberships are already computed. (Used for sped up in genetic algorithms)
- Returns:
array with the firing strength of each rule for each sample.
- Return type:
array
- compute_association_degrees(X, precomputed_truth=None)[source]#
Returns the winning rule for each sample. Takes into account dominance scores if already computed. :param X: array with the values of the inputs. :return: array with the winning rule for each sample.
- winning_rule_predict(X, precomputed_truth=None, out_class_names=False)[source]#
Returns the winning rule for each sample. Takes into account dominance scores if already computed.
- Parameters:
X (array) – array with the values of the inputs.
precomputed_truth – if not None, the antecedent memberships are already computed. (Used for sped up in genetic algorithms)
- Returns:
array with the winning rule for each sample.
- Return type:
array
- explainable_predict(X, out_class_names=False, precomputed_truth=None)[source]#
Returns the predicted class for each sample.
- Parameters:
X (array) – array with the values of the inputs.
out_class_names – if True, the output will be the class names instead of the class index.
- Returns:
np array samples (x 1) with the predicted class.
- Return type:
array
- add_rule_base(rule_base)[source]#
Adds a rule base to the list of rule bases.
- Parameters:
rule_base (RuleBase) – rule base to add.
- print_rules(return_rules=False, bootstrap_results=True)[source]#
Print all the rules for all the consequents.
- Parameters:
autoprint – if True, the rules are printed. If False, the rules are returned as a string.
- get_rules()[source]#
Returns a list with all the rules.
- Returns:
list with all the rules.
- Return type:
- fuzzy_type()[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.
- Return type:
- purge_rules(tolerance=0.001)[source]#
Delete the roles with a dominance score lower than the tolerance.
- Parameters:
tolerance – tolerance to delete the rules.
- __getitem__(item)[source]#
Returns the corresponding rulebase.
- Parameters:
item – index of the rulebase.
- Returns:
the corresponding rulebase.
- Return type:
- __eq__(_MasterRuleBase__value)[source]#
Returns True if the two rule bases are equal.
- Parameters:
__value – object to compare.
- Returns:
True if the two rule bases are equal.
- Return type:
- __call__(X)[source]#
Gives the prediction for each sample (same as winning_rule_predict)
- Parameters:
X (array) – array of dims: samples x features.
- Returns:
vector of predictions, size: samples,
- Return type:
array
- predict(X)[source]#
Gives the prediction for each sample (same as winning_rule_predict)
- Parameters:
X (array) – array of dims: samples x features.
- Returns:
vector of predictions, size: samples,
- Return type:
array