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: Optional[str] = None, explanation: Optional[str] = None)
The
Measure
class is an abstract class.Its subclasses must implement the
__call__()
method.- abstract __call__(concept: galactic.concepts.Concept, predicate: galactic.descriptions.Predicate) float
Evaluate the individuals present in the concept whose call to predicate is true.
- __init__(label: Optional[str] = None, explanation: Optional[str] = None)
Initialise a
Strategy
class.
- class Cardinality(label: Optional[str] = None, explanation: Optional[str] = None)
The
Cardinality
class computes the cardinality of the predecessor.- __call__(concept: galactic.concepts.Concept, predicate: galactic.descriptions.Predicate) float
Compute the cardinality of the predecessor.
- __init__(label: Optional[str] = None, explanation: Optional[str] = None)
Initialise a
Strategy
class.
- class Confidence(label: Optional[str] = None, explanation: Optional[str] = None)
The
Confidence
class computes the confidence.It is the cardinality ratio between the predecessor and the successor.
- __call__(concept: galactic.concepts.Concept, predicate: galactic.descriptions.Predicate) float
Compute the confidence of the predecessor.
- __init__(label: Optional[str] = None, explanation: Optional[str] = None)
Initialise a
Strategy
class.
- class Support(label: Optional[str] = None, explanation: Optional[str] = None)
The
Support
class computes the support of the predecessor.- __call__(concept: galactic.concepts.Concept, predicate: galactic.descriptions.Predicate) float
Compute the support of the predecessor.
- __init__(label: Optional[str] = None, explanation: Optional[str] = None)
Initialise a
Strategy
class.
- class Strategy(label: Optional[str] = None, explanation: Optional[str] = None)
The
Strategy
class.It produces, for a collection of individuals, a collection of candidate predicates.
- abstract __call__(concept: galactic.concepts.Concept) Iterator[galactic.descriptions.Predicate]
Produce an iterator of selectors.
- Parameters:
concept (
Concept
) – The concept whose selectors are requested.- Returns:
An iterator of selectors.
- Return type:
- __init__(label: Optional[str] = None, explanation: Optional[str] = None)
Initialise a
Strategy
class.
- class BasicStrategy(*characteristics: galactic.characteristics.Characteristic, **kwargs: Any)
The
BasicStrategy
class is used for classical strategies.- abstract __call__(concept: galactic.concepts.Concept) Iterator[galactic.descriptions.Predicate]
Produce an iterator of selectors.
- Parameters:
concept (
Concept
) – The concept whose selectors are requested.- Returns:
An iterator of selectors.
- Return type:
- __init__(*characteristics: galactic.characteristics.Characteristic, **kwargs: Any)
Initialise a
BasicStrategy
instance.- Parameters:
*characteristics (
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 explanation: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
str, optional
- property label: Optional[str]
Get the label.
- Returns:
The strategy label.
- Return type:
str, optional
- property space: Sequence[galactic.characteristics.Characteristic]
Get the characteristics.
- Returns:
A sequence of characteristics.
- Return type:
- class MetaStrategy(*strategies: galactic.strategies.Strategy, **kwargs: Any)
The
MetaStrategy
class.It is used for strategy that own their proper inner strategies.
- __call__(concept: galactic.concepts.Concept) Iterator[galactic.descriptions.Predicate]
Compute an iterator of selectors.
- Parameters:
concept (
Concept
) – The concept whose selectors are requested.- Returns:
An iterator of selectors.
- Return type:
- __init__(*strategies: galactic.strategies.Strategy, **kwargs: Any) None
Initialise a
MetaStrategy
instance.
- property explanation: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
str, optional
- property label: Optional[str]
Get the label.
- Returns:
The strategy label.
- Return type:
str, optional
- property strategies: Sequence[galactic.strategies.Strategy]
Get the strategies.
- Returns:
The sequence of strategies.
- Return type:
- class LimitFilter(*strategies: galactic.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: galactic.concepts.Concept) Iterator[galactic.descriptions.Predicate]
Produce an iterator or selectors.
- Parameters:
concept (
Concept
) – The concept whose selectors are requested.- Returns:
The selectors.
- Return type:
- __init__(*strategies: galactic.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.
- property explanation: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
str, optional
- property label: Optional[str]
Get the label.
- Returns:
The strategy label.
- Return type:
str, optional
- property measure: galactic.strategies.Measure
Get the measure.
- Returns:
The measure.
- Return type:
- property strategies: Sequence[galactic.strategies.Strategy]
Get the strategies.
- Returns:
The sequence of strategies.
- Return type:
- class SelectionFilter(*strategies: galactic.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: galactic.concepts.Concept) Iterator[galactic.descriptions.Predicate]
Produce an iterator or selectors.
- Parameters:
concept (
Concept
) – The concept whose selectors are requested.- Returns:
The selectors.
- Return type:
- __init__(*strategies: galactic.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.
- property explanation: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
str, optional
- property label: Optional[str]
Get the label.
- Returns:
The strategy label.
- Return type:
str, optional
- property measure: galactic.strategies.Measure
Get the measure.
- Returns:
The measure.
- Return type:
- property strategies: Sequence[galactic.strategies.Strategy]
Get the strategies.
- Returns:
The sequence of strategies.
- Return type:
- class ConditionedStrategy(*strategies: galactic.strategies.Strategy, conditions: Iterable[galactic.descriptions.Predicate], **kwargs: Any)
The
ConditionedStrategy
class is conditioned by predicates.- __call__(concept: galactic.concepts.Concept) Iterator[galactic.descriptions.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: galactic.strategies.Strategy, conditions: Iterable[galactic.descriptions.Predicate], **kwargs: Any) None
Initialise a
ConditionedStrategy
instance.
- property conditions: Sequence[galactic.descriptions.Predicate]
Get the conditions.
- Returns:
The conditions.
- Return type:
- property explanation: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
str, optional
- property label: Optional[str]
Get the label.
- Returns:
The strategy label.
- Return type:
str, optional
- property strategies: Sequence[galactic.strategies.Strategy]
Get the strategies.
- Returns:
The sequence of strategies.
- Return type:
- class Explorer(descriptions: Iterable[galactic.descriptions.Description], strategies: Iterable[galactic.strategies.Strategy], characteristics: Optional[Iterable[galactic.characteristics.Characteristic]] = None, predicates: Optional[Iterable[galactic.descriptions.Predicate]] = None, measures: Optional[Iterable[galactic.strategies.Measure]] = None)
The
Explorer
class holds descriptions and strategies.- __init__(descriptions: Iterable[galactic.descriptions.Description], strategies: Iterable[galactic.strategies.Strategy], characteristics: Optional[Iterable[galactic.characteristics.Characteristic]] = None, predicates: Optional[Iterable[galactic.descriptions.Predicate]] = None, measures: Optional[Iterable[galactic.strategies.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[galactic.characteristics.Characteristic]
Get the characteristics of this explorer.
- Returns:
The characteristics.
- Return type:
- property descriptions: Sequence[galactic.descriptions.Description]
Get the descriptions of this explorer.
- Returns:
The descriptions.
- Return type:
- classmethod from_file(stream: TextIO) galactic.strategies.Explorer
Create an explorer from a readable opened file.
- property measures: Sequence[galactic.strategies.Measure]
Get the measures of this explorer.
- Returns:
The measures.
- Return type:
- property predicates: Sequence[galactic.descriptions.Predicate]
Get the predicates of this explorer.
- Returns:
The characteristics.
- Return type:
- property strategies: Sequence[galactic.strategies.Strategy]
Get the strategies of this explorer.
- Returns:
The strategies.
- Return type:
- next_priority_concept(closure: galactic.concepts.ConceptClosure, strategies: Sequence[galactic.strategies.Strategy]) Iterator[Tuple[galactic.concepts.Concept, AbstractSet[galactic.concepts.Concept], AbstractSet[galactic.concepts.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:
Iterator[Tuple[Concept, AbstractSet[Concept], AbstractSet[Concept]]]