📘 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)
top
bottom = Concept(connection, items=[])
bottom
<galactic.algebras.concept.core.Concept object at 0x7aa7a0420880>
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 0x7aa7a0548300>
[Item(key='Dove', value=<tuple object at 0x7aa7a04e6070>),
Item(key='Hen', value=<tuple object at 0x7aa7a0506040>),
Item(key='Duck', value=<tuple object at 0x7aa7a01e13a0>),
Item(key='Goose', value=<tuple object at 0x7aa7a01e13a0>),
Item(key='Owl', value=<tuple object at 0x7aa7a01e13f0>),
Item(key='Hawk', value=<tuple object at 0x7aa7a01e13f0>),
Item(key='Eagle', value=<tuple object at 0x7aa7a01e1440>),
Item(key='Fox', value=<tuple object at 0x7aa7a01e1490>),
Item(key='Dog', value=<tuple object at 0x7aa7a946f740>),
Item(key='Wolf', value=<tuple object at 0x7aa7a04b5180>),
Item(key='Cat', value=<tuple object at 0x7aa7a01e14e0>),
Item(key='Tiger', value=<tuple object at 0x7aa7a01e1530>),
Item(key='Lion', value=<tuple object at 0x7aa7a01ae140>),
Item(key='Horse', value=<tuple object at 0x7aa7a01afa60>),
Item(key='Zebra', value=<tuple object at 0x7aa7a01afa60>),
Item(key='Cow', value=<tuple object at 0x7aa7a946f8d0>)]
<galactic.algebras.concept.core.Intent object at 0x7aa7a0200600>
[]
<galactic.algebras.concept.core.Extent object at 0x7aa7a02016c0>
[]
<galactic.algebras.concept.core.Intent object at 0x7aa7a01e5740>
[<function small at 0x7aa7a01c4860>,
<function medium at 0x7aa7a01d6480>,
<function big at 0x7aa7a01d65c0>,
<function twolegs at 0x7aa7a01d6980>,
<function fourlegs at 0x7aa7a01d6d40>,
<function hair at 0x7aa7a01d7100>,
<function feathers at 0x7aa7a01d6160>,
<function fly at 0x7aa7a01d77e0>,
<function swim at 0x7aa7a01d7ba0>,
<function run at 0x7aa7a01d7f60>,
<function hunt at 0x7aa7a01f8360>,
<function mane at 0x7aa7a01f8720>,
<function hooves at 0x7aa7a01f8ae0>]
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,
items=[
context.domain.item(key='Cat'),
context.domain.item(key='Wolf'),
],
)
concept_2 = Concept(
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 0x7aa7a05168c0>
[Item(key='Wolf', value=<tuple object at 0x7aa7a04b5180>),
Item(key='Lion', value=<tuple object at 0x7aa7a01ae140>)]
<galactic.algebras.concept.core.Intent object at 0x7aa7a04f5e80>
[<function fourlegs at 0x7aa7a01d6d40>,
<function hair at 0x7aa7a01d7100>,
<function run at 0x7aa7a01d7f60>,
<function hunt at 0x7aa7a01f8360>,
<function mane at 0x7aa7a01f8720>]
<galactic.algebras.concept.core.Extent object at 0x7aa7a020c880>
[Item(key='Fox', value=<tuple object at 0x7aa7a01e1490>),
Item(key='Dog', value=<tuple object at 0x7aa7a946f740>),
Item(key='Wolf', value=<tuple object at 0x7aa7a04b5180>),
Item(key='Cat', value=<tuple object at 0x7aa7a01e14e0>),
Item(key='Tiger', value=<tuple object at 0x7aa7a01e1530>),
Item(key='Lion', value=<tuple object at 0x7aa7a01ae140>),
Item(key='Horse', value=<tuple object at 0x7aa7a01afa60>),
Item(key='Zebra', value=<tuple object at 0x7aa7a01afa60>)]
<galactic.algebras.concept.core.Intent object at 0x7aa7a0506480>
[<function fourlegs at 0x7aa7a01d6d40>,
<function hair at 0x7aa7a01d7100>,
<function run at 0x7aa7a01d7f60>]
True
True
True