# permaviss.persistence_algebra.barcode_bases¶

barcode_bases.py

Classes

 `barcode_basis`(bars[, prev_basis, …]) This class implements barcode bases.
class `permaviss.persistence_algebra.barcode_bases.``barcode_basis`(bars, prev_basis=None, coordinates=array([], shape=(1, 0), dtype=float64), store_well_defined=False, broken_basis=False, broken_differentials=None)[source]

This class implements barcode bases.

Associated bars and coordinates are given for some barcode base. Each coordinate is stored in a column, whereas bars are stored on rows. This generates a barcode basis with all the input data. There is the exception of broken barcode bases, which come up when solving the extension problem.

Note

Barcode bases are assumed to be well defined in the sense that:

1)They are linearly independent with respect to boxplus operation

2)They generate the respective module or submodule.

Parameters: bars (`Numpy Array (dim, 2)`) – Each entry is a pair specifying birth and death radius of a bar. prev_basis (reference to a previously defined `barcode_basis`.) – This will be the basis in which the coordinates are given. coordinates (`Numpy Array (dim, prev_basis.dim)`) – Cooridnates of this basis in terms of prev_basis store_well_defined (bool, default is False) – Whether we want to store the indices of well defined bars. That is, whether we wish to store indices of bars where the birth radius is strictly smaller than the death radius. broken_basis (bool, default is False) – Whether the barcode basis is broken. This appears when solving the extension problem. A barcode base is broken if it is not natural. broken_differentials (`Numpy Array (dim, dim)`) – Matrix of broken differentials. These give coefficients of a barcode generator in term of other generators. This is used when the given generator dies, and we write it in terms of other generators that are still alive. `barcode_basis` ValueError – If prev_coord.dim is different to the number of rows in coordinates ValueError – If the number of rows in bar is different to the number of columns in coordinates. ValueError – If broken_basis = True but broken_differentials is not given.

Examples

```>>> import numpy as np
>>> bars = np.array([[0,2],[0,1],[2,3],[2,2]])
>>> base1 = barcode_basis(bars, store_well_defined=True)
>>> base1.dim
3
>>> base1.well_defined
array([ True,  True,  True, False], dtype=bool)
>>> print(base1)
Barcode basis
[[0 2]
[0 1]
[2 3]]
```
```>>> bars = np.array([[0,2],[2,3]])
>>> coordinates = np.array([[1,0],
...                         [1,0],
...                         [0,2]])
>>> base2 = barcode_basis(bars, prev_basis, coordinates)
>>> base2.dim
2
>>> print(base2)
Barcode basis
[[0 2]
[2 3]]
[[1 0]
[1 0]
[0 2]]
```
```>>> bars = np.array([[0,2],[0,1],[1,3]])
>>> broken_differential = np.array(
... [[0,0,0],
...  [0,0,0],
...  [0,1,0]])
>>> base3 = barcode_basis(bars, broken_basis=True,
... broken_differentials=broken_differential)
>>> base3.dim
3
>>> print(base3)
Barcode basis
[[0 2]
[0 1]
[1 3]]
```
`__str__`()[source]

Printing function for barcode bases.

`active`(rad)[source]

Returns array with active indices at rad.

Option to restrict to generators from start to self.dim

Parameters: rad (float) – Radius where we want to check which barcodes are active. One-dimensional array with indices of active generators. `Numpy Array`

Example

```>>> print(base3)
Barcode basis
[[0 2]
[0 1]
[1 3]]
>>> base3.active(1.2)
array([0, 2])
```
`birth`(rad)[source]

Returns an array with the indices being born at rad.

Example

```>>> print(base4)
Barcode basis
[[-1  3]
[ 0  4]
[ 1  4]
[ 1  2]]
>>> base4.birth(1)
array([2, 3])
```
`changes_list`()[source]

Returns an array with the values of changes occurring in the basis.

Returns: One-dimensional array with radii where either a bar dies or is born in self. `Numpy Array`

Example

```>>> print(base1)
Barcode basis
[[0 2]
[0 1]
[2 3]]
>>> base1.changes_list()
array([0, 1, 2, 3])
```
`death`(rad)[source]

Returns an array with the indices dying at rad.

Example

```>>> print(base4)
Barcode basis
[[-1  3]
[ 0  4]
[ 1  4]
[ 1  2]]
>>> base4.death(4)
array([1, 2])
```
`sort`(precision=7, send_order=False)[source]

Sorts a barcode basis according to the standard barcode order.

That is, from smaller birth radius to bigger, and from bigger death radius to smaller. A precision up to n zeros is an optional argument.

Parameters: precision (int, default is 7) – Number of zeros of precision. send_order (bool, default is False) – Whether we want to generate a `Numpy Array` storing the original order. One dimensional array storing original order of barcodes. `Numpy Array`

Example

```>>> bars = np.array([[1,2],[0,4],[-1,3],[1,4]])
>>> base4 = barcode_basis(bars)
>>> base4.sort(send_order=True)
array([2, 1, 3, 0])
>>> base4 = barcode_basis(bars)
>>> print(base4)
Barcode basis
[[ 1  2]
[ 0  4]
[-1  3]
[ 1  4]]
>>> base4.sort(send_order=True)
array([2, 1, 3, 0])
>>> print(base4)
Barcode basis
[[-1  3]
[ 0  4]
[ 1  4]
[ 1  2]]
```
`update_broken`(A, rad, p)[source]

Updates a matrix A, using the broken differentials of the generators dying at rad.

We assume that the broken barcode basis is indexing the rows of A.

Parameters: A (`Numpy Array`) – columns represent coordinates in the barcode_basis. rad (float) – Radius at which we want to update the coordinates using the broken_differentials. A – return updated matrix `Numpy Array`

Example

```>>> print(base3)
Barcode basis
[[0 2]
[0 1]
[1 3]]
>>> A = np.array(
... [[1,1,1],
...  [0,2,-1],
...  [0,1,1]])
>>> base3.update_broken(A, 1)
array([[1, 1, 1],
[0, 0, 0],
[0, 3, 0]])
```