Strategies¶
The galactic.strategies
module defines
the
galactic.strategies.Strategy
class which is the super-class of all strategies classes;the
galactic.strategies.Explorer
class for representing list of strategies;the
galactic.strategies.BasicStrategy
class which must be inherited to implement a new strategy;the
galactic.strategies.AbsurdStrategy
class which generates no predecessors;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.PredecessorCardinality
which measures the cardinality of the predecessor;the
galactic.strategies.Support
which measures the support of an concept;the
galactic.strategies.PredecessorSupport
which measures the support of the predecessor;the
galactic.strategies.Confidence
which measures the ratio between the confidence of a concept.
-
class
galactic.strategies.
Strategy
Bases:
collections.abc.Hashable
The
Strategy
class produces, for a collection of individuals, a collection of candidate predicates.-
descriptions
An iterator over the description spaces linked to this strategy.
-
selection
(concept: galactic.concepts.main.Concept) → Iterator[galactic.descriptions.main.Predicate] Compute an iterator over the selectors of a collection of individuals.
- Parameters
concept (
Concept
) – A concept.- Returns
An iterator over a collection of selectors.
- Return type
-
abstract
selectors
(concept: galactic.concepts.main.Concept) → Iterator[galactic.descriptions.main.Predicate] The
selectors()
method must return an iterator or selectors.- Parameters
concept (
Concept
) – The concept whose selectors are requested.- Returns
- Return type
-
abstract
descriptions
() → Iterator[galactic.descriptions.main.Description] Get an iterator over the descriptions.
- Returns
- Return type
-
-
class
galactic.strategies.
Explorer
Bases:
list
The
Explorer
class implements the NextPriorityConcept algorithm to compute a mapping from concepts to their predecessors and their successors.-
classmethod
from_file
(file: TextIO) → galactic.strategies.main.Explorer Create a list of strategies from a readable opened file.
- Keyword Arguments
file (
TextIOBase
) – File to read- Returns
A new list of strategies
- Return type
Explorer
-
run
(population: galactic.population.main.Population) → Iterator[Tuple[galactic.concepts.main.Concept, Tuple[Iterator[galactic.concepts.main.Concept], Iterator[galactic.concepts.main.Concept]]]] Produce a collection of couples (
Concept
, (Iterator[Concept]
,Iterator[Concept]
))- Returns
An iterator of all concepts and their couple (successors, predecessors).
- Return type
-
classmethod
-
class
galactic.strategies.
BasicStrategy
(description: galactic.descriptions.main.Description) Bases:
galactic.strategies.main.Strategy
The
BasicStrategy
class is used for classical strategies. This class is designed for sub-classing. Sub-classes must set the_description
slot in their constructor.-
descriptions
An iterator over the description spaces linked to this strategy. This iterator iterate over one value.
-
description
The description owned by this strategy.
- Type
Description
-
space
The description space of this strategy. This is a proxy to
self.description.space
.- Type
Tuple[Characteristic]
-
descriptions
() → Iterator[galactic.descriptions.main.Description] Get an iterator over the descriptions.
- Returns
- Return type
-
abstract
selectors
(concept: galactic.concepts.main.Concept) → Iterator[galactic.descriptions.main.Predicate] The
selectors()
method must return an iterator or selectors.- Parameters
concept (
Concept
) – The concept whose selectors are requested.- Returns
- Return type
-
-
class
galactic.strategies.
MetaStrategy
(*args: galactic.strategies.main.Strategy) Bases:
galactic.strategies.main.Strategy
The
MetaStrategy
class is used for strategy that own their proper inner strategies.-
descriptions
An iterator over the description spaces linked to this strategy.
-
strategies
The tuple of strategies owned by this meta-strategy.
- Type
Tuple[Strategy]
-
__init__
(*args: galactic.strategies.main.Strategy) → None Initialise a
MetaStrategy
instance.- Raises
TypeError – If an argument is not an instance of
Strategy
-
descriptions
() → Iterator[galactic.descriptions.main.Description] Get an iterator over the descriptions.
- Returns
- Return type
-
selectors
(concept: galactic.concepts.main.Concept) → Iterator[galactic.descriptions.main.Predicate] The
selectors()
method must return an iterator or selectors.- Parameters
concept (
Concept
) – The concept whose selectors are requested.- Returns
- Return type
-
-
class
galactic.strategies.
AbsurdStrategy
(*args: galactic.descriptions.main.Description) Bases:
galactic.strategies.main.Strategy
The
AbsurdStrategy
has been designed to describe individuals using predicates that must not be used for producing concepts.-
__init__
(*args: galactic.descriptions.main.Description) → None Initialize an
AbsurdStrategy
instance.- Keyword Arguments
*args (
Collection[Description]
) – A collection of description spaces
-
selectors
(concept: galactic.concepts.main.Concept) → Iterator[galactic.descriptions.main.Predicate] The
selectors()
method must return an iterator or selectors.- Parameters
concept (
Concept
) – The concept whose selectors are requested.- Returns
- Return type
-
descriptions
() → Iterator[galactic.descriptions.main.Description] Get an iterator over the descriptions.
- Returns
- Return type
-
-
class
galactic.strategies.
LimitFilter
(*args: galactic.strategies.main.Strategy, limit: SupportsFloat = 0.0, strict: bool = False, lower: bool = True, **kwargs: Any) Bases:
galactic.strategies.filters.Filter
The
LimitFilter
class limits the possible predecessors by choosing those whose measure is greater (or less than a threshold).-
__init__
(*args: galactic.strategies.main.Strategy, limit: SupportsFloat = 0.0, strict: bool = False, lower: bool = True, **kwargs: Any) → None Initialize a
LimitFilter
class.- Keyword Arguments
limit (
SupportsFloat
) – The limit valuestrict (
bool
) – Is the limit strict?lower (
bool
) – Is it a lower limit?
-
selectors
(concept: galactic.concepts.main.Concept) → Iterator[galactic.descriptions.main.Predicate] The
selectors()
method must return an iterator or selectors.- Parameters
concept (
Concept
) – The concept whose selectors are requested.- Returns
- Return type
-
-
class
galactic.strategies.
SelectionFilter
(*args: galactic.strategies.main.Strategy, keep: SupportsInt = 1, maximize: bool = True, decrease: bool = True, strict: bool = False, rate: SupportsFloat = 1.0, **kwargs: Any) Bases:
galactic.strategies.filters.Filter
The
SelectionFilter
class limits the possible predecessors by choosing those whose measure is among the greatest (or smallest).- 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.
-
selectors
(concept: galactic.concepts.main.Concept) → Iterator[galactic.descriptions.main.Predicate] The
selectors()
method must return an iterator or selectors.- Parameters
concept (
Concept
) – The concept whose selectors are requested.- Returns
- Return type
-
class
galactic.strategies.
Measure
Bases:
object
The
Measure
class is an abstract class. Its subclasses must implement the__call__()
method.-
abstract
__call__
(concept: galactic.concepts.main.Concept, predicate: galactic.descriptions.main.Predicate) → float The
__call__()
method evaluate the individuals present in the concept whose call to predicate is true.- Parameters
concept (
Concept
) – The concept for which individuals will be tested.- Keyword Arguments
predicate (
Predicate
) – The predicate to be tested.- Returns
The computed measure.
- Return type
-
abstract
-
class
galactic.strategies.
Cardinality
Bases:
galactic.strategies.measures.Measure
The
Cardinality
class computes the cardinality of the predecessor.
-
class
galactic.strategies.
Support
Bases:
galactic.strategies.measures.Measure
The
Support
class computes the support of the predecessor.
-
class
galactic.strategies.
Confidence
Bases:
galactic.strategies.measures.Measure
The
Confidence
class computes the cardinality ratio between the predecessor and the successor.
-
class
galactic.strategies.
Lattice
(population: galactic.population.main.Population, explorer: galactic.strategies.main.Explorer) Bases:
galactic.algebras.lattice.lattices.CompactLattice
The
Lattice
class implements theGeneratedBasicLattice
class.-
__init__
(population: galactic.population.main.Population, explorer: galactic.strategies.main.Explorer) Initialise a
Lattice
instance.- Parameters
population (
Population
) – The underlying populationexplorer (
Explorer
) – An explorer
-
maximum
() → galactic.concepts.main.Concept Get the maximum element of this join semi-lattice.
- Returns
The maximum element
- Return type
-
index
(concept: galactic.concepts.main.Concept) → int Get the index of a concept.
- Returns
- Return type
The index of a concept
-
new_predicates
(concept: galactic.concepts.main.Concept) → Iterator[galactic.descriptions.main.Predicate] Get the new predicates given by the concept.
- Parameters
concept (
Concept
) – The concept whose new predicates are requested.- Returns
An iterator over the new predicates.
- Return type
-
new_individuals
(concept: galactic.concepts.main.Concept) → Iterator[str] Get the new individuals given by the concept.
- Parameters
concept (
Concept
) – The concept whose new individuals are requested.- Returns
An iterator over the individual keys.
- Return type
-
population
() → galactic.population.main.Population Get the population
- Returns
The population
- Return type
Population
-
explorer
() → galactic.strategies.main.Explorer Get the explorer
- Returns
The explorer
- Return type
Explorer
-
-
class
galactic.strategies.
Table
(lattice: galactic.strategies.lattice.Lattice, **options: Any) Bases:
object
The
Table
class is used to represent lattice in jupyter notebooks.-
__init__
(lattice: galactic.strategies.lattice.Lattice, **options: Any) Initialize a
Table
class.- Parameters
lattice (
Lattice
) – The lattice whose table representation is requestedoptions (
dict
<python.dict>`) –A collection of options
all_individuals
is a boolean flag for displaying all individuals for each conceptall_predicates
is a boolean flag for displaying all predicates for each conceptconcept_width
the concept widthindividual_width
the individual widthpredicate_width
the predicate width
By default only new predicates and new individuals are displayed. The values of the given widths are compared with each other to allocate relative column sizes.
-