toponetx.Simplex#

class toponetx.Simplex(elements: Collection, construct_tree: bool = False, **kwargs)[source]#

Bases: Atom[frozenset[Hashable]]

A class representing a simplex in a simplicial complex.

This class represents a simplex in a simplicial complex, which is a set of nodes with a specific dimension. The simplex is immutable, and the nodes in the simplex must be hashable and unique.

Parameters:
elementsCollection

The nodes in the simplex.

construct_treebool, default=True

If True, construct the entire simplicial tree for the simplex.

**kwargskeyword arguments, optional

Additional attributes to be associated with the simplex.

Attributes:
boundary

Return the set of the set of all n-1 faces in of the input n-simplex.

faces

Get the set of faces of the simplex.

Methods

clone()

Return a copy of the simplex.

construct_simplex_tree(elements)

Return set of Simplex objects representing the faces.

sign(face)

Calculate the sign of the simplex with respect to a given face.

update(attributes)

Update the attributes of the atom.

validate_attributes(attributes)

Validate the attributes of the simplex.

Examples

>>> # Create a 0-dimensional simplex (point)
>>> s = tnx.Simplex((1,))
>>> # Create a 1-dimensional simplex (line segment)
>>> s = tnx.Simplex((1, 2))
>>> # Create a 2-dimensional simplex (triangle)
>>> simplex1 = tnx.Simplex((1, 2, 3))
>>> simplex2 = tnx.Simplex(("a", "b", "c"))
>>> # Create a 3-dimensional simplex (tetrahedron)
>>> simplex3 = tnx.Simplex((1, 2, 4, 5), weight=1)
__init__(elements: Collection, construct_tree: bool = False, **kwargs) None[source]#

Methods

__init__(elements[, construct_tree])

clone()

Return a copy of the simplex.

construct_simplex_tree(elements)

Return set of Simplex objects representing the faces.

sign(face)

Calculate the sign of the simplex with respect to a given face.

update(attributes)

Update the attributes of the atom.

validate_attributes(attributes)

Validate the attributes of the simplex.

Attributes

boundary

Return the set of the set of all n-1 faces in of the input n-simplex.

faces

Get the set of faces of the simplex.

elements

name

property boundary: frozenset[Simplex]#

Return the set of the set of all n-1 faces in of the input n-simplex.

Returns:
frozenset[Simplex]

A frozenset representing boundary simplices.

Examples

For a n-simplex [1,2,3], the boundary is all the n-1 subsets of [1,2,3] :

(1,2), (2,3), (3,1).

clone() Self[source]#

Return a copy of the simplex.

The clone method by default returns an independent shallow copy of the simplex and attributes. That is, if an attribute is a container, that container is shared by the original and the copy. Use Python’s copy.deepcopy for new containers.

Returns:
Simplex

A copy of this simplex.

static construct_simplex_tree(elements: Collection) frozenset[Simplex][source]#

Return set of Simplex objects representing the faces.

Parameters:
elementsCollection

The simplex for which to construct the simplex tree.

Returns:
frozenset[Simplex]

The set of faces of the simplex.

property faces#

Get the set of faces of the simplex.

If construct_tree is True, return the precomputed set of faces _faces. Otherwise, construct the simplex tree and return the set of faces.

Returns:
frozenset[Simplex]

The set of faces of the simplex.

sign(face) int[source]#

Calculate the sign of the simplex with respect to a given face.

Parameters:
faceSimplex

A face of the simplex.

update(attributes: dict) None#

Update the attributes of the atom.

Parameters:
attributesdict

The attributes to be updated.

static validate_attributes(attributes: dict) None[source]#

Validate the attributes of the simplex.

Parameters:
attributesdict

The attributes to be validated.

Raises:
ValueError

If the attributes contain the reserved keys is_maximal or membership.