🐍 Categorical Description#
Predicates#
The CategoryPredicate predicate can be used to test whether an individual lies in a category.
[1]:
from galactic.algebras.concept.core import Item
from galactic.algebras.convex.characteristics.core import Component, String
from galactic.algebras.convex.descriptions.category.basic.core import CategoryPredicate
category = CategoryPredicate(
space=(String(components=(Component(),), name="category"),),
elements=("a", "b", "c"),
)
str(category)
[1]:
"category ∈ {'a', 'b', 'c'}"
[2]:
category(Item(value="a"))
[2]:
True
[3]:
category(Item(value="d"))
[3]:
False
Descriptions#
A CategoryDescription can describe a collection of individuals by subset of possible of these indidividuals.
[4]:
from galactic.algebras.convex.characteristics.core import Component, String
from galactic.algebras.convex.descriptions.category.basic.core import (
CategoryDescription,
)
characteristic = String(components=(Component(),))
description = CategoryDescription(space=(characteristic,))
[5]:
[str(attr) for attr in description([Item(value="a"), Item(value="b")])]
[5]:
["str(@) ∈ {'a', 'b'}"]
[6]:
[str(attr) for attr in description([Item()])]
[6]:
[]
[7]:
[str(attr) for attr in description([])]
[7]:
['⊥']
Concepts#
[8]:
from galactic.algebras.concept.core import ItemUniverse
from galactic.algebras.convex.characteristics.core import Component, Integer, String
from galactic.algebras.convex.descriptions.category.basic.core import (
CategoryDescription,
)
from galactic.algebras.convex.descriptions.core import (
Concept,
Context,
GaloisConnection,
PredicateUniverse,
)
category = String(components=(Component(expr="[0]"),), name="category")
stars = Integer(components=(Component(expr="[1]"),), name="stars")
descriptions = [
CategoryDescription(space=(category,)),
CategoryDescription(space=(stars,)),
]
dataset = [["a", 0], ["b", 0], ["c", 1]]
context = Context(
ItemUniverse(dataset),
PredicateUniverse(descriptions=descriptions),
)
connection = GaloisConnection(context)
[9]:
list(context.domain)
[9]:
[Item(key=0, value=<list object at 0x7c2e7bdfea00>),
Item(key=1, value=<list object at 0x7c2e7bdfe9c0>),
Item(key=2, value=<list object at 0x7c2e7bdfd880>)]
[10]:
top = Concept(connection)
[11]:
list(top.extent)
[11]:
[Item(key=0, value=<list object at 0x7c2e7bdfea00>),
Item(key=1, value=<list object at 0x7c2e7bdfe9c0>),
Item(key=2, value=<list object at 0x7c2e7bdfd880>)]
[12]:
[str(attr) for attr in top.intent]
[12]:
["category ∈ {'a', 'b', 'c'}", 'stars ∈ {0, 1}']
[13]:
bot = Concept(connection, items=[])
[14]:
list(bot.extent)
[14]:
[]
[15]:
[str(attr) for attr in bot.intent]
[15]:
['⊥', '⊥']
[16]:
from galactic.algebras.concept.core import ExtensibleLattice
from galactic.algebras.concept.renderer import (
ConceptRenderer,
ConceptHasseDiagramDrawer,
)
from galactic.algebras.convex.strategies.core import NaiveStrategy
lattice = ExtensibleLattice()
drawer = ConceptHasseDiagramDrawer(domain_renderer=ConceptRenderer())
drawer.draw(lattice)
[16]:
[17]:
lattice.extend([top])
drawer.draw(lattice)
[17]:
[18]:
lattice.extend([bot])
drawer.draw(lattice)
[18]:
[19]:
strategy = NaiveStrategy(descriptions=descriptions)
predecessors = list(strategy(top))
display(predecessors)
[<galactic.algebras.convex.descriptions.core.Concept object at 0x7c2e7bc06080>,
<galactic.algebras.convex.descriptions.core.Concept object at 0x7c2e7bc05590>,
<galactic.algebras.convex.descriptions.core.Concept object at 0x7c2e7bc06170>]
[20]:
lattice.extend([predecessors[0]])
drawer.draw(lattice)
[20]:
[21]:
lattice.extend([predecessors[1]])
drawer.draw(lattice)
[21]:
[22]:
lattice.extend([predecessors[2]])
drawer.draw(lattice)
[22]: