Concepts
The galactic.concepts
module contains classes for exploring concept lattices.
Concept
class is used to represent collections of objects that share a set of predicates;ConceptLattice
class is used to represent concept lattices;ConceptClosure
class is used to represent closure operators used inConceptLattice
instances.
Two classes allow to visualize concept lattices:
ConceptRenderer
,ConceptLatticeRenderer
andHierarchicalRenderer
classes are used to draw concept nodes into graphviz graphs.ConceptTable
class is used to display concepts into jupyter notebooks;
And two functions:
- class Concept(closure: galactic.concepts.ConceptClosure, keys: Optional[Iterable[str]] = None)
The
Concept
class represents a formal concept.- __and__(other: Any) galactic.concepts.Concept
Return the join of this concept and the other.
- Parameters:
other (
Concept
) – the other concept- Returns:
Concept
– the join of this concept and the otherNotImplementedType
–NotImplemented
if the other parameter is not a concept.
- Raises:
ValueError – If the closure operators of the two concepts are not identical.
- __eq__(other: Any) bool
Test if this concept is equal to the other.
- Parameters:
other (
Concept
) – the other concept- Returns:
bool –
True
if this concept is equal to the other.NotImplementedType
–NotImplemented
if the other parameter is not a concept.
- __ge__(other: Any) bool
Test if this concept is greater than or equal to the other.
- Parameters:
other (
Concept
) – the other concept- Returns:
bool –
True
if this concept is greater than or equal to the other.NotImplementedType
–NotImplemented
if the other parameter is not a concept.
- Raises:
ValueError – If the closure operators of the two concepts are not identical.
- __gt__(other: Any) bool
Test if this concept is greater than the other.
- Parameters:
other (
Concept
) – the other concept- Returns:
bool –
True
if this concept is greater than the other.NotImplementedType
–NotImplemented
if the other parameter is not a concept.
- Raises:
ValueError – If the closure operators of the two concepts are not identical.
- __init__(closure: galactic.concepts.ConceptClosure, keys: Optional[Iterable[str]] = None)
Initialise a
Concept
instance.- Parameters:
closure (
ConceptClosure
) – The concept closure operator.- Keyword Arguments:
keys (
Iterable[str]
, optional) – An iterable of identifiers.
- __le__(other: Any) bool
Test if this concept is lesser than or equal to the other.
- Parameters:
other (
Concept
) – the other concept- Returns:
bool –
True
if this concept is lesser than or equal to the other.NotImplementedType
–NotImplemented
if the other parameter is not a concept.
- Raises:
ValueError – If the closure operators of the two concepts are not identical.
- __lt__(other: Any) bool
Test if this concept is lesser than the other.
- Parameters:
other (
Concept
) – the other concept- Returns:
bool –
True
if this concept is lesser than the other.NotImplementedType
–NotImplemented
if the other parameter is not a concept.
- Raises:
ValueError – If the closure operators of the two concepts are not identical.
- __or__(other: Any) galactic.concepts.Concept
Return the join of this concept and the other.
- Parameters:
other (
Concept
) – the other concept- Returns:
Concept
– the join of this concept and the otherNotImplementedType
–NotImplemented
if the other parameter is not a concept.
- Raises:
ValueError – If the closure operators of the two concepts are not identical.
- property closure: galactic.concepts.ConceptClosure
Get the closure operator.
- Returns:
The closure operator.
- Return type:
- property descriptors: Mapping[galactic.descriptions.Description, AbstractSet[galactic.descriptions.Predicate]]
Get the descriptors.
- Returns:
The descriptors.
- Return type:
- enlarge(keys: Iterable[str]) galactic.concepts.Concept
Enlarge the concept by adding objects.
- Parameters:
keys (
Iterable[Predicate]
) – An iterable of identifiers.- Returns:
A new concept.
- Return type:
- equivalence(element: galactic.algebras.closure._main._T) Iterator[galactic.algebras.closure._main._T]
Compute equivalences of the element.
- Parameters:
element (
_T
) – The element whose equivalences are requested- Returns:
An iterator over the equivalence elements of element
- Return type:
- intersection(*args: Any) galactic.algebras.lattice.Meetable
Return the intersection of this element and the others.
- predicates() Iterator[galactic.descriptions.Predicate]
Get an iterator over the predicates.
- Returns:
- Return type:
- restrict(predicates: Iterable[galactic.descriptions.Predicate]) galactic.concepts.Concept
Restrict the concept by adding predicates.
- Parameters:
predicates (
Iterable[Predicate]
) – An iterable of predicates.- Returns:
A new concept.
- Return type:
- subsumption(element: galactic.algebras.closure._main._T) Iterator[galactic.algebras.closure._main._T]
Compute subsumed elements of the element.
- Parameters:
element (
_T
) – The element whose subsumed elements are requested- Returns:
An iterator over the subsumed elements of element
- Return type:
- supsumption(element: galactic.algebras.closure._main._T) Iterator[galactic.algebras.closure._main._T]
Compute supsumed elements of the element.
Notes
supsumption is a neologism to designate the inverse relation of subsumption.
- Parameters:
element (
_T
) – The element whose supsumed elements are requested- Returns:
An iterator over the supsumed elements of element
- Return type:
- union(*args: Any) galactic.algebras.lattice.Joinable
Return the union of this element and the others.
- class ConceptClosure(population: galactic.population.Population, descriptions: Iterable[galactic.descriptions.Description])
The
ConceptClosure
class.It allows to compute concepts using a closure operator.
- __call__(keys: Optional[Iterable[str]] = None) galactic.concepts.Concept
Initialise a concept using an iterable of identifiers.
- Keyword Arguments:
keys (
Iterable[str]
, optional) – An iterable of identifiers.- Returns:
A new concept equal to the closure of the keys.
- Return type:
- __init__(population: galactic.population.Population, descriptions: Iterable[galactic.descriptions.Description])
Initialise a
ConceptClosure
instance.- Parameters:
population (
Population
) – A population of individuals.descriptions (
Iterable[Description]
) – An iterable of descriptions.
- property descriptions: Sequence[galactic.descriptions.Description]
Get the descriptions.
- Returns:
The descriptions.
- Return type:
- property population: galactic.population.Population
Get the population.
- Returns:
The population of individuals.
- Return type:
- property universe: galactic.algebras.set.FiniteUniverse[str]
Get the underlying universe.
- Returns:
The underlying universe.
- Return type:
FiniteUniverse[str]
- class ConceptLattice(population: galactic.population.Population, descriptions: Iterable[galactic.descriptions.Description])
The
ConceptLattice
class represents concept lattices.- __copy__() galactic.algebras.lattice.Lattice[galactic.algebras.lattice._lattices._E]
Get a copy of the lattice.
The operation is in \(O(j+m)\).
- Returns:
The copy of this lattice.
- Return type:
- __init__(population: galactic.population.Population, descriptions: Iterable[galactic.descriptions.Description]) None
Initialise a
ConceptLattice
instance.- Parameters:
population (
Population
) – The population.descriptions (
Iterable[Description]
) – An iterable of descriptions.
- __iter__() Iterator[Tuple[galactic.algebras.poset._abstract._P, galactic.algebras.poset._abstract._P]]
Get an iterator over the elements.
- Returns:
An iterator over the elements
- Return type:
- apply(strategies: Iterable[galactic.strategies.Strategy]) None
Apply an iterable of strategies on a concept lattice.
- Parameters:
lattice (
ConceptLattice
) – The concept latticestrategies (
Iterable[Strategy]
) – The iterable of strategies
- property atoms: AbstractSet[galactic.algebras.lattice._lattices._E]
Get the atoms of this lattice.
- Returns:
The atoms
- Return type:
- property bottom: AbstractSet[galactic.algebras.lattice._lattices._E]
Get the bottom elements.
The collection contains only one element, the minimum element.
- Returns:
The bottom elements.
- Return type:
- property closure: galactic.concepts.ConceptClosure
Get the underlying closure operator.
- Returns:
The closure operator.
- Return type:
- property co_atoms: AbstractSet[galactic.algebras.lattice._lattices._E]
Get the co-atoms of this lattice.
- Returns:
The co-atoms.
- Return type:
- property co_domain: AbstractSet[galactic.algebras.lattice._lattices._E]
Get the co-domain of this lattice.
- Returns:
The co-domain of this lattice.
- Return type:
- property cover: galactic.algebras.poset.AbstractReversibleCoveringRelation[galactic.algebras.lattice._lattices._E]
Get the covering relation of this lattice.
- Returns:
The covering relation.
- Return type:
- classmethod create(population: galactic.population.Population, descriptions: Iterable[galactic.descriptions.Description], strategies: Iterable[galactic.strategies.Strategy]) galactic.concepts.ConceptLattice
Create a
ConceptLattice
instance.- Parameters:
cls (
Type[ConceptLattice]
) – TheConceptLattice
class.population (
Population
) – The population.descriptions (
Iterable[Description]
) – An iterable of descriptions.strategies (
Iterable[Strategy]
) – An iterable of strategies.
- Returns:
A concept lattice.
- Return type:
- property descriptions: Sequence[galactic.descriptions.Description]
Get the underlying descriptions.
- Returns:
The descriptions. It’s a proxy to
self.closure.descriptions
.- Return type:
- property domain: AbstractSet[galactic.algebras.lattice._lattices._E]
Get the domain of this lattice.
- Returns:
The domain of this lattice.
- Return type:
- extend(iterable: Iterable[galactic.algebras.lattice._lattices._E]) None
In-place enlarge the lattice with an iterable of elements.
- Parameters:
iterable (
Iterable[_E]
) – An iterable of elements
- filter(element: galactic.algebras.lattice._lattices._E) galactic.algebras.lattice.AbstractLattice[galactic.algebras.lattice._lattices._E]
Get a filter of a lattice.
- Parameters:
element (
_E
) – The lower limit- Returns:
The lower bounded lattice.
- Return type:
AbstractLattice[_E]
- Raises:
ValueError – If the element does not belong to the poset.
- property global_entropy: float
Compute the global entropy of the Moore family.
\[H(L)=\sum_{A\in L}p(A)I(A)=n-\frac{\sum_{A\in L}\kappa(( A,B))\log_2(\kappa(A))}{2^n}\]Notes
See Information .
- Returns:
The global entropy.
- Return type:
Examples
>>> from galactic.algebras.closure import MooreFamily >>> from galactic.examples.closure import NumericalClosure, NumericalClosed >>> elements = {0, 1, 2, 3, 4, 5} >>> closure = NumericalClosure(elements) >>> family = MooreFamily[NumericalClosed, int](closure) >>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])]) >>> round(family.global_entropy, 3) 1.311
- property global_information: float
Compute the global information of the Moore family.
It is equal to the global entropy multiplied by the number of element defined by the closure operator.
\[I(L)=n H(L)\]- Returns:
The global information.
- Return type:
Examples
>>> from galactic.algebras.closure import MooreFamily >>> from galactic.examples.closure import NumericalClosure, NumericalClosed >>> elements = {0, 1, 2, 3, 4, 5} >>> closure = NumericalClosure(elements) >>> family = MooreFamily[NumericalClosed, int](closure) >>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])]) >>> round(family.global_information, 3) 7.868
- property global_logarithmic_stability: float
Compute the global normalized logarithmic stability of the Moore family.
\[\lambda(L)=\sum_{A\in L}p(A)\lambda(A)\]- Returns:
The global normalized logarithmic stability.
- Return type:
Examples
>>> from galactic.algebras.closure import MooreFamily >>> from galactic.examples.closure import NumericalClosure, NumericalClosed >>> elements = {0, 1, 2, 3, 4, 5} >>> closure = NumericalClosure(elements) >>> family = MooreFamily[NumericalClosed, int](closure) >>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])]) >>> round(family.global_logarithmic_stability, 3) 0.335
- property global_stability: float
Compute the global stability of the Moore family.
\[\sigma(L)=\sum_{A\in L}p(A)\sigma(A) =\sum_{A\in L}\frac{\kappa(A)^2}{2^{|A|+n}}\]- Returns:
The global stability.
- Return type:
Examples
>>> from galactic.algebras.closure import MooreFamily >>> from galactic.examples.closure import NumericalClosure, NumericalClosed >>> elements = {0, 1, 2, 3, 4, 5} >>> closure = NumericalClosure(elements) >>> family = MooreFamily[NumericalClosed, int](closure) >>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])]) >>> round(family.global_stability, 3) 0.703
- greatest_join_irreducible(element: galactic.algebras.lattice._lattices._E) AbstractSet[galactic.algebras.lattice._lattices._E]
Get the greatest join irreducible smaller than an element.
- Parameters:
element (
_E
) – The element whose greatest join irreducible are requested- Returns:
The greatest join irreducible smaller than the element.
- Return type:
- Raises:
ValueError – If the element does not belong to the lattice.
- ideal(element: galactic.algebras.lattice._lattices._E) galactic.algebras.lattice.AbstractLattice[galactic.algebras.lattice._lattices._E]
Get an ideal of a lattice.
- Parameters:
element (
_E
) – The upper limit- Returns:
The upper bounded lattice.
- Return type:
AbstractLattice[_E]
- Raises:
ValueError – If the element does not belong to the poset.
- information() Iterator[Tuple[galactic.algebras.closure._main._E, float]]
Get an iterator on elements (\(A\), \(I(A)\)).
\(I(A)\) is the information of \(A\).
\[I(A)=-\log_2(p(A)\]- Returns:
An iterator on elements and their information.
- Return type:
Notes
See Information .
Examples
>>> from galactic.algebras.closure import MooreFamily >>> from galactic.examples.closure import NumericalClosure, NumericalClosed >>> elements = {0, 1, 2, 3, 4, 5} >>> closure = NumericalClosure(elements) >>> family = MooreFamily[NumericalClosed, int](closure) >>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])]) >>> for element, information in family.information(): ... print(list(element), information) [2, 3] 4.0 [2, 3, 4] 4.0 [1, 2, 3] 4.0 [1, 2, 3, 4] 4.0 [0, 1, 2, 3, 4, 5] 0.4150374992788439
- isdisjoint(other)
Return True if two sets have a null intersection.
- property join_irreducible: AbstractSet[galactic.algebras.lattice._lattices._E]
Get the join irreducible elements.
- Returns:
The join irreducible elements
- Return type:
- logarithmic_stabilities() Iterator[Tuple[galactic.algebras.closure._main._E, float]]
Get an iterator on (\(A\), \(\lambda(A)\)).
\(\lambda(A)\) is the normalized logarithmic stabilities of \(A\) (the normalized logarithmic stability is always between 0 and 1).
if \(\kappa(A)\) is equal to \(2^{|A|}\), the normalized logarithmic stability is equal to 1.
if \(\kappa(A)\) is equal to \(1\), the normalized logarithmic stability is equal to 0
the special case \(A=\emptyset\) (\(2^{|A|}=\kappa(A)=1\)) gives \(\lambda(\emptyset)=1\) by convention.
\[\begin{split}\begin{eqnarray} \lambda(A) &=&\frac{-\log_2\left(1-\sigma(A)+\frac{1}{2^{|A|}}\right)}{|A|}\\ &=&\frac{-\log_2\left(\frac{2^{|A|}-\kappa(A)+1}{2^{|A|}}\right)}{|A|}\\ &=&\frac{|A|-\log_2\left(2^{|A|}-\kappa(A)+1\right)}{|A|}\\ &=&1-\frac{\log_2\left(2^{|A|}-\kappa(A)+1\right)}{|A|}\\ \lambda(\emptyset) &=&1\\ \end{eqnarray}\end{split}\]See also
Notes
Originally, the logarithmic stability was defined using
\[\begin{split}\begin{eqnarray} -\log_2\left(1-\sigma(A)\right) &=&-\log_2\left(1-\frac{\kappa(A)}{2^{|A|}}\right)\\ &=&|A|-\log_2\left(2^{|A|}-\kappa(A)\right)\\ \end{eqnarray}\end{split}\]but this formulae can give an infinity value and it is not normalized between elements.
References
- Returns:
An iterator on elements and their normalized logarithmic stability.
- Return type:
Examples
>>> from galactic.algebras.closure import MooreFamily >>> from galactic.examples.closure import NumericalClosure, NumericalClosed >>> elements = {0, 1, 2, 3, 4, 5} >>> closure = NumericalClosure(elements) >>> family = MooreFamily[NumericalClosed, int](closure) >>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])]) >>> for element, stability in family.logarithmic_stabilities(): ... print(list(element), round(stability, 3)) [2, 3] 1.0 [2, 3, 4] 0.226 [1, 2, 3] 0.226 [1, 2, 3, 4] 0.075 [0, 1, 2, 3, 4, 5] 0.319
- lower_limit(limit: galactic.algebras.lattice._lattices._E, strict: bool = Ellipsis) AbstractSet[galactic.algebras.lattice._lattices._E]
Get the elements greater than a
limit
.- Parameters:
- Returns:
The selected elements.
- Return type:
- property maximum: galactic.algebras.lattice._lattices._E
Get the maximum element of this lattice.
- Returns:
the maximum element
- Return type:
- property meet_irreducible: AbstractSet[galactic.algebras.lattice._lattices._E]
Get the meet irreducible elements.
- Returns:
The meet irreducible elements
- Return type:
- property minimum: galactic.algebras.lattice._lattices._E
Get the minimum element of this lattice.
- Returns:
The minimum element
- Return type:
- parts() Iterator[Tuple[galactic.algebras.closure._main._E, int]]
Get an iterator on (\(A\), \(\kappa(A)\)).
\(\kappa(A)\) is the number of parts of \(A\) whose closure \(\phi\) equal to \(A\).
\[\kappa(A)= \left|\left\{ \tilde A\subseteq A: \phi\left(\tilde A\right)=A \right\}\right|\]- Returns:
An iterator on elements and the number of parts \(\tilde A\subseteq A\subseteq X\) whose closure is equal to the element.
- Return type:
Examples
>>> from galactic.algebras.closure import MooreFamily >>> from galactic.examples.closure import NumericalClosure, NumericalClosed >>> elements = {0, 1, 2, 3, 4, 5} >>> closure = NumericalClosure(elements) >>> family = MooreFamily[NumericalClosed, int](closure) >>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])]) >>> for element, count in family.parts(): ... print(list(element), count) [2, 3] 4 [2, 3, 4] 4 [1, 2, 3] 4 [1, 2, 3, 4] 4 [0, 1, 2, 3, 4, 5] 48
- property population: galactic.population.Population
Get the underlying population.
- Returns:
The population. It’s a proxy to
self.closure.population
.- Return type:
- predecessors(element: galactic.algebras.lattice._lattices._E) AbstractSet[galactic.algebras.lattice._lattices._E]
Get the predecessors of an
element
.- Parameters:
element (
_E
) – The element whose predecessors are requested- Returns:
The predecessors.
- Return type:
- Raises:
ValueError – If the element does not belong to the poset.
- probabilities() Iterator[Tuple[galactic.algebras.closure._main._E, float]]
Get an iterator on (\(A\), \(p(A)\)).
\(p(A)\) is the probability of \(A\).
\[p(A)=\frac{\kappa(A)}{2^n}\]See also
- Returns:
An iterator on elements and their probability.
- Return type:
Examples
>>> from galactic.algebras.closure import MooreFamily >>> from galactic.examples.closure import NumericalClosure, NumericalClosed >>> elements = {0, 1, 2, 3, 4, 5} >>> closure = NumericalClosure(elements) >>> family = MooreFamily[NumericalClosed, int](closure) >>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])]) >>> for element, probability in family.probabilities(): ... print(list(element), probability) [2, 3] 0.0625 [2, 3, 4] 0.0625 [1, 2, 3] 0.0625 [1, 2, 3, 4] 0.0625 [0, 1, 2, 3, 4, 5] 0.75
- property reduced_context: galactic.algebras.relational.AbstractBinaryRelation[galactic.algebras.lattice._lattices._E, galactic.algebras.lattice._lattices._E]
Get the reduced context from this lattice.
- Returns:
The reduced context.
- Return type:
- property sinks: AbstractSet[galactic.algebras.lattice._lattices._E]
Get the sink elements.
The collection contains only one element, the maximum element.
- Returns:
The sink elements.
- Return type:
- smallest_meet_irreducible(element: galactic.algebras.lattice._lattices._E) AbstractSet[galactic.algebras.lattice._lattices._E]
Get the smallest meet irreducible greater than an element.
- Parameters:
element (
_E
) – The element whose greatest join irreducible are requested- Returns:
The smallest meet irreducible smaller than the element.
- Return type:
- Raises:
ValueError – If the element does not belong to the lattice.
- property sources: AbstractSet[galactic.algebras.lattice._lattices._E]
Get the source elements.
The collection contains only one element, the minimum element.
- Returns:
The source elements.
- Return type:
- stabilities() Iterator[Tuple[galactic.algebras.closure._main._E, float]]
Get an iterator on (\(A\), \(\sigma(A)\)).
\(\sigma(A)\) is the stability of \(A\).
\[\sigma(A)=\frac{\kappa(A)}{2^{|A|}}\]See also
- Returns:
An iterator on elements and their stability.
- Return type:
Examples
>>> from galactic.algebras.closure import MooreFamily >>> from galactic.examples.closure import NumericalClosure, NumericalClosed >>> elements = {0, 1, 2, 3, 4, 5} >>> closure = NumericalClosure(elements) >>> family = MooreFamily[NumericalClosed, int](closure) >>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])]) >>> for element, stability in family.stabilities(): ... print(list(element), round(stability, 3)) [2, 3] 1.0 [2, 3, 4] 0.5 [1, 2, 3] 0.5 [1, 2, 3, 4] 0.25 [0, 1, 2, 3, 4, 5] 0.75
- successors(element: galactic.algebras.lattice._lattices._E) AbstractSet[galactic.algebras.lattice._lattices._E]
Get the successors of an
element
.- Parameters:
element (
_E
) – The element whose successors are requested- Returns:
The successors.
- Return type:
- Raises:
ValueError – If the element does not belong to the poset.
- property top: AbstractSet[galactic.algebras.lattice._lattices._E]
Get the top elements.
The collection contains only one element, the maximum element.
- Returns:
The top elements.
- Return type:
- property universes: Tuple[AbstractSet[galactic.algebras.lattice._lattices._E], AbstractSet[galactic.algebras.lattice._lattices._E]]
Get the universes of this lattice.
- Returns:
The universes.
- Return type:
- upper_limit(limit: galactic.algebras.lattice._lattices._E, strict: bool = False) AbstractSet[galactic.algebras.lattice._lattices._E]
Get the elements lesser than a
limit
.- Parameters:
- Returns:
The selected elements.
- Return type:
- class ConceptRenderer(fill_color: str = '#ffffff', current_color: str = '#ad7fa8', anonymous_color: str = '#d3d3d3', generator_color: str = '#fcaf3e', pseudo_color: str = '#729fcf', prototype_color: str = '#8ae234', show_predicates: bool = False, show_individuals: bool = False, compact: bool = True, join_irreducible: bool = False, meet_irreducible: bool = False, width: int = 40)
The
ConceptRenderer
class renders graphviz node and edge attributes.It is used for rendering
Concept
instances.- __init__(fill_color: str = '#ffffff', current_color: str = '#ad7fa8', anonymous_color: str = '#d3d3d3', generator_color: str = '#fcaf3e', pseudo_color: str = '#729fcf', prototype_color: str = '#8ae234', show_predicates: bool = False, show_individuals: bool = False, compact: bool = True, join_irreducible: bool = False, meet_irreducible: bool = False, width: int = 40)
Initialise a
ConceptRenderer
instance.- Keyword Arguments:
fill_color (str) – The fill color.
anonymous_color (str) – The anonymous color.
generator_color (str) – The generator color.
pseudo_color (str) – The pseudo-generator color.
prototype_color (str) – The prototype color.
show_predicates (bool) – Display predicates.
show_individuals (bool) – Display individuals.
compact (bool) – Compact mode.
join_irreducible (bool) – Display elements as join irreducible.
meet_irreducible (bool) – Display elements as meet irreducible.
width (int) – The node width.
- attributes(element: galactic.concepts.Concept, index: Optional[int] = None, current: bool = False, successors: Optional[AbstractSet[galactic.concepts.Concept]] = None, predecessors: Optional[AbstractSet[galactic.concepts.Concept]] = None) Dict[str, str]
Produce a dictionary of graphviz attributes for a node.
- Parameters:
element (
Concept
) – The concept to render.- Keyword Arguments:
index (int, optional) – The element index.
successors (
AbstractSet[Concept]
, optional) – The successors ofelement
.predecessors (
AbstractSet[Concept]
, optional) – The predecessors ofelement
.
- Returns:
A dictionary of graphviz attributes.
- Return type:
Notes
See http://www.graphviz.org/doc/info/attrs.html.
- render(element: galactic.concepts.Concept, index: int) str
Render a concept for a cell element.
- class HierarchicalRenderer(*args, **kwds)
The
HierarchicalRenderer
class renders edge attributes.Notes
See http://www.graphviz.org/doc/info/attrs.html.
- attributes(source: galactic.concepts.Concept, destination: galactic.concepts.Concept, successors: Optional[AbstractSet[galactic.concepts.Concept]] = None, predecessors: Optional[AbstractSet[galactic.concepts.Concept]] = None) Dict[str, str]
Return a dictionary of graphviz attributes for an edge.
- Parameters:
- Keyword Arguments:
successors (
AbstractSet[_F]
, optional) – The successors of source (including current destination).predecessors (
AbstractSet[_E]
, optional) – The predecessors of destination (including current source).
- Returns:
A dictionary of graphviz attributes
- Return type:
- class ConceptLatticeRenderer(rank_sep: Optional[float] = None)
The
ConceptLatticeRenderer
class renders graph attributes.Notes
See http://www.graphviz.org/doc/info/attrs.html.
- __init__(rank_sep: Optional[float] = None) None
Initialize a
ConceptLatticeRenderer
.- Keyword Arguments:
rank_sep (float, optional) – An optional rank separator in inches (default is 0.5)
- add_destination(element: galactic.algebras.relational._renderer._F, index: Optional[int] = None, current: bool = False, successors: Optional[AbstractSet[galactic.algebras.relational._renderer._E]] = None, predecessors: Optional[AbstractSet[galactic.algebras.relational._renderer._E]] = None) None
Add a destination to the graph.
- Parameters:
element (
_F
) – The destination to add.- Keyword Arguments:
index (int, optional) – The destination index.
current (bool) – is
element
the current element?successors (
AbstractSet[_E]
, optional) – The successors of the destination.predecessors (
AbstractSet[_E]
, optional) – The predecessors of the destination.
- add_edge(source: galactic.concepts.Concept, destination: galactic.concepts.Concept, successors: Optional[AbstractSet[galactic.concepts.Concept]] = None, predecessors: Optional[AbstractSet[galactic.concepts.Concept]] = None) None
Add an edge to the Hasse diagram.
- Parameters:
- Keyword Arguments:
successors (
AbstractSet[Concept]
, optional) – The successors of source (including current destination).predecessors (
AbstractSet[Concept]
, optional) – The predecessors of destination (including current source).
- add_source(element: galactic.algebras.relational._renderer._E, index: Optional[int] = None, current: bool = False, successors: Optional[AbstractSet[galactic.algebras.relational._renderer._F]] = None, predecessors: Optional[AbstractSet[galactic.algebras.relational._renderer._F]] = None) None
Add a source to the graph.
- Parameters:
element (
_E
) – The source to add.- Keyword Arguments:
index (int, optional) – The source index.
current (bool) – is
element
the current element?successors (
AbstractSet[_F]
, optional) – The successors of the source.predecessors (
AbstractSet[_F]
, optional) – The predecessors of the source.
- attributes() Dict[str, str]
Return a dictionary of graphviz attributes for a concept lattice.
- Returns:
A dictionary of graphviz attributes
- Return type:
- class ConceptTable(lattice: galactic.concepts.ConceptLattice, all_individuals: bool = False, all_predicates: bool = False, concept_width: int = 1, individual_width: int = 1, predicate_width: int = 1)
The
Table
class is used to represent lattice in jupyter notebooks.- __init__(lattice: galactic.concepts.ConceptLattice, all_individuals: bool = False, all_predicates: bool = False, concept_width: int = 1, individual_width: int = 1, predicate_width: int = 1)
Initialise a
Table
class.- Parameters:
lattice (
ConceptLattice
) – The lattice whose table representation is requested- Keyword Arguments:
all_individuals (bool) – A boolean flag for displaying all individuals for each concept
all_predicates (bool) – A boolean flag for displaying all predicates for each concept
concept_width (int) – The concept width
individual_width (int) – The individual width.
predicate_width (int) – The predicate width.
By default only new predicates and new individuals are displayed. The values of the given widths are compared with each other to allocate relative column sizes.
- property all_individuals: bool
Get the all individuals flag.
- Returns:
The all individuals flag.
- Return type:
- property all_predicates: bool
Get the all predicates flag.
- Returns:
The all predicates flag.
- Return type:
- property individual_width: int
Get the individual width.
- Returns:
The individual width.
- Return type:
- property lattice: galactic.concepts.ConceptLattice
Get the underlying lattice.
- Returns:
The concept lattice.
- Return type:
- new_predicates(concept: galactic.concepts.Concept, successors: AbstractSet[galactic.concepts.Concept]) Iterator[galactic.descriptions.Predicate]
Get the new predicates given by the concept.
- Parameters:
concept (
Concept
) – The concept whose new predicates are requested.successors (
AbstractSet[Concept]
) – The successors of the concept.
- Returns:
An iterator over the new predicates.
- Return type:
- new_individuals(concept: galactic.concepts.Concept, predecessors: AbstractSet[galactic.concepts.Concept]) Iterator[str]
Get the new individuals given by the concept.
- Parameters:
concept (
Concept
) – The concept whose new individuals are requested.predecessors (
AbstractSet[Concept]
) – The predecessors of the concept.
- Returns:
An iterator over the individual keys.
- Return type: