ex_fuzzy.evolutionary_fit.FitRuleBase#

class ex_fuzzy.evolutionary_fit.FitRuleBase(X, y, nRules, nAnts, n_classes, thread_runner=None, linguistic_variables=None, n_linguistic_variables=3, fuzzy_type=FUZZY_SETS.t1, domain=None, categorical_mask=None, tolerance=0.01, alpha=0.0, beta=0.0, ds_mode=0, encode_mods=False, allow_unknown=False)[source]#

Bases: Problem

Class to model as pymoo problem the fitting of a rulebase for a classification problem using Evolutionary strategies. Supports type 1 and iv fs (iv-type 2)

vl_names = [[], [], ['Low', 'High'], ['Low', 'Medium', 'High'], ['Low', 'Medium', 'High', 'Very High'], ['Very Low', 'Low', 'Medium', 'High', 'Very High']]#
__init__(X, y, nRules, nAnts, n_classes, thread_runner=None, linguistic_variables=None, n_linguistic_variables=3, fuzzy_type=FUZZY_SETS.t1, domain=None, categorical_mask=None, tolerance=0.01, alpha=0.0, beta=0.0, ds_mode=0, encode_mods=False, allow_unknown=False)[source]#

Cosntructor method. Initializes the classifier with the number of antecedents, linguist variables and the kind of fuzzy set desired.

Parameters:
  • X (array) – np array or pandas dataframe samples x features.

  • y (array) – np vector containing the target classes. vector sample

  • nRules (int) – number of rules to optimize.

  • nAnts (int) – max number of antecedents to use.

  • n_class – number of classes in the problem. If None (as default) it will be computed from the data.

  • linguistic_variables (list[fuzzyVariable]) – list of linguistic variables precomputed. If given, the rest of conflicting arguments are ignored.

  • n_linguistic_variables (int) – number of linguistic variables per antecedent.

  • fuzzy_type – Define the fuzzy set or fuzzy set extension used as linguistic variable.

  • domain (list) – list with the upper and lower domains of each input variable. If None (as default) it will stablish the empirical min/max as the limits.

  • tolerance (float) – float. Tolerance for the size evaluation.

  • alpha (float) – float. Weight for the rulebase size term in the fitness function. (Penalizes number of rules)

  • beta (float) – float. Weight for the average rule size term in the fitness function.

  • ds_mode (int) – int. Mode for the dominance score. 0: normal dominance score, 1: rules without weights, 2: weights optimized for each rule based on the data.

  • encode_mods (bool) – bool. If True, the optimization process will include the modifiers for the membership functions.

  • allow_unknown (bool) – if True, the classifier will allow the unknown class in the classification process. (Which would be a -1 value)

encode_rulebase(rule_base, optimize_lv, encode_mods=False)[source]#

Given a rule base, constructs the corresponding gene associated with that rule base.

GENE STRUCTURE

First: antecedents chosen by each rule. Size: nAnts * nRules (index of the antecedent) Second: Variable linguistics used. Size: nAnts * nRules Third: Parameters for the fuzzy partitions of the chosen variables. Size: nAnts * self.n_linguistic_variables * 8|4 (2 trapezoidal memberships if t2) Four: Consequent classes. Size: nRules

Parameters:
  • rule_base (MasterRuleBase) – rule base object.

  • optimize_lv (bool) – if True, the gene is prepared to optimize the membership functions.

  • encode_mods (bool) – if True, the gene is prepared to encode the modifiers for the membership functions.

Returns:

np array of size self.single_gen_size.

Return type:

array

fitness_func(ruleBase, X, y, tolerance, alpha=0.0, beta=0.0, precomputed_truth=None)[source]#

Fitness function for the optimization problem. :param ruleBase: RuleBase object :param X: array of train samples. X shape = (n_samples, n_features) :param y: array of train labels. y shape = (n_samples,) :param tolerance: float. Tolerance for the size evaluation. :param alpha: float. Weight for the accuracy term. :param beta: float. Weight for the average rule size term. :param precomputed_truth: np array. If given, it will be used as the truth values for the evaluation. :return: float. Fitness value.