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:

Closure[_E, _T]

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:

Iterator[_T]

intersection(*args: Any) galactic.algebras.lattice.Meetable

Return the intersection of this element and the others.

Parameters:

*args (object) – the others elements

Returns:

the meet of this element and the others

Return type:

Meetable

Raises:

TypeError – if one of the other elements is not an instance of this element class.

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:

Iterator[_T]

property support: float

Get the closed set support.

Returns:

The closed set support.

Return type:

float

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:

Iterator[_T]

union(*args: Any) galactic.algebras.lattice.Joinable

Return the union of this element and the others.

Parameters:

*args (object) – the others elements

Returns:

the join of this element and the others

Return type:

Joinable

Raises:

TypeError – if one of the other elements is not an instance of this element class.

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:

_E

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>, <>]
__contains__(item: Any) bool

Get the membership of an element.

Parameters:

item – The element whose membership is requested.

Returns:

True if the item belongs to the partially ordered set.

Return type:

bool

__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:

Lattice[_E]

__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:

Iterator[Tuple[_P, _P]]

property atoms: AbstractSet[galactic.algebras.lattice._lattices._E]

Get the atoms of this lattice.

Returns:

The atoms

Return type:

AbstractSet[_E]

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:

AbstractSet[_E]

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:

Closure[_E, _T]

property co_atoms: AbstractSet[galactic.algebras.lattice._lattices._E]

Get the co-atoms of this lattice.

Returns:

The co-atoms.

Return type:

AbstractSet[_E]

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:

AbstractSet[_E]

property cover: galactic.algebras.poset.AbstractReversibleCoveringRelation[galactic.algebras.lattice._lattices._E]

Get the covering relation of this lattice.

Returns:

The covering relation.

Return type:

AbstractReversibleCoveringRelation[_E]

property domain: AbstractSet[galactic.algebras.lattice._lattices._E]

Get the domain of this lattice.

Returns:

The domain of this lattice.

Return type:

AbstractSet[_E]

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:

float

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:

float

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:

float

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:

float

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:

AbstractSet[_E]

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:

Iterator[Tuple[_E, float]]

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:

AbstractSet[_E]

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

parts()

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

A. Buzmakov , S. Kuznetsov , A. Napoli , Scalable estimates of element stability, in: C. Glodeanu, M. Kaytoue, C. Sacarea (Eds.), Formal element Analysis, Lecture Notes in Computer Science, 8478, Springer International Publishing, 2014, pp. 157–172

Returns:

An iterator on elements and their normalized logarithmic stability.

Return type:

Iterator[Tuple[_E, float]]

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:
  • limit (_E) – The lower limit

  • strict (bool) – Is the comparison strict?

Returns:

The selected elements.

Return type:

AbstractSet[_E]

property maximum: galactic.algebras.lattice._lattices._E

Get the maximum element of this lattice.

Returns:

the maximum element

Return type:

_E

property meet_irreducible: AbstractSet[galactic.algebras.lattice._lattices._E]

Get the meet irreducible elements.

Returns:

The meet irreducible elements

Return type:

AbstractSet[_E]

property minimum: galactic.algebras.lattice._lattices._E

Get the minimum element of this lattice.

Returns:

The minimum element

Return type:

_E

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:

Iterator[Tuple[_E, int]]

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:

AbstractSet[_E]

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

parts()

Returns:

An iterator on elements and their probability.

Return type:

Iterator[Tuple[_E, float]]

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:

AbstractBinaryRelation[_E, _E]

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:

AbstractSet[_E]

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:

AbstractSet[_E]

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:

AbstractSet[_E]

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

parts()

Returns:

An iterator on elements and their stability.

Return type:

Iterator[Tuple[_E, float]]

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:

AbstractSet[_E]

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:

AbstractSet[_E]

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:

Tuple[AbstractSet[_E], AbstractSet[_E]]

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:
  • limit (_E) – The upper limit

  • strict (bool) – Is the comparison strict?

Returns:

The selected elements.

Return type:

AbstractSet[_E]