Closures
The galactic.algebras.closure
module.
It defines classes for creating closure operators and closed sets.
- class Closed(*args, **kwds)
The
Closed
class is used to represent a closed set.- abstract property closure: galactic.algebras.closure.Closure[galactic.algebras.closure._main._E, galactic.algebras.closure._main._T]
Get the underlying closure operators.
- Returns:
The closure operator.
- 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.
- 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 Closure(*args, **kwds)
The
Closure
class is used to represent a closure operator.The Greek letter \(\phi\) is often used to name a closure operator.
Notes
See https://en.wikipedia.org/wiki/Closure_operator
- abstract __call__(elements: Optional[Iterable[galactic.algebras.closure._main._T]] = None) galactic.algebras.closure._main._E
Call this closure on a iterable of elements.
- Parameters:
elements (
Iterable[_T]
, optional) – The iterable of elements.- Returns:
The closed representation of the object into a row.
- Return type:
- class MooreFamily(closure: galactic.algebras.closure.Closure[galactic.algebras.closure._main._E, galactic.algebras.closure._main._T])
A
MooreFamily
is a lattice of closed sets containing the universe.Notes
See https://en.wikipedia.org/wiki/Closure_operator
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) >>> list(family.domain) [<0,5>] >>> family.extend([closure([0, 1, 3]), closure([2, 5])]) >>> list(family.domain) [<0,5>, <0,3>, <2,5>, <2,3>] >>> family.extend([closure([4, 5])]) >>> list(family.domain) [<0,5>, <2,5>, <0,3>, <4,5>, <2,3>, <>]
- __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__(closure: galactic.algebras.closure.Closure[galactic.algebras.closure._main._E, galactic.algebras.closure._main._T])
Initialise a
MooreFamily
instance.- Parameters:
closure (
Closure[_E, _T]
) – A closure operator.
- __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:
- 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.algebras.closure.Closure[galactic.algebras.closure._main._E, galactic.algebras.closure._main._T]
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:
- 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
- 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: