fuzzy_dl_owl2.fuzzydl.query.defuzzify.defuzzify_query

An abstract base class that defines the structure for defuzzifying fuzzy logic queries by converting membership degrees into crisp values using Mixed-Integer Linear Programming.

Description

Defuzzification logic is encapsulated within this abstract class, which orchestrates the conversion of fuzzy membership degrees into crisp numerical values for a specific individual and feature. The process begins by calculating the maximum degree of membership for a given individual to a concept and asserting this value into a cloned version of the knowledge base to establish a constrained environment. Once the context is set, the logic identifies the mathematical variable associated with the target feature and optimizes an objective expression derived from that variable to produce the final crisp result. By delegating the construction of the objective expression to subclasses, the design allows for various defuzzification strategies while centralizing the common workflow of solving Mixed-Integer Linear Programming problems and handling potential ontology inconsistencies.

Classes

DefuzzifyQuery

This abstract class defines the structure for performing defuzzification, which involves converting a fuzzy membership degree into a crisp value for a specific individual and feature within a knowledge base. During execution, it first determines the maximum degree of membership for the individual to the given concept and asserts this value into a cloned version of the knowledge base. It then identifies the variable associated with the specified feature and optimizes an objective expression derived from that variable to produce the final result. Subclasses are required to implement the abstract method for generating the objective expression, allowing for different defuzzification strategies to be applied. The process relies on Mixed-Integer Linear Programming (MILP) and handles potential inconsistencies in the ontology gracefully.

Module Contents

UML Class Diagram for DefuzzifyQuery

UML Class Diagram for DefuzzifyQuery

class DefuzzifyQuery(
c: fuzzy_dl_owl2.fuzzydl.concept.concept.Concept,
ind: fuzzy_dl_owl2.fuzzydl.individual.individual.Individual,
feature_name: str,
)[source]

Bases: fuzzy_dl_owl2.fuzzydl.query.query.Query

Inheritance diagram of fuzzy_dl_owl2.fuzzydl.query.defuzzify.defuzzify_query.DefuzzifyQuery

This abstract class defines the structure for performing defuzzification, which involves converting a fuzzy membership degree into a crisp value for a specific individual and feature within a knowledge base. During execution, it first determines the maximum degree of membership for the individual to the given concept and asserts this value into a cloned version of the knowledge base. It then identifies the variable associated with the specified feature and optimizes an objective expression derived from that variable to produce the final result. Subclasses are required to implement the abstract method for generating the objective expression, allowing for different defuzzification strategies to be applied. The process relies on Mixed-Integer Linear Programming (MILP) and handles potential inconsistencies in the ontology gracefully.

Parameters:
  • conc (Concept) – The concept for which the defuzzification operation is performed.

  • a (Individual) – The individual entity for which the defuzzification query is being executed.

  • f_name (str) – The name of the feature for which to perform defuzzification.

  • obj_expr (Expression) – The objective expression used to optimize the solution, representing the degree of membership of the individual to the concept.

abstractmethod get_obj_expression(variable: fuzzy_dl_owl2.fuzzydl.milp.variable.Variable) fuzzy_dl_owl2.fuzzydl.milp.expression.Expression[source]

Retrieves the objective expression associated with the specified variable for the defuzzification process. This abstract method requires subclasses to implement the logic for constructing the expression, which typically represents the target function or calculation needed to resolve the fuzzy variable into a crisp value. The implementation determines how the variable’s properties are translated into a formal expression used by the query engine.

Parameters:

variable (Variable) – The variable instance for which the corresponding object expression is to be retrieved.

Returns:

The expression representing the object associated with the provided variable.

Return type:

Expression

preprocess(kb: fuzzy_dl_owl2.fuzzydl.knowledge_base.KnowledgeBase) None[source]

Prepares the defuzzification query by solving a maximum satisfiability problem to determine the optimal degree for the conclusion associated with the current individual. If a consistent solution is found, the method updates the internal reference to the individual, asserts the calculated numeric degree back into the knowledge base, and resolves these assertions. Furthermore, it inspects the individual’s role relations to identify a specific target individual, retrieving the corresponding MILP variable to construct and store an objective expression for later use.

Parameters:

kb (KnowledgeBase) – The knowledge base instance used to solve queries, retrieve individuals, and manage assertions and MILP variables. This object is modified during the preprocessing step.

solve(kb: fuzzy_dl_owl2.fuzzydl.knowledge_base.KnowledgeBase) fuzzy_dl_owl2.fuzzydl.milp.solution.Solution | None[source]

Attempts to solve the defuzzification problem by first resolving the ABox of the provided Knowledge Base and then operating on a cloned instance to preserve the original state. The method applies preprocessing to the clone and, if an objective expression is defined, performs an optimization to find a solution. If the resulting solution value is negative, it is converted to its absolute value before being returned. If no objective expression is available, the method issues a warning and returns None. Furthermore, it handles inconsistent ontologies by catching the specific exception and returning a Solution object marked as inconsistent.

Parameters:

kb (KnowledgeBase) – The knowledge base containing the ontology and ABox to be solved and optimized.

Returns:

A Solution object representing the optimization result, or None if the objective expression is missing or a defuzzification problem occurs. Returns a specific Solution indicating inconsistency if the ontology is inconsistent.

Return type:

Optional[Solution]

a: fuzzy_dl_owl2.fuzzydl.individual.individual.Individual
conc: fuzzy_dl_owl2.fuzzydl.concept.concept.Concept
f_name: str
obj_expr: fuzzy_dl_owl2.fuzzydl.milp.expression.Expression = None