Strategies
The galactic.strategies
module.
It defines:
the
galactic.strategies.Strategy
class which is the super-class of all strategies classes;the
galactic.strategies.BasicStrategy
class which must be inherited to implement a new strategy;the
galactic.strategies.MetaStrategy
class which is the base class for all the meta strategies (strategies that use other strategies);the
galactic.strategies.LimitFilter
class which is the a meta strategy which limits the predecessors using a threshold measure;the
galactic.strategies.SelectionFilter
class which is the a meta strategy which keeps the predecessors having the best (or the worst) measure;the
galactic.strategies.Measure
class which is the base class for all measures. A measure can be called on a set of individuals and must a return a comparable value;the
galactic.strategies.Cardinality
which measures the cardinality of a concept;the
galactic.strategies.Support
which measures the support of a concept;the
galactic.strategies.Confidence
which measures the ratio between the confidence of a concept and its successor;the
galactic.strategies.Explorer
class for representing characteristics, descriptions and strategies;
Finally it adds some methods to ConceptLattice
:
ConceptLattice.create()
ConceptLattice.apply()
- class Measure(label: str = '', explanation: str = '')
The
Measure
class is an abstract class.Its subclasses must implement the
__call__()
method.- abstract __call__(concept: Concept, predicate: Predicate) float
Evaluate the individuals present in the concept whose call to predicate is true.
- class Cardinality(label: str = '', explanation: str = '')
The
Cardinality
class computes the cardinality of the predecessor.- __call__(concept: Concept, predicate: Predicate) float
Compute the cardinality of the predecessor.
- class Confidence(label: str = '', explanation: str = '')
The
Confidence
class computes the confidence.It is the cardinality ratio between the predecessor and the successor.
- class Support(label: str = '', explanation: str = '')
The
Support
class computes the support of the predecessor.
- class Strategy(label: str = '', explanation: str = '')
The
Strategy
class.It produces, for a collection of individuals, a collection of candidate predicates.
- abstract __call__(concept: Concept) Iterator[Predicate]
Produce an iterator of selectors.
- Parameters:
concept (
Concept
) – The concept whose selectors are requested.- Returns:
An iterator of selectors.
- Return type:
- class BasicStrategy(*space: Characteristic, **kwargs: Any)
The
BasicStrategy
class is used for classical strategies.- abstract __call__(concept: Concept) Iterator[Predicate]
Produce an iterator of selectors.
- Parameters:
concept (
Concept
) – The concept whose selectors are requested.- Returns:
An iterator of selectors.
- Return type:
- __init__(*space: Characteristic, **kwargs: Any)
Initialise a
BasicStrategy
instance.- Parameters:
*space (
Characteristic[Any]
) – The underlying characteristics.- Keyword Arguments:
**kwargs (
Any
) – Additional keyword parameters.- Raises:
TypeError – If an argument is not an instance of
Characteristic[Any]
.
- property space: Sequence[Characteristic]
Get the characteristics.
- Returns:
A sequence of characteristics.
- Return type:
- class MetaStrategy(*strategies: Strategy, **kwargs: Any)
The
MetaStrategy
class.It is used for strategy that own their proper inner strategies.
- __call__(concept: Concept) Iterator[Predicate]
Compute an iterator of selectors.
- Parameters:
concept (
Concept
) – The concept whose selectors are requested.- Returns:
An iterator of selectors.
- Return type:
- __init__(*strategies: Strategy, **kwargs: Any) None
Initialise a
MetaStrategy
instance.
- class Filter(*strategies: Strategy, measure: Measure, **kwargs: Any)
The
Filter
class is a meta-strategy.Its goal is to filter possible predecessors using a measure on the concept and its predecessor.
- __call__(concept: Concept) Iterator[Predicate]
Compute an iterator of selectors.
- Parameters:
concept (
Concept
) – The concept whose selectors are requested.- Returns:
An iterator of selectors.
- Return type:
- class LimitFilter(*strategies: Strategy, limit: SupportsFloat = 0.0, strict: bool = False, lower: bool = True, **kwargs: Any)
The
LimitFilter
class limits the possible predecessors.It chooses the predecessors whose measure is greater (or less than a threshold).
- __call__(concept: Concept) Iterator[Predicate]
Produce an iterator or selectors.
- Parameters:
concept (
Concept
) – The concept whose selectors are requested.- Returns:
The selectors.
- Return type:
- __init__(*strategies: Strategy, limit: SupportsFloat = 0.0, strict: bool = False, lower: bool = True, **kwargs: Any) None
Initialise a
LimitFilter
instance.- Parameters:
*strategies (
Strategy
) – A collection of strategies.- Keyword Arguments:
limit (
SupportsFloat
) – The limit valuestrict (bool) – Is the limit strict?
lower (bool) – Is it a lower limit?
**kwargs (
Any
) – Additional keyword parameters.
- class SelectionFilter(*strategies: Strategy, keep: SupportsInt = 1, maximize: bool = True, decrease: bool = True, strict: bool = False, rate: SupportsFloat = 1.0, **kwargs: Any)
The
SelectionFilter
class limits the possible predecessors.It chooses the predecessors whose measure is among the greatest (or smallest).
- __call__(concept: Concept) Iterator[Predicate]
Produce an iterator or selectors.
- Parameters:
concept (
Concept
) – The concept whose selectors are requested.- Returns:
The selectors.
- Return type:
- __init__(*strategies: Strategy, keep: SupportsInt = 1, maximize: bool = True, decrease: bool = True, strict: bool = False, rate: SupportsFloat = 1.0, **kwargs: Any) None
Initialise a
SelectionFilter
instance.- Parameters:
*strategies (
Strategy
) – A tuple of strategies.- Keyword Arguments:
keep (
SupportsInt
) – The number of group having the same value kept by this strategymaximize (bool) – Does this measure keep the maximum or the minimum predecessors?
decrease (bool) – Does this strategy have to decrease the measure value between a concept and its predecessors.
strict (bool) – Is the comparison strict between the concept and its predecessors.
rate (
SupportsFloat
) – The rate applied to the concept measure that the predecessors have to be lesser or greater than.**kwargs (
Any
) – Additional keyword parameters.
- class ConditionedStrategy(*strategies: Strategy, conditions: Iterable[Predicate], **kwargs: Any)
The
ConditionedStrategy
class is conditioned by predicates.- __call__(concept: Concept) Iterator[Predicate]
Compute an iterator of selectors.
- Parameters:
concept (
Concept
) – The concept whose selectors are requested.- Returns:
An iterator of selectors produced by the inner strategies if all conditions are met.
- Return type:
- __init__(*strategies: Strategy, conditions: Iterable[Predicate], **kwargs: Any) None
Initialise a
ConditionedStrategy
instance.
- class Explorer(descriptions: Iterable[Description], strategies: Iterable[Strategy], characteristics: Optional[Iterable[Characteristic]] = None, predicates: Optional[Iterable[Predicate]] = None, measures: Optional[Iterable[Measure]] = None)
The
Explorer
class holds descriptions and strategies.- __init__(descriptions: Iterable[Description], strategies: Iterable[Strategy], characteristics: Optional[Iterable[Characteristic]] = None, predicates: Optional[Iterable[Predicate]] = None, measures: Optional[Iterable[Measure]] = None)
Initialise an
Explorer
instance.- Parameters:
descriptions (
Iterable[Description]
) – An iterable of descriptions.strategies (
Iterable[Strategy]
) – An iterable of strategies.
- Keyword Arguments:
characteristics (
Iterable[Characteristics]
, optional) – An iterable of characteristics.predicates (
Iterable[Predicate]
, optional) – An iterable of predicates.measures (
Iterable[Measure]
, optional) – An iterable of measures.
- property characteristics: Sequence[Characteristic]
Get the characteristics of this explorer.
- Returns:
The characteristics.
- Return type:
- property descriptions: Sequence[Description]
Get the descriptions of this explorer.
- Returns:
The descriptions.
- Return type:
- property measures: Sequence[Measure]
Get the measures of this explorer.
- Returns:
The measures.
- Return type:
- property predicates: Sequence[Predicate]
Get the predicates of this explorer.
- Returns:
The characteristics.
- Return type:
- next_priority_concept(closure: ConceptClosure, strategies: Sequence[Strategy]) Iterator[Neighbourhood[Concept]]
Produce a collection of triples (concept, successors, predecessors).
- Parameters:
closure (
ConceptClosure
) – The concept closure operator.strategies (
Sequence[Strategy]
) – A sequence of descriptions.
- Returns:
An iterator of all concepts and their successors, predecessors.
- Return type: