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.

Parameters:

rule_base (list[RuleBase]) – list of rule bases.

rename_cons(consequent_names)[source]#

Renames the consequents of the rule base.

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_consequents()[source]#

Returns a list with the consequents of each rule base.

Returns:

list with the consequents of each rule base.

Return type:

list[int]

get_consequents_names()[source]#

Returns a list with the names of the consequents.

Returns:

list with the names of the consequents.

Return type:

list[str]

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.

print_rule_bootstrap_results()[source]#

Prints the bootstrap results for each rule.

get_rules()[source]#

Returns a list with all the rules.

Returns:

list with all the rules.

Return type:

list[RuleSimple]

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:

FUZZY_SETS

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:

RuleBase

__len__()[source]#

Returns the number of rule bases.

__str__()[source]#

Returns a string with the rules for each consequent.

__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:

bool

__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

get_rulebases()[source]#

Returns a list with all the rules.

Returns:

list

Return type:

list[RuleBase]

n_linguistic_variables()[source]#

Returns the number of linguistic variables in the rule base.

get_antecedents()[source]#

Returns the antecedents of the rule base.

copy(deep=True)[source]#

Creates a copy of the MasterRuleBase.

Parameters:

deep – if True, creates a deep copy. If False, creates a shallow copy.

Returns:

a copy of the MasterRuleBase.