Strategies

The galactic.strategies module.

It defines:

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.

Parameters:
  • concept (Concept) – The concept for which individuals will be tested.

  • predicate (Predicate) – The predicate to be tested.

Returns:

The computed measure.

Return type:

float

__init__(label: Optional[str] = None, explanation: Optional[str] = None)

Initialise a Strategy class.

Keyword Arguments:
  • label (str, optional) – An optional label.

  • explanation (str, optional) – An optional explanation in markdown text.

property explanation: Optional[str]

Get the explanation.

Returns:

The measure explanation.

Return type:

str, optional

property label: Optional[str]

Get the label.

Returns:

The measure label.

Return type:

str, optional

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.

Parameters:
Returns:

The cardinality.

Return type:

float

__init__(label: Optional[str] = None, explanation: Optional[str] = None)

Initialise a Strategy class.

Keyword Arguments:
  • label (str, optional) – An optional label.

  • explanation (str, optional) – An optional explanation in markdown text.

property explanation: Optional[str]

Get the explanation.

Returns:

The measure explanation.

Return type:

str, optional

property label: Optional[str]

Get the label.

Returns:

The measure label.

Return type:

str, optional

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.

Parameters:
Returns:

The confidence.

Return type:

float

__init__(label: Optional[str] = None, explanation: Optional[str] = None)

Initialise a Strategy class.

Keyword Arguments:
  • label (str, optional) – An optional label.

  • explanation (str, optional) – An optional explanation in markdown text.

property explanation: Optional[str]

Get the explanation.

Returns:

The measure explanation.

Return type:

str, optional

property label: Optional[str]

Get the label.

Returns:

The measure label.

Return type:

str, optional

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.

Parameters:
Returns:

The support.

Return type:

float

__init__(label: Optional[str] = None, explanation: Optional[str] = None)

Initialise a Strategy class.

Keyword Arguments:
  • label (str, optional) – An optional label.

  • explanation (str, optional) – An optional explanation in markdown text.

property explanation: Optional[str]

Get the explanation.

Returns:

The measure explanation.

Return type:

str, optional

property label: Optional[str]

Get the label.

Returns:

The measure label.

Return type:

str, optional

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:

Iterator[Predicate]

__init__(label: Optional[str] = None, explanation: Optional[str] = None)

Initialise a Strategy class.

Keyword Arguments:
  • label (str, optional) – An optional label.

  • explanation (str, optional) – An optional explanation in markdown text.

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

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:

Iterator[Predicate]

__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:

Sequence[Characteristic[Any]]

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:

Iterator[Predicate]

__init__(*strategies: galactic.strategies.Strategy, **kwargs: Any) None

Initialise a MetaStrategy instance.

Parameters:

*strategies (Strategy) – A tuple of strategies.

Keyword Arguments:

**kwargs (Any) – Additional keyword parameters.

Raises:

TypeError – If an argument is not an instance of Strategy

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:

Sequence[Strategy]

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:

Iterator[Predicate]

__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 value

  • strict (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 limit: float

Get the limit.

Returns:

The limit.

Return type:

float

property lower: bool

Get the lower flag.

Returns:

The lower flag.

Return type:

bool

property measure: galactic.strategies.Measure

Get the measure.

Returns:

The measure.

Return type:

Measure

property strategies: Sequence[galactic.strategies.Strategy]

Get the strategies.

Returns:

The sequence of strategies.

Return type:

Sequence[Strategy]

property strict: bool

Get the strict flag.

Returns:

The strict flag.

Return type:

bool

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:

Iterator[Predicate]

__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 strategy

  • maximize (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 decrease: bool

Get the decrease flag.

Returns:

The decrease flag.

Return type:

bool

property explanation: Optional[str]

Get the explanation.

Returns:

The strategy explanation.

Return type:

str, optional

property keep: int

Get the keep value.

Returns:

The keep value.

Return type:

int

property label: Optional[str]

Get the label.

Returns:

The strategy label.

Return type:

str, optional

property maximize: bool

Get the maximize flag.

Returns:

The maximize flag.

Return type:

bool

property measure: galactic.strategies.Measure

Get the measure.

Returns:

The measure.

Return type:

Measure

property rate: float

Get the rate value.

Returns:

The rate value.

Return type:

float

property strategies: Sequence[galactic.strategies.Strategy]

Get the strategies.

Returns:

The sequence of strategies.

Return type:

Sequence[Strategy]

property strict: bool

Get the strict flag.

Returns:

The strict flag.

Return type:

int

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:

Iterator[Predicate]

__init__(*strategies: galactic.strategies.Strategy, conditions: Iterable[galactic.descriptions.Predicate], **kwargs: Any) None

Initialise a ConditionedStrategy instance.

Parameters:

*strategies (Strategy) – A sequence of strategies.

Keyword Arguments:
  • conditions (Iterable[Predicate]) – An iterable of predicates

  • **kwargs (Any) – Additional keyword parameters.

property conditions: Sequence[galactic.descriptions.Predicate]

Get the conditions.

Returns:

The conditions.

Return type:

Sequence[Predicate]

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:

Sequence[Strategy]

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:
Keyword Arguments:
property characteristics: Sequence[galactic.characteristics.Characteristic]

Get the characteristics of this explorer.

Returns:

The characteristics.

Return type:

Sequence[Characteristic]

property descriptions: Sequence[galactic.descriptions.Description]

Get the descriptions of this explorer.

Returns:

The descriptions.

Return type:

Sequence[Description]

classmethod from_file(stream: TextIO) galactic.strategies.Explorer

Create an explorer from a readable opened file.

Parameters:

stream (TextIO) – File to read

Returns:

A new explorer.

Return type:

Explorer

property measures: Sequence[galactic.strategies.Measure]

Get the measures of this explorer.

Returns:

The measures.

Return type:

Sequence[Measure]

property predicates: Sequence[galactic.descriptions.Predicate]

Get the predicates of this explorer.

Returns:

The characteristics.

Return type:

Sequence[Predicate]

property strategies: Sequence[galactic.strategies.Strategy]

Get the strategies of this explorer.

Returns:

The strategies.

Return type:

Sequence[Strategy]

write(stream: TextIO) None

Write an explorer to a file in yaml format.

Parameters:

stream (TextIO) – A file to be written

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:
Returns:

An iterator of all concepts and their successors, predecessors.

Return type:

Iterator[Tuple[Concept, AbstractSet[Concept], AbstractSet[Concept]]]

register_classes() None

Register all classes defined in this module.