soft.fuzzy.logic.rules.reduction package
Subpackages
Submodules
soft.fuzzy.logic.rules.reduction.rough_theory module
This Python script will be used to implement fuzzy logic rule reduction algorithms.
- soft.fuzzy.logic.rules.reduction.rough_theory.find_unique_premise_variables(rules: Iterable[Rule]) List[int]
Find the unique variables in the rules’ premises.
- Parameters:
rules – A list of fuzzy logic rules.
- Returns:
A list of unique variables in the rules’ premises.
- soft.fuzzy.logic.rules.reduction.rough_theory.make_rule_matrix(rules: ~typing.List[~soft.fuzzy.logic.rules.Rule], unique_premise_variables: ~typing.List[int], output_values: ~torch.Tensor | ~numpy.array | None = None) -> (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>)
Create a matrix representation of the rules. The matrix is of shape (number of rules, number of unique premise variables + 1). The last column of the matrix contains the rules’ consequences. If the rules’ consequences are not provided, the rules’ consequences are used. This function will also return a Numpy array of the rules’ consequences.
- Parameters:
rules – A list of fuzzy logic rules.
unique_premise_variables – A list of unique variables in the rules’ premises.
output_values – The output values of the rules. If None, the rules’ consequences are used.
- Returns:
A matrix representation of the rules and a Numpy array of the rules’ consequences.
- soft.fuzzy.logic.rules.reduction.rough_theory.parse_reduced_rules(numpy_matrix: ndarray, output_values: ndarray, reduced_rules: ListVector, rules: List[Rule]) Tuple[List[Rule], List[float]]
Go through the reduced rules and extract the rules’ premises and consequences. The reduced rules are in the form of R objects, which are converted to Python objects using rpy2. The reduced rules are then parsed, and the final rules and output values are returned. Some reduced rules may not be valid, in which case they are ignored. For a reduced rule to be valid, it must have a Laplace value greater than the average and a support value greater than the minimum support value. The final rules are in the form of a list of Rule objects. The output values are in the form of a list of floats.
- Parameters:
numpy_matrix – The matrix of the fuzzy logic rules.
output_values – The output values of the fuzzy logic rules.
reduced_rules – The reduced rules in the form of R objects.
rules – The original fuzzy logic rules.
- Returns:
The final rules and output values.
- soft.fuzzy.logic.rules.reduction.rough_theory.reduce_fuzzy_logic_rules_with_rough_sets(rules: List[Rule], config: Config, output_values: Tensor | array | None = None) Tuple[List[Rule], Tensor]
Reduce fuzzy logic rules’ attributes using rough set theory.
- Parameters:
rules – A list of fuzzy logic rules.
config – A configuration object.
output_values – The output values of the rules. If None, the output values will be inferred from the rules’ consequences. Defaults to None. For example, if the output_values are given, then the fuzzy logic rules are assumed to belong to a zero-order TSK fuzzy logic controller. If the output_values are None, then the fuzzy logic rules are assumed to belong to a Mamdani fuzzy logic controller and the output_values will be inferred from the rules’ consequences.
- Returns:
A list of reduced fuzzy logic rules and the output values of the newly reduced rules.