📘 Formal concepts#
Formal concepts are the building blocks of formal concept analysis (FCA), representing
the relationships between a set of items and their attributes. In the GALACTIC
framework, formal concepts are implemented using the
Concept class of the
galactic.algebras.concept.core module, which allows for the creation,
manipulation, and analysis of these concepts within a given antitone Galois connection.
Creating concepts#
The constructor of the Concept class takes
an instance of the
GaloisConnection class as input,
which defines the context in which the concepts are formed and optionnally an iterable
of items or attributes to initialize the concept. When neither items nor attributes
are provided, the concept is initialized as the top concept (with full extent and
smallest intent).
from galactic.algebras.concept.core import (
Concept,
GaloisConnection,
create_context_from_dataset
)
from galactic.algebras.concept.examples.animals.core import ANIMAL_ATTRS, ANIMAL_DATA
context = create_context_from_dataset(ANIMAL_DATA, ANIMAL_ATTRS)
connection = GaloisConnection(context)
top = Concept(connection=connection)
top
bottom = Concept(connection=connection, items=[])
bottom
<galactic.algebras.concept.core.Concept object at 0x76c1e8148e80>
The extent and intent of the concept can be accessed using the
extent and
intent attributes, respectively.
They are closed sets of items and attributes within the context of the antitone
Galois connection.
<galactic.algebras.concept.core.Extent object at 0x76c1e7993200>
[Item(key='Dove', value=<list object at 0x76c1e7990a00>),
Item(key='Hen', value=<list object at 0x76c1e7990d40>),
Item(key='Duck', value=<list object at 0x76c1e7990a40>),
Item(key='Goose', value=<list object at 0x76c1e7990d80>),
Item(key='Owl', value=<list object at 0x76c1e7990dc0>),
Item(key='Hawk', value=<list object at 0x76c1e7990e00>),
Item(key='Eagle', value=<list object at 0x76c1e7990e40>),
Item(key='Fox', value=<list object at 0x76c1e7990e80>),
Item(key='Dog', value=<list object at 0x76c1e7990ec0>),
Item(key='Wolf', value=<list object at 0x76c1e7990f00>),
Item(key='Cat', value=<list object at 0x76c1e7990f40>),
Item(key='Tiger', value=<list object at 0x76c1e7990f80>),
Item(key='Lion', value=<list object at 0x76c1e7990fc0>),
Item(key='Horse', value=<list object at 0x76c1e7991000>),
Item(key='Zebra', value=<list object at 0x76c1e7991040>),
Item(key='Cow', value=<list object at 0x76c1e7991080>)]
<galactic.algebras.concept.core.Intent object at 0x76c1e79a0600>
[]
<galactic.algebras.concept.core.Extent object at 0x76c1e8147a80>
[]
<galactic.algebras.concept.core.Intent object at 0x76c1e7975a40>
[<function small at 0x76c1e815c900>,
<function medium at 0x76c1e79942c0>,
<function big at 0x76c1e7994400>,
<function twolegs at 0x76c1e79947c0>,
<function fourlegs at 0x76c1e7994b80>,
<function hair at 0x76c1e7994f40>,
<function feathers at 0x76c1e797ade0>,
<function fly at 0x76c1e7995620>,
<function swim at 0x76c1e79959e0>,
<function run at 0x76c1e7995da0>,
<function hunt at 0x76c1e7996160>,
<function mane at 0x76c1e7996520>,
<function hooves at 0x76c1e79968e0>]
Operating on concepts#
The Concept class implements the
Element protocol of the
galactic.algebras.lattice.core module, which
also provides methods to create concepts using the join (\(\vee\)) or
meet (\(\wedge\)) operators.
concept_1 = Concept(
connection=connection,
items=[
context.domain.item(key='Cat'),
context.domain.item(key='Wolf'),
],
)
concept_2 = Concept(
connection=connection,
attrs=[
context.co_domain.attr(name='mane'),
],
)
join = concept_1 | concept_2
meet = concept_1 & concept_2
display(meet.extent, list(meet.extent))
display(meet.intent, list(meet.intent))
display(join.extent, list(join.extent))
display(join.intent, list(join.intent))
display(meet <= join, meet.extent <= join.extent, meet.intent >= join.intent)
<galactic.algebras.concept.core.Extent object at 0x76c1e79b1880>
[Item(key='Wolf', value=<list object at 0x76c1e7990f00>),
Item(key='Lion', value=<list object at 0x76c1e7990fc0>)]
<galactic.algebras.concept.core.Intent object at 0x76c1e79b1840>
[<function fourlegs at 0x76c1e7994b80>,
<function hair at 0x76c1e7994f40>,
<function run at 0x76c1e7995da0>,
<function hunt at 0x76c1e7996160>,
<function mane at 0x76c1e7996520>]
<galactic.algebras.concept.core.Extent object at 0x76c1e7960300>
[Item(key='Fox', value=<list object at 0x76c1e7990e80>),
Item(key='Dog', value=<list object at 0x76c1e7990ec0>),
Item(key='Wolf', value=<list object at 0x76c1e7990f00>),
Item(key='Cat', value=<list object at 0x76c1e7990f40>),
Item(key='Tiger', value=<list object at 0x76c1e7990f80>),
Item(key='Lion', value=<list object at 0x76c1e7990fc0>),
Item(key='Horse', value=<list object at 0x76c1e7991000>),
Item(key='Zebra', value=<list object at 0x76c1e7991040>)]
<galactic.algebras.concept.core.Intent object at 0x76c1e8354d00>
[<function fourlegs at 0x76c1e7994b80>,
<function hair at 0x76c1e7994f40>,
<function run at 0x76c1e7995da0>]
True
True
True