🐍 Numerical Quantile Strategy#

Preparing the context#

[1]:
from galactic.algebras.concept.core import ItemUniverse
from galactic.algebras.convex.characteristics.core import Component, Number
from galactic.algebras.convex.descriptions.core import (
    Concept,
    Context,
    GaloisConnection,
    PredicateUniverse,
)
from galactic.algebras.convex.descriptions.numerical.hull.core import (
    NumericalDescription,
)
from galactic.algebras.convex.strategies.numerical.quantile.core import (
    QuantileStrategy,
)
[2]:
dataset = {
    "Darth Vador": {"age": 46, "height": 202},
    "Boba Fett": {"age": 36, "height": 183},
    "Chewbacca": {"age": 204, "height": 230},
    "Han Solo": {"age": 36, "height": 180},
    "Leia Organa": {"age": 23, "height": 150},
    "Luke Skywalker": {"age": 23, "height": 172},
}
age = Number(components=(Component(expr="age"),), name="age")
height = Number(components=(Component(expr="height"),), name="height")
context = Context(
    ItemUniverse(dataset),
    PredicateUniverse(
        descriptions=(
            NumericalDescription(space=(age,)),
            NumericalDescription(space=(height,)),
        ),
    ),
)
connection = GaloisConnection(context)

Creating the concept lattice#

[3]:
from galactic.algebras.concept.core import ExtensibleLattice
from galactic.algebras.concept.renderer import (
    ConceptRenderer,
    ConceptHasseDiagramDrawer,
)

concept = Concept(connection)
lattice = ExtensibleLattice([concept])
drawer = ConceptHasseDiagramDrawer(domain_renderer=ConceptRenderer())
drawer.draw(lattice)
[3]:
../../../../../../../../_images/share_galactic_algebras_convex_strategies_numerical_quantile_notebooks_notebook_4_0.svg

Extending the concept lattice with the quantile strategy#

[4]:
from galactic.algebras.convex.strategies.numerical.quantile.core import QuantileStrategy

lattice.extend(list(QuantileStrategy(space=(age,), lower=True)(concept)))
lattice.extend(list(QuantileStrategy(space=(height,), lower=True)(concept)))
drawer.draw(lattice)
[4]:
../../../../../../../../_images/share_galactic_algebras_convex_strategies_numerical_quantile_notebooks_notebook_6_0.svg
[5]:
from galactic.algebras.convex.strategies.numerical.quantile.core import QuantileStrategy

lattice.extend(list(QuantileStrategy(space=(age,), lower=False)(concept)))
lattice.extend(list(QuantileStrategy(space=(height,), lower=False)(concept)))
drawer.draw(lattice)
[5]:
../../../../../../../../_images/share_galactic_algebras_convex_strategies_numerical_quantile_notebooks_notebook_7_0.svg

Comparing with the naive strategy#

[6]:
from galactic.algebras.convex.strategies.numerical.quantile.core import QuantileStrategy
from galactic.algebras.convex.strategies.core import NaiveStrategy, RecursiveStrategy

lattice.extend(
    list(
        RecursiveStrategy(
            strategies=(
                NaiveStrategy(
                    descriptions=context.descriptions,
                ),
            ),
        )(concept)
    )
)
drawer.draw(lattice)
[6]:
../../../../../../../../_images/share_galactic_algebras_convex_strategies_numerical_quantile_notebooks_notebook_9_0.svg