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

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

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 0x7440c1ee5840>
[Item(key='Dove', value=<list object at 0x7440c149d5c0>),
 Item(key='Hen', value=<list object at 0x7440c14b5740>),
 Item(key='Duck', value=<list object at 0x7440c14b5780>),
 Item(key='Goose', value=<list object at 0x7440c14b57c0>),
 Item(key='Owl', value=<list object at 0x7440c14b5800>),
 Item(key='Hawk', value=<list object at 0x7440c14b5840>),
 Item(key='Eagle', value=<list object at 0x7440c14b5880>),
 Item(key='Fox', value=<list object at 0x7440c14b58c0>),
 Item(key='Dog', value=<list object at 0x7440c14b5900>),
 Item(key='Wolf', value=<list object at 0x7440c14b5940>),
 Item(key='Cat', value=<list object at 0x7440c14b5980>),
 Item(key='Tiger', value=<list object at 0x7440c14b59c0>),
 Item(key='Lion', value=<list object at 0x7440c14b5a00>),
 Item(key='Horse', value=<list object at 0x7440c14b5a40>),
 Item(key='Zebra', value=<list object at 0x7440c14b5a80>),
 Item(key='Cow', value=<list object at 0x7440c14b5ac0>)]
<galactic.algebras.concept.core.Intent object at 0x7440c14d88c0>
[]
<galactic.algebras.concept.core.Extent object at 0x7440c14d8800>
[]
<galactic.algebras.concept.core.Intent object at 0x7440c1e07080>
[<function small at 0x7440c1fd7c40>,
 <function medium at 0x7440c14a7b00>,
 <function big at 0x7440c14a7c40>,
 <function twolegs at 0x7440c14c0040>,
 <function fourlegs at 0x7440c14c0400>,
 <function hair at 0x7440c14c07c0>,
 <function feathers at 0x7440c14a6660>,
 <function fly at 0x7440c14c0ea0>,
 <function swim at 0x7440c14c1260>,
 <function run at 0x7440c14c1620>,
 <function hunt at 0x7440c14c19e0>,
 <function mane at 0x7440c14c1da0>,
 <function hooves at 0x7440c14c2160>]

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 0x7440c14dd500>
[Item(key='Wolf', value=<list object at 0x7440c14b5940>),
 Item(key='Lion', value=<list object at 0x7440c14b5a00>)]
<galactic.algebras.concept.core.Intent object at 0x7440c14b4d80>
[<function fourlegs at 0x7440c14c0400>,
 <function hair at 0x7440c14c07c0>,
 <function run at 0x7440c14c1620>,
 <function hunt at 0x7440c14c19e0>,
 <function mane at 0x7440c14c1da0>]
<galactic.algebras.concept.core.Extent object at 0x7440c1fe2700>
[Item(key='Fox', value=<list object at 0x7440c14b58c0>),
 Item(key='Dog', value=<list object at 0x7440c14b5900>),
 Item(key='Wolf', value=<list object at 0x7440c14b5940>),
 Item(key='Cat', value=<list object at 0x7440c14b5980>),
 Item(key='Tiger', value=<list object at 0x7440c14b59c0>),
 Item(key='Lion', value=<list object at 0x7440c14b5a00>),
 Item(key='Horse', value=<list object at 0x7440c14b5a40>),
 Item(key='Zebra', value=<list object at 0x7440c14b5a80>)]
<galactic.algebras.concept.core.Intent object at 0x7440c1e06880>
[<function fourlegs at 0x7440c14c0400>,
 <function hair at 0x7440c14c07c0>,
 <function run at 0x7440c14c1620>]
True
True
True