# 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, start=0, end=-1)[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. start (int, default is 0) – Generator in self from which we start to search. end (int, default is -1) – Generator in self until which we end searching for active generators. One-dimensional array with indices of active generators. This is relative to the start index. `Numpy Array`

Example

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

Active submatrix of coordinates at rad

Example

```>>> bars = np.array(
... [[0,5],[1,5],[1,5],[2,4]])
>>> baseP = barcode_basis(bars)
>>> barsC = np.array(
... [[1,4],[2,5]])
>>> coord = np.array(
... [[1,0],
...  [0,1],
...  [2,1],
...  [0,1]])
>>> baseC = barcode_basis(barsC, baseP, coord)
>>> print(baseC)
Barcode basis
[[1 4]
[2 5]]
[[1 0]
[0 1]
[2 1]
[0 1]]
>>> bars
array([[0, 5],
[1, 5],
[1, 5],
[2, 4]])
>>> baseC.active_coordinates(1.3)
array([,
,
])
>>> baseC.active_coordinates(4.8)
array([,
,
])
>>> baseC.active_coordinates(3)
array([[1, 0],
[0, 1],
[2, 1],
[0, 1]])
```
`active_domain`(rad)[source]

Active columns of coordinates at rad

Example

```>>> print(baseC)
Barcode basis
[[1 4]
[2 5]]
[[1 0]
[0 1]
[2 1]
[0 1]]
>>> baseC.active_domain(1.3)
array([,
,
,
])
```
`birth_radius`(coordinates)[source]

This finds the birth radius of a list of coordinates.

Example

```>>> base3 = barcode_basis([[0,2],[0,1],[1,3]])
1
```
`bool_select`(selection)[source]

Given a boolean array, we select generators from a barcode basis.

Example

```>>> print(base3)
Barcode basis
[[0 2]
[0 1]
[1 3]]
>>> base5 = base3.bool_select([True,False,True])
>>> print(base5)
Barcode basis
[[0 2]
[1 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, start=0)[source]

Returns an array with the indices dying at rad.

These indices are relative to the optional argument start.

Parameters: rad (float) – Radius at which generators might be dying start (int, default is 0) –

Example

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

Find the death radius of given coordinates.

Example

```>>> print(base3)
Barcode basis
[[0 2]
[0 1]
[1 3]]
3
```
`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]]
```
`trans_active_coord`(coord, rad, start=0)[source]

Given coordinates on the active generators, this returns coordinates in the whole basis.

This also can be done relative to a start index higher than 0

Parameters: coord (`Numpy Array`) – One dimensional array specifying the coordinates on the active basis. rad (float) – Radius on which we are checking for active generators. start (int, default is 0) – We ignore the indices smaller than this. Notice that coord as well as the produced absolute coordinates will be adjusted appropriately. One dimensional array with a `Numpy Array`

Example

```>>> bars = [[0,5],[0,2],[1,4],[0.5,3]]
>>> base7 = barcode_basis(bars)
>>> base7.trans_active_coord([0,1,1],2.4)
array([ 0.,  0.,  1.,  1.])
>>> base7.trans_active_coord([-1,1],3.8)
array([-1.,  0.,  1.,  0.])
>>> base7.trans_active_coord([-1,1],2.2,1)
array([ 0., -1.,  1.])
```
`update_broken`(A, rad)[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]])
```