📘 Strategies#
The galactic.algebras.convex.strategies.core module defines the foundational
building blocks of strategies.
It provides:
the
Strategyprotocolthe
BasicStrategyprotocol whose results are computed from the characteristics of items. Each subclass implements a specific way to compute the strategy result from the characteristics of item using the_call()method.
Creating strategies#
A strategy is created from a sequence of characteristics and some optional parameters depending on the strategy type.
from galactic.algebras.concept.core import ItemUniverse
from galactic.algebras.convex.characteristics.core import Integer
from galactic.algebras.convex.descriptions.core import (
PredicateUniverse,
Context,
GaloisConnection,
)
from galactic.algebras.convex.strategies.examples.arithmetic.core import (
MultipleStrategy,
)
from galactic.algebras.convex.descriptions.examples.arithmetic.core import (
MultipleDescription,
DivisorDescription,
)
dataset = [36, 48, 16]
domain = ItemUniverse(dataset)
characteristic = Integer()
descriptions = [
DivisorDescription(characteristic=characteristic),
MultipleDescription(characteristic=characteristic),
]
co_domain = PredicateUniverse(*descriptions)
context = Context(domain, co_domain)
connection = GaloisConnection(context)
strategy = MultipleStrategy(characteristic=characteristic)
Applying strategies#
from galactic.algebras.convex.descriptions.core import Concept
top = Concept(connection)
display([str(attr) for attr in top.intent])
concepts = list(strategy(top))
display(
[
[str(attr) for attr in sub.intent]
for sub in concepts
]
)
display(
[
[item.key for item in sub.extent]
for sub in concepts
]
)
['D(int(@),144)', 'M(int(@),4)']
[['D(int(@),144)', 'M(int(@),4)', 'M(int(@),3)'],
['D(int(@),48)', 'M(int(@),16)']]
[[0, 1], [1, 2]]
Extending lattice#
from galactic.algebras.concept.core import ExtensibleLattice
from galactic.algebras.concept.viewer import ConceptRenderer
from galactic.algebras.poset.viewer import HasseDiagram
lattice = ExtensibleLattice()
diagram = HasseDiagram(lattice, domain_renderer=ConceptRenderer(lattice))
diagram
lattice.extend([top])
diagram
lattice.extend(concepts)
diagram