ontolearn.abstracts
The main abstract classes.
Attributes
Classes
Encoded Abstract learning problem for use in Scorers. |
|
Encoded Abstract learning problem following pos-neg lp standard. |
|
An abstract class for quality functions. |
|
Abstract base class for heuristic functions. |
|
Abstract base class for fitness functions. |
|
Base class for Refinement Operators. |
|
Abstract search tree node. |
|
Abstract Node for the CELOEHeuristic heuristic function. |
|
Abstract search tree node which has a concept. |
|
Abstract knowledge base. |
|
Abstract learning problem. |
|
Abstract search tree for the Length based learner. |
|
Abstract class for Convolutional DQL concept learning. |
|
Abstract Tree for DRILL. |
Module Contents
- ontolearn.abstracts.logger
- class ontolearn.abstracts.EncodedLearningProblem[source]
Encoded Abstract learning problem for use in Scorers.
- __slots__ = ()
- class ontolearn.abstracts.EncodedPosNegLPStandardKind[source]
Bases:
EncodedLearningProblem
Encoded Abstract learning problem following pos-neg lp standard.
- __slots__ = ()
- class ontolearn.abstracts.AbstractScorer(*args, **kwargs)[source]
Bases:
Generic
[_N
]An abstract class for quality functions.
- __slots__ = ()
- name: ClassVar[str]
- score_elp(instances: set, learning_problem: EncodedLearningProblem) Tuple[bool, float | None] [source]
Quality score for a set of instances with regard to the learning problem.
- Parameters:
instances (set) – Instances to calculate a quality score for.
learning_problem – Underlying learning problem to compare the quality to.
- Returns:
- Tuple, first position indicating if the function could be applied, second position the quality value
in the range 0.0–1.0.
- abstract score2(tp: int, fn: int, fp: int, tn: int) Tuple[bool, float | None] [source]
Quality score for a coverage count.
- Parameters:
tp – True positive count.
fn – False negative count.
fp – False positive count.
tn – True negative count.
- Returns:
- Tuple, first position indicating if the function could be applied, second position the quality value
in the range 0.0–1.0.
- apply(node: AbstractNode, instances, learning_problem: EncodedLearningProblem) bool [source]
Apply the quality function to a search tree node after calculating the quality score on the given instances.
- Parameters:
node – search tree node to set the quality on.
instances (set) – Instances to calculate the quality for.
learning_problem – Underlying learning problem to compare the quality to.
- Returns:
True if the quality function was applied successfully
- class ontolearn.abstracts.AbstractHeuristic[source]
Bases:
Generic
[_N
]Abstract base class for heuristic functions.
Heuristic functions can guide the search process.
- __slots__ = ()
- abstract apply(node: _N, instances, learning_problem: EncodedLearningProblem)[source]
Apply the heuristic on a search tree node and set its heuristic property to the calculated value.
- Parameters:
node – Node to set the heuristic on.
instances (set, optional) – Set of instances covered by this node.
learning_problem – Underlying learning problem to compare the heuristic to.
- class ontolearn.abstracts.AbstractFitness[source]
Abstract base class for fitness functions.
Fitness functions guide the evolutionary process.
- __slots__ = ()
- name: ClassVar[str]
- class ontolearn.abstracts.BaseRefinement(knowledge_base: _KB)[source]
Bases:
Generic
[_N
]Base class for Refinement Operators.
Let C, D in N_c where N_c os a finite set of concepts.
Proposition 3.3 (Complete and Finite Refinement Operators) [1] * ρ(C) = {C ⊓ T} ∪ {D | D is not empty AND D sqset C}
The operator is finite,
The operator is complete as given a concept C, we can reach an arbitrary concept D such that D subset of C.
*) Theoretical Foundations of Refinement Operators [1].
- *) Defining a top-down refimenent operator that is a proper is crutial.
4.1.3 Achieving Properness [1]
*) Figure 4.1 [1] defines of the refinement operator.
[1] Learning OWL Class Expressions.
- kb
The knowledge base used by this refinement operator.
- Type:
- __slots__ = 'kb'
- kb: _KB
- class ontolearn.abstracts.AbstractOEHeuristicNode[source]
Abstract Node for the CELOEHeuristic heuristic function.
This node must support quality, horizontal expansion (h_exp), is_root, parent_node and refinement_count.
- __slots__ = ()
- property quality: float | None
- Abstractmethod:
Get the quality of the node.
- Returns:
Quality of the node.
- property h_exp: int
- Abstractmethod:
Get horizontal expansion.
- Returns:
Horizontal expansion.
- property is_root: bool
- Abstractmethod:
Is this the root node?
- Returns:
True if this is the root node, otherwise False.
- property parent_node: _N | None
- Abstractmethod:
Get the parent node.
- Returns:
Parent node.
- property refinement_count: int
- Abstractmethod:
Get the refinement count for this node.
- Returns:
Refinement count.
- property heuristic: float | None
- Abstractmethod:
Get the heuristic value.
- Returns:
Heuristic value.
- class ontolearn.abstracts.AbstractConceptNode[source]
Abstract search tree node which has a concept.
- __slots__ = ()
- property concept: owlapy.class_expression.OWLClassExpression
- Abstractmethod:
Get the concept representing this node.
- Returns:
The concept representing this node.
- class ontolearn.abstracts.AbstractKnowledgeBase[source]
Abstract knowledge base.
- __slots__ = ()
- describe() None [source]
Print a short description of the Knowledge Base to the info logger output.
- abstract clean() None [source]
This method should reset any caches and statistics in the knowledge base.
- abstract individuals_set(*args, **kwargs) Set [source]
Encode an individual, an iterable of individuals or the individuals that are instances of a given concept into a set.
- Parameters:
arg (OWLClassExpression) – Individual to encode.
arg – Individuals to encode.
arg – Encode individuals that are instances of this concept.
- Returns:
Encoded set representation of individual(s).
- class ontolearn.abstracts.AbstractLearningProblem(*args, **kwargs)[source]
Abstract learning problem.
- __slots__ = ()
- abstract encode_kb(knowledge_base: AbstractKnowledgeBase) EncodedLearningProblem [source]
Encode the learning problem into the knowledge base.
- class ontolearn.abstracts.LBLSearchTree[source]
Bases:
Generic
[_N
]Abstract search tree for the Length based learner.
- abstract get_most_promising() _N [source]
Find most “promising” node in the search tree that should be refined next.
- Returns:
Most promising search tree node.
- abstract add_node(node: _N, parent_node: _N, kb_learning_problem: EncodedLearningProblem)[source]
Add a node to the search tree.
- Parameters:
node – Node to add.
parent_node – Parent of that node.
kb_learning_problem – Underlying learning problem to compare the quality to.
- abstract get_top_n(n: int) List[_N] [source]
Retrieve the best n search tree nodes.
- Parameters:
n – Maximum number of nodes.
- Returns:
List of top n search tree nodes.
- abstract show_search_tree(root_concept: owlapy.class_expression.OWLClassExpression, heading_step: str)[source]
Debugging function to print the search tree to standard output.
- Parameters:
root_concept – The tree is printed starting from this search tree node.
heading_step – Message to print at top of the output.
- abstract add_root(node: _N, kb_learning_problem: EncodedLearningProblem)[source]
Add the root node to the search tree.
- Parameters:
node – Root node to add.
kb_learning_problem – Underlying learning problem to compare the quality to.
- class ontolearn.abstracts.DepthAbstractDrill(path_of_embeddings, reward_func, learning_rate=None, num_episode=None, num_episodes_per_replay=None, epsilon=None, num_of_sequential_actions=None, max_len_replay_memory=None, representation_mode=None, batch_size=None, epsilon_decay=None, epsilon_min=None, num_epochs_per_replay=None, num_workers=None, verbose=0)[source]
Abstract class for Convolutional DQL concept learning.
- name = 'DRILL'
- instance_embeddings
- reward_func
- representation_mode
- heuristic_func = None
- num_workers
- epsilon
- learning_rate
- num_episode
- num_of_sequential_actions
- num_epochs_per_replay
- max_len_replay_memory
- epsilon_decay
- epsilon_min
- batch_size
- verbose
- num_episodes_per_replay
- optimizer = None
- seen_examples
- start_time = None
- goal_found = False
- experiences