📘 Formal concepts

📘 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 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 ConceptGaloisConnection 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).

<galactic.algebras.concept.core.Concept object at 0x7ff808305c00>

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.

display(top.extent, list(top.extent))
display(top.intent, list(top.intent))
display(bottom.extent, list(bottom.extent))
display(bottom.intent, list(bottom.intent))
<galactic.algebras.concept.core.Extent object at 0x7ff7ef71b2c0>
[Item(key='Dove', value=<tuple object at 0x7ff8082ba3e0>),
 Item(key='Hen', value=<tuple object at 0x7ff8082d3dc0>),
 Item(key='Duck', value=<tuple object at 0x7ff7ef71c040>),
 Item(key='Goose', value=<tuple object at 0x7ff7ef71c040>),
 Item(key='Owl', value=<tuple object at 0x7ff7ef71c090>),
 Item(key='Hawk', value=<tuple object at 0x7ff7ef71c090>),
 Item(key='Eagle', value=<tuple object at 0x7ff7ef71c0e0>),
 Item(key='Fox', value=<tuple object at 0x7ff7ef71c130>),
 Item(key='Dog', value=<tuple object at 0x7ff8082b9670>),
 Item(key='Wolf', value=<tuple object at 0x7ff808467940>),
 Item(key='Cat', value=<tuple object at 0x7ff7ef71c180>),
 Item(key='Tiger', value=<tuple object at 0x7ff7ef71c1d0>),
 Item(key='Lion', value=<tuple object at 0x7ff80814fa60>),
 Item(key='Horse', value=<tuple object at 0x7ff7ef70cd00>),
 Item(key='Zebra', value=<tuple object at 0x7ff7ef70cd00>),
 Item(key='Cow', value=<tuple object at 0x7ff8082b9c10>)]
<galactic.algebras.concept.core.Intent object at 0x7ff808306c80>
[]
<galactic.algebras.concept.core.Extent object at 0x7ff7ef738d40>
[]
<galactic.algebras.concept.core.Intent object at 0x7ff8082d6a40>
[<function small at 0x7ff7ef7084a0>,
 <function medium at 0x7ff7ef709a80>,
 <function big at 0x7ff7ef709bc0>,
 <function twolegs at 0x7ff7ef709f80>,
 <function fourlegs at 0x7ff7ef70a340>,
 <function hair at 0x7ff7ef70a700>,
 <function feathers at 0x7ff7ef709760>,
 <function fly at 0x7ff7ef70ade0>,
 <function swim at 0x7ff7ef70b1a0>,
 <function run at 0x7ff7ef70b560>,
 <function hunt at 0x7ff7ef70b920>,
 <function mane at 0x7ff7ef70bce0>,
 <function hooves at 0x7ff7ef7280e0>]

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 0x7ff7ef7356c0>
[Item(key='Wolf', value=<tuple object at 0x7ff808467940>),
 Item(key='Lion', value=<tuple object at 0x7ff80814fa60>)]
<galactic.algebras.concept.core.Intent object at 0x7ff7ef735700>
[<function fourlegs at 0x7ff7ef70a340>,
 <function hair at 0x7ff7ef70a700>,
 <function run at 0x7ff7ef70b560>,
 <function hunt at 0x7ff7ef70b920>,
 <function mane at 0x7ff7ef70bce0>]
<galactic.algebras.concept.core.Extent object at 0x7ff7ef734880>
[Item(key='Fox', value=<tuple object at 0x7ff7ef71c130>),
 Item(key='Dog', value=<tuple object at 0x7ff8082b9670>),
 Item(key='Wolf', value=<tuple object at 0x7ff808467940>),
 Item(key='Cat', value=<tuple object at 0x7ff7ef71c180>),
 Item(key='Tiger', value=<tuple object at 0x7ff7ef71c1d0>),
 Item(key='Lion', value=<tuple object at 0x7ff80814fa60>),
 Item(key='Horse', value=<tuple object at 0x7ff7ef70cd00>),
 Item(key='Zebra', value=<tuple object at 0x7ff7ef70cd00>)]
<galactic.algebras.concept.core.Intent object at 0x7ff7ef735a00>
[<function fourlegs at 0x7ff7ef70a340>,
 <function hair at 0x7ff7ef70a700>,
 <function run at 0x7ff7ef70b560>]
True
True
True