Strategies

The galactic.strategies module.

It defines:

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.

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: str = '', explanation: str = '') None

Initialize a Resource instance.

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

  • explanation (str, optional) – An optional explanation in markdown text. The text will be sanitized by keeping only strong and emphasis markup.

property explanation: str

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str

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.

Parameters:
Returns:

The cardinality.

Return type:

float

__init__(label: str = '', explanation: str = '') None

Initialize a Resource instance.

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

  • explanation (str, optional) – An optional explanation in markdown text. The text will be sanitized by keeping only strong and emphasis markup.

property explanation: str

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str

class Confidence(label: str = '', explanation: str = '')

The Confidence class computes the confidence.

It is the cardinality ratio between the predecessor and the successor.

__call__(concept: Concept, predicate: Predicate) float

Compute the confidence of the predecessor.

Parameters:
Returns:

The confidence.

Return type:

float

__init__(label: str = '', explanation: str = '') None

Initialize a Resource instance.

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

  • explanation (str, optional) – An optional explanation in markdown text. The text will be sanitized by keeping only strong and emphasis markup.

property explanation: str

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str

class Support(label: str = '', explanation: str = '')

The Support class computes the support of the predecessor.

__call__(concept: Concept, predicate: Predicate) float

Compute the support of the predecessor.

Parameters:
Returns:

The support.

Return type:

float

__init__(label: str = '', explanation: str = '') None

Initialize a Resource instance.

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

  • explanation (str, optional) – An optional explanation in markdown text. The text will be sanitized by keeping only strong and emphasis markup.

property explanation: str

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str

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:

Iterator[Predicate]

__init__(label: str = '', explanation: str = '') None

Initialize a Resource instance.

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

  • explanation (str, optional) – An optional explanation in markdown text. The text will be sanitized by keeping only strong and emphasis markup.

property explanation: str

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str

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:

Iterator[Predicate]

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

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str

property space: Sequence[Characteristic]

Get the characteristics.

Returns:

A sequence of characteristics.

Return type:

Sequence[Characteristic]

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:

Iterator[Predicate]

__init__(*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: str

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str

property strategies: Sequence[Strategy]

Get the strategies.

Returns:

The sequence of strategies.

Return type:

Sequence[Strategy]

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:

Iterator[Predicate]

__init__(*strategies: Strategy, measure: Measure, **kwargs: Any)

Initialise a Filter instance.

Parameters:

*strategies (Strategy) – A collection of strategies.

Keyword Arguments:
  • measure (Measure) – A measure used for filtering.

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

property explanation: str

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str

property measure: Measure

Get the measure.

Returns:

The measure.

Return type:

Measure

property strategies: Sequence[Strategy]

Get the strategies.

Returns:

The sequence of strategies.

Return type:

Sequence[Strategy]

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:

Iterator[Predicate]

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

  • strict (bool) – Is the limit strict?

  • lower (bool) – Is it a lower limit?

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

property explanation: str

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str

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

Get the measure.

Returns:

The measure.

Return type:

Measure

property strategies: Sequence[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: 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:

Iterator[Predicate]

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

Get the explanation.

Returns:

The explanation.

Return type:

str

property keep: int

Get the keep value.

Returns:

The keep value.

Return type:

int

property label: str

Get the label.

Returns:

The label.

Return type:

str

property maximize: bool

Get the maximize flag.

Returns:

The maximize flag.

Return type:

bool

property measure: 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[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: 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:

Iterator[Predicate]

__init__(*strategies: Strategy, conditions: Iterable[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[Predicate]

Get the conditions.

Returns:

The conditions.

Return type:

Sequence[Predicate]

property explanation: str

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str

property strategies: Sequence[Strategy]

Get the strategies.

Returns:

The sequence of strategies.

Return type:

Sequence[Strategy]

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

Get the characteristics of this explorer.

Returns:

The characteristics.

Return type:

Sequence[Characteristic]

property descriptions: Sequence[Description]

Get the descriptions of this explorer.

Returns:

The descriptions.

Return type:

Sequence[Description]

classmethod from_file(stream: IO[str]) Explorer

Create an explorer from a readable opened file.

Parameters:

stream (IO[str]) – File to read

Returns:

A new explorer.

Return type:

Explorer

property measures: Sequence[Measure]

Get the measures of this explorer.

Returns:

The measures.

Return type:

Sequence[Measure]

property predicates: Sequence[Predicate]

Get the predicates of this explorer.

Returns:

The characteristics.

Return type:

Sequence[Predicate]

property strategies: Sequence[Strategy]

Get the strategies of this explorer.

Returns:

The strategies.

Return type:

Sequence[Strategy]

write(stream: IO[str]) None

Write an explorer to a file in yaml format.

Parameters:

stream (IO[str]) – A file to be written

next_priority_concept(closure: ConceptClosure, strategies: Sequence[Strategy]) Iterator[Neighbourhood[Concept]]

Produce a collection of triples (concept, successors, predecessors).

Parameters:
Returns:

An iterator of all concepts and their successors, predecessors.

Return type:

Iterator[Neighbourhood[Concept]]