soft.rough.information package
Submodules
soft.rough.information.approximation module
A module that contains the RoughApproximation class, which is a class that represents the rough approximation of a set of objects. The rough approximation is a set of objects that are indiscernible from each other with respect to a set of relations. The rough approximation is a generalization of the lower and upper approximation, which are defined by Pawlak on page 10 of his book “Rough Sets: Theoretical Aspects of Reasoning About Data”.
- class soft.rough.information.approximation.RoughApproximation
Bases:
RoughGranulation
A class that represents the rough approximation of a set of objects. The rough approximation is a set of objects that are indiscernible from each other with respect to a set of relations. The rough approximation is a generalization of the lower and upper approximation, which are defined by Pawlak on page 10 of his book “Rough Sets: Theoretical Aspects of Reasoning About Data”.
- accuracy(relations, category)
Calculate the inexactness of a set (category) due to the existence of a borderline region. The greater the borderline region, the lower the accuracy is of the set.
If the accuracy is 1, then the set X is R-definable, otherwise, it is R-undefinable (i.e., our knowledge is incomplete).
- Parameters:
relations
category
Returns:
- approximation(relations: str | set, categories: set | frozenset | List[frozenset], mode: callable) frozenset | Set[frozenset]
Get the approximation of a (set of) category(s), as defined by Pawlak on page 10 of his book “Rough Sets: Theoretical Aspects of Reasoning About Data”. The approximation is determined by the mode argument, which is a function that takes two arguments: a subset and the category. The mode function should return True if the subset satisfies the category.
- Parameters:
relations – Either a set of relations or a string that references a specific relation
KnowledgeBase. (in the)
categories – The category (frozenset) or a family of categories (list of frozensets).
mode – The mode of approximation, which is a function that takes two arguments: a
satisfies (subset and a category. The mode function should return True if the subset)
approximation (the category. In the case of the lower)
return (the mode function should)
upper (True if the subset is a subset of the category. In the case of the)
approximation
the (the mode function should return True if the subset intersects with)
category.
- Returns:
Either a frozenset or a set of frozensets that represent the [mode] approximation.
- boundary_region(relations: str | set, categories: set | frozenset | List[frozenset]) frozenset | Set[frozenset]
The undecidable area of the universe (i.e., none of the objects belonging to the boundary can be classified with certainty into categories or not categories, as far as knowledge ‘relations’ is concerned.
- Parameters:
relations – Either a set of relations or a string that references a specific relation
KnowledgeBase. (in the)
categories – The category (frozenset) or a family of categories (list of frozensets).
- Returns:
Either a frozenset or a set of frozensets that represent the boundary region.
- definable(relations: str | set, category: frozenset) namedtuple
A category X is called:
R-definable if X is the union of some R-basic categories; otherwise X is R-undefinable. Also called R-exact sets. R-undefinable sets are also called R-inexact or R-rough sets.
Roughly definable if we are able to decide whether some elements of the universe belong to X or not X.
Internally undefinable if we are able to decide whether some elements of the universe belong to not X, but we are unable to indicate one element of X.
Externally undefinable if we are able to decide for some elements of the universe whether they belong to X, but we are unable to indicate one element of not X.
Totally undefinable if we are unable to decide for any element of the universe whether it belongs to X or not X.
- Parameters:
relations – Either a set of relations or a string that references a specific relation
KnowledgeBase. (in the)
category – The category (frozenset).
- Returns:
A namedtuple with the lower and upper approximation of the given category. The name of the tuple depends on the type of definability of the category.
- indiscernibility(equivalence_relations: str | set | list)
The indiscernibility relation over a vector of equivalence relations (referred to as “P”). Defined on page 3 of “Rough Sets: Theoretical Aspects of Reasoning About Data”.
- Parameters:
equivalence_relations – An iterable of equivalence relations that must be a subset
passed (equivalence relations. If a list is)
to (it is assumed)
passed
of (it is assumed to be a set)
passed
equivalence (it is assumed to be a list of)
relations.
- Returns:
An indiscernibility relation over a collection of equivalence relations (i.e., the family of equivalence classes of the equivalence relation IND(P)) yields the family of equivalence classes; denotes knowledge associated with the family of equivalence relations P, called P-basic knowledge about U (universe) in K (knowledge base).
- lower_approximation(relations: str | set, categories: set | frozenset | List[frozenset]) frozenset | Set[frozenset]
Get the lower approximation of a (set of) category(s), as defined by Pawlak on page 10 of his book “Rough Sets: Theoretical Aspects of Reasoning About Data”.
- Parameters:
relations – Either a set of relations or a string that references a specific relation
KnowledgeBase. (in the)
categories – The category (frozenset) or a family of categories (list of frozensets).
- Returns:
Either a frozenset or a set of frozensets that represent the lower approximation.
- negative_region(relations: str | set, categories: frozenset | List[frozenset]) frozenset | Set[frozenset]
The set of objects with which it can be determined without any ambiguity, employing knowledge ‘relations’, that they do not belong to the ‘categories’ (i.e., they belong to the complement of ‘categories’)
- Parameters:
relations – Either a set of relations or a string that references a specific relation
KnowledgeBase. (in the)
categories – The category (frozenset) or a family of categories (list of frozensets).
- Returns:
Either a frozenset or a set of frozensets that represent the negative region.
- positive_region(relations: str | set, categories: set | frozenset | List[frozenset]) frozenset | Set[frozenset]
Analogous to the R-lower approximation.
- Parameters:
relations – Either a set of relations or a string that references a specific relation
KnowledgeBase. (in the)
categories – The category (frozenset) or a family of categories (list of frozensets).
- Returns:
Either a frozenset or a set of frozensets that represent the positive region or the lower approximation.
- quality_of_approximation(relations, categories)
The quality of approximation of X, a family of non-empty sets, using knowledge ‘relations’.
This metric expresses the percentage of possible correct decisions when classifying objects employing the knowledge ‘relations’.
- Parameters:
relations
categories
Returns:
- roughly_equal(relations, category, other_category, mode: bottom | top | both = 'both')
Determines if the category and the other category are roughly equal given knowledge about “relations”. The definition of equality depends on the mode.
If mode is “bottom”, then the lower approximation of category is equal to the lower approximation of the other category given “relations”; essentially, the positive examples of the sets “category” and the “other category” are the same.
If mode is “top”, then the upper approximation of the given category is equal to the upper approximation of the other category given knowledge about “relations”; essentially, the negative examples of the sets “category” and the “other category” are the same.
If mode is “both”, then the lower and upper approximation of category is equal to the lower and upper approximation of the other category given “relations”; essentially, the positive and negative examples of the sets “category” and the “other category” are the same.
- Parameters:
relations – The equivalence relations.
category – The category in question.
other_category – The other category in question.
mode – The mode of equality.
- Returns:
Whether the category and the other category are roughly equal given knowledge about “relations”.
- roughly_included(relations, category, other_category, mode: bottom | top | both = 'both')
Determines whether the category is roughly included in the other category given knowledge about “relations”. The definition of inclusion depends on the mode.
If mode is “bottom”, then the lower approximation of category is equal to the lower approximation of the other category given “relations”; essentially, the positive examples of the sets “category” and the “other category” are the same.
If mode is “top”, then the upper approximation of the given category is equal to the upper approximation of the other category given knowledge about “relations”; essentially, the negative examples of the sets “category” and the “other category” are the same.
If mode is “both”, then the lower and upper approximation of category is equal to the lower and upper approximation of the other category given “relations”; essentially, the positive and negative examples of the sets “category” and the “other category” are the same.
Whether the lower and upper approximations of X are subset to the lower and upper approximations of Y given ‘relations’, respectively.
- Parameters:
relations – The equivalence relations.
category – The category in question.
other_category – The other category in question.
mode – The mode of inclusion (i.e., subsethood).
- Returns:
Whether the category is roughly included in (i.e., a subset of) the other category given knowledge about “relations”.
- roughness(relations, category)
The complement of a rough set’s accuracy or inexactness; represents the degree of incompleteness of knowledge ‘relations’ about the set X.
- Parameters:
relations
category
Returns:
- upper_approximation(relations: str | set, categories: set | frozenset | List[frozenset]) frozenset | Set[frozenset]
Get the upper approximation of a (set of) category(s), as defined by Pawlak on page 10 of his book “Rough Sets: Theoretical Aspects of Reasoning About Data”.
- Parameters:
relations – Either a set of relations or a string that references a specific relation
KnowledgeBase. (in the)
categories – The category (frozenset) or a family of categories (list of frozensets).
- Returns:
Either a frozenset or a set of frozensets that represent the upper approximation.
soft.rough.information.decisions module
Implements the methods required to work with rough theory.
- class soft.rough.information.decisions.RoughDecisions
Bases:
RoughOperations
This class implements the necessary methods for handling decisions in rough set theory. For example, the discernibility matrix, the CORE, and the reduct. Features include the ability to simplify decision tables as well as remove redundant attributes.
- decompose_decision_table(condition_attributes, decision_attributes)
Given the condition attributes (condition_attributes) and the decision attributes (decision_attributes), decompose the decision table into a consistent decision table and an inconsistent decision table.
- Parameters:
condition_attributes – The condition attributes.
decision_attributes – The decision attributes.
- Returns:
A consistent decision table (frozenset), an inconsistent decision table (frozenset)
- discernibility_matrix(relations, decision_attributes=None) dict
Calculate the discernibility matrix for a set of relations.
- Parameters:
relations – The set of relations.
decision_attributes – The decision attributes.
- Returns:
The discernibility matrix.
- find_attribute_cores(minimal_condition_attributes)
Find the core attributes.
- Parameters:
minimal_condition_attributes
Returns:
- find_attribute_reducts(minimal_condition_attributes)
Find the reduct attributes.
- Parameters:
minimal_condition_attributes
Returns:
- find_core_by_matrix(matrix) frozenset
Find the CORE by the matrix method. The CORE is the set of attributes that are not redundant.
- Parameters:
matrix – The discernibility matrix.
- Returns:
The CORE.
- minimum_discernibility_matrix(relations, matrix=None, decision_attributes=None)
A. Skowron has proposed to represent knowledge in this form. It is a n x n matrix, where ‘n’ is the number of items in the universe of discourse. Each entry, c_{ij}, in the matrix follows:
$(c_{ij}) = { a in A : a(x_{i}) != a(x_{j}) } for i, j = 1, 2, …, n$
Thus entry c_{ij} is the set of all attributes which discern objects x_{i} and x_{j}.
- Parameters:
relations
matrix
decision_attributes
Returns:
- remove_redundant_attributes(condition_attributes, decision_attributes)
Remove any attributes identified as redundant.
- Parameters:
condition_attributes – The condition attributes.
decision_attributes – The decision attributes.
Returns:
- simplify_decision_table(condition_attributes, decision_attributes)
Simplify the decision table, given the condition attributes and the decision attributes.
- Parameters:
condition_attributes – The condition attributes.
decision_attributes – The decision attributes.
Returns:
soft.rough.information.granulation module
A module that contains the RoughGranulation class, which is used to provide the necessary granulation operations required for rough set theory. This class is inherited by more specialized classes, such as RoughApproximation, to provide the basic granulation operations.
- class soft.rough.information.granulation.RoughGranulation
Bases:
Core
A class that represents the necessary granulation operations required for rough set theory. This class is inherited by more specialized classes, such as RoughApproximation, to provide the basic granulation operations.
- edges(relation: str) Set[frozenset]
Get the ‘name’ (vertex attribute) of each vertex that interacts with the given relation.
- Parameters:
relation – A relation.
- Returns:
A set of frozensets, where each frozenset contains the ‘name’ of vertices that are neighbors which interact with .
- family_intersection(relative_to: set) frozenset
Get the intersection of a family of sets/categories ‘relative_to’ some set of relations.
- Parameters:
relative_to – A selection of relations.
- Returns:
The family intersection.
- family_union(relative_to: set) frozenset
Get the union of a family of sets/categories ‘relative_to’ some set of relations.
- Parameters:
relative_to – A selection of relations.
- Returns:
The family union.
soft.rough.information.operations module
Implements the methods required to work with rough theory.
- class soft.rough.information.operations.RoughOperations
Bases:
RoughApproximation
This class implements several methods that are relevant to KnowledgeBase objects working with rough set theory.
- depends_on(relations: str | set, other_relations: str | set) bool
Knowledge Q depends on knowledge P (P ==> Q) if and only if IND(P) is a subset of IND(Q). More precisely, knowledge Q is derivable from knowledge P, if all elementary categories of Q can be defined in terms of some elementary categories of knowledge P.
- Parameters:
relations
other_relations
Returns:
- dispensable(relations: set | frozenset, relation: str | set, relative_to: set | frozenset | None = None, mode: callable | None = None) bool
Checks whether the relation is dispensable from the set “relations”.
- Parameters:
relations – The set of relations to check for dispensability.
relation – The relation to check for dispensability.
relative_to – The set of relations to find the relative positive region. If None, then the relative positive region is the positive region of the set “relations”.
mode – The mode to determine dispensability.
- Returns:
True if dispensable, False otherwise.
- equivalent_to(relations: str | set, other_relations: str | set) bool
Knowledge P and Q are equivalent if and only if knowledge P derives Q and knowledge Q derives P.
- Parameters:
relations
other_relations
Returns:
- find_core(relations: set, relative_to: set | None = None, mode: callable | None = None) frozenset
Obtains the reducts of the knowledge and identifies the most important part aka the core.
- Parameters:
relations
relative_to
mode – The function to use to calculate the core. Defaults to indiscernibility.
Returns:
- find_reducts(relations: set, relative_to: set | None = None, mode: callable | None = None) frozenset
Find the reducts of the knowledge base given the “relations”, relative to the relations specified in “relative_to”, if applicable.
- Parameters:
relations – The set of relations to find the reducts.
relative_to – The set of relations to find the relative positive region. If None, then
"relations". (the relative positive region is the positive region of the set)
mode – The mode to determine dispensability. If relative_to is None and mode is None,
indiscernibility. (then the mode is the)
- Returns:
The set of reducts.
- find_relative_positive_region(relations: str | set, relative_to: str | set) frozenset
The P-positive region (POS) of Q is the set of all objects of the universe, U, which can be properly classified to classes of U / Q employing knowledge expressed by the classification U / P.
- Parameters:
relations – The set of relations to find the relative positive region.
relative_to
- Returns:
The relative positive region.
- independent(relations: set | frozenset, relative_to: set | frozenset | None = None, mode: callable | None = None) bool
Checks each relation within the set “relations” to see if it is dispensable; if at least one relation is dispensable, then the set “relations” are dependent. Otherwise, the set of “relations” are independent.
- Parameters:
relations – The set of relations to check for independence.
relative_to – The set of relations to find the relative positive region. If None, then
"relations". (the relative positive region is the positive region of the set)
mode – The mode to determine dispensability. If None, then the mode is the
indiscernibility.
- Returns:
True if independent, False otherwise.
- independent_of(relations: str | set, other_relations: str | set) bool
Knowledge P and Q are independent, denoted as P != Q, if neither P ==> Q nor Q ==> P hold.
- Parameters:
relations
other_relations
Returns:
- is_q_reduct_of_p(relations: set, restrictions: set, set_s: set) bool
The family S that is a subset of P is called a Q-reduct of P, if and only if S is the Q-independent subfamily of P and POS_{S}(Q) == POS_{P}(Q).
- Parameters:
relations
restrictions
set_s
Returns:
- is_y_reduct_of_f(categories_f, categories_h, category_y) bool
The family H is a subset of F and a Y-reduct of the intersection of F, if H is Y-independent in the intersection of F, and the intersection of H is a subset of Y.
- Parameters:
categories_f
categories_h
category_y
Returns:
- partial_depends_on(relations: str | set, other_relations: str | set, category: set | frozenset | List[frozenset] | None = None) float
Partial dependency of knowledge: the derivation (dependency) can also be partial, which means that only part of the knowledge Q is derivable from knowledge P.
In essence, knowledge Q depends on a degree k (0 <= k <= 1) from knowledge P, symbolically P ==>_{k} Q.
If k = 1, then Q totally depends on P; if 0 < k < 1, then Q roughly (partially) depends on P, and if k = 0, then Q is totally independent from knowledge P.
In other words, if k = 1, then all the elements of the universe, U, can be classified to elementary categories of U / Q. If k != 1, only those elements of the universe which belong to the positive region can be classified to categories of knowledge Q, employing knowledge P. In particular, if k = 0, then none of the elements of the universe can be classified using knowledge P to elementary categories of knowledge Q.
Disclaimer: The measure k of dependency, $P –>_{k} Q$, does not capture how this partial dependency is actually distributed among classes of U / Q. For example, some decision classes can be fully characterized by P, whereas others may be characterized only partially. Hence, an alternative definition is proposed where $gamma(X) = card(P_lower X) / card(X)$ where $X in U / Q$ which shows how many elements of each class of U / Q can be classified by employing knowledge P.
To use the ‘alternative definition’, change the ‘category’ argument to a set that occurs in U / Q. When using the alternative definition, ‘Q’ can be ‘None’.
- Parameters:
relations
other_relations
category
- Returns:
The partial dependency of knowledge.
- y_dispensable(categories: set | list, relation: str, category: str) bool
Determine if the category in categories is (relation)-dispensable in the intersection of categories.
- Parameters:
categories – A set of categories.
relation – A relation.
category – A category.
- Returns:
Whether the given category is dispensable.
- y_independent(categories: set, category_y: str) bool
The family of sets, categories, is Y-independent in the intersection of categories if all of its components are Y-indispensible in the intersection of categories; otherwise, the categories are Y-dependent in the intersection of categories.
- Parameters:
categories – A set of categories.
category_y
Returns: