<jupyter_start><jupyter_text>Quickstart GuideOnce you have [successfully installed](installation.html) `bats`, you can follow this guide to help you get started.  You can download this guide as a Jupyter notebook [here](_sources/quickstart.ipynb).You can find additional information and examples in the [tutorials](tutorials/index.html) and [examples](examples/index.html), and ultimately the [API reference](api.html).First, import `bats`:<jupyter_code>import bats<jupyter_output><empty_output><jupyter_text>Simplicial Complexes and HomologyBATS offers two implementations of simplicial complexes: `SimplicialComplex` and `LightSimplicialComplex`.  While the internal representations differ, they both have the same interface which can be used.Simplices in bats should generally be assumed to be *ordered*, meaning that    `[0,1,2]` is not the same as `[1,2,0]`.  If you want to use    *unordered* simplices, you can either add vertices in sorted order, or use    a sorting algorithm before adding simplices to complexes.The `add` method will add simplices, assuming that all faces have previously been added.  The `add_recursive` method will recursively add faces as needed.<jupyter_code>X = bats.SimplicialComplex()
X.add_recursive([0,1,2])
X.add_recursive([2,3])
X.add([1,3])

X.get_simplices()<jupyter_output><empty_output><jupyter_text>Now let's compute homology<jupyter_code>R = bats.reduce(X, bats.F2()) # F2 is coefficient field

for k in range(R.maxdim()):
    print("dim H_{}: {}".format(k, R.hdim(k)))<jupyter_output>dim H_0: 1
dim H_1: 1<jupyter_text>The output of `bats.reduce` is a `ReducedChainComplex` which holds information used to compute homology.For `LightSimplicialComplex`, you need to provide an upper bound on the number of vertices and maximum simplex dimension.<jupyter_code>n = 4 # number of vertices
d = 2 # max simplex dimension
X = bats.LightSimplicialComplex(n, d)
X.add_recursive([0,1,2])
X.add_recursive([2,3])
X.add([1,3])

X.get_simplices()
R = bats.reduce(X, bats.F2())

for k in range(R.maxdim()):
    print("dim H_{}: {}".format(k, R.hdim(k)))<jupyter_output>dim H_0: 1
dim H_1: 1<jupyter_text>Persistent HomologyYou can add simplices to a filtration by providing a parameter at which they first appear.<jupyter_code>F = bats.FilteredSimplicialComplex()
F.add_recursive(0.0, [0,1,2])
F.add_recursive(1.0, [2, 3])
F.add(2.0, [1,3])

F.complex().get_simplices()<jupyter_output><empty_output><jupyter_text>again, we can use the `reduce` function, but now we get a `ReducedFilteredChainComplex`<jupyter_code>R = bats.reduce(F, bats.F2())

for k in range(R.maxdim()):
    for p in R.persistence_pairs(k):
        print(p)<jupyter_output>0 : (0,inf) <0,-1>
0 : (0,0) <1,0>
0 : (0,0) <2,1>
0 : (1,1) <3,3>
1 : (0,0) <2,0>
1 : (2,inf) <4,-1><jupyter_text>The output of `R.persistence_pairs(k)` is a vector of `PersistencePairs` for k-dimensional persistent homology.  A `PersistencePair` includes 5 pieces of information:* The dimension of the homology class.* The birth and death parameters of the homology class.* The simplex indices responsible for birth and death.<jupyter_code>p = R.persistence_pairs(1)[-1]
print(p)
print(p.dim(), p.birth(), p.death(), p.birth_ind(), p.death_ind(), sep=', ')<jupyter_output>1 : (2,inf) <4,-1>
1, 2.0, inf, 4, 18446744073709551615<jupyter_text>infinite bars have a death index set to `2**64 - 1`  MapsBATS makes dealing with maps between topological spaces and associated chain mapsand induced maps on homology easy.  The relevant class is a `CellularMap` whichkeeps track of what cells in one complex map to what cells in another.We'll just look at a wrapper for `CellularMap`, called `SimplcialMap` which can be usedto extend a map on the vertex set of a `SimplicialComplex` to a map of simplices.First, we'll build identical simplicial complexes `X` and `Y` which are both cycle graphson four vertices.<jupyter_code>X = bats.SimplicialComplex()
X.add_recursive([0,1])
X.add_recursive([1,2])
X.add_recursive([2,3])
X.add_recursive([0,3])

Y = X<jupyter_output><empty_output><jupyter_text>We then build a simplicial map from X to Y which is extended from a reflection of the vertices.<jupyter_code>f0 = [2, 1, 0, 3]
F = bats.SimplicialMap(X, Y, f0)<jupyter_output><empty_output><jupyter_text>The map is extended by sending vertex `i` in `X` to vertex`f0[i]` in `Y`.  Next, we can apply the chain functor.  We'll useF3 coefficients.<jupyter_code>CX = bats.Chain(X, bats.F3())
CY = bats.Chain(Y, bats.F3())
CF = bats.Chain(F, bats.F3())<jupyter_output><empty_output><jupyter_text>Finally, we can compute homology of the chain complexes and the induced maps.<jupyter_code>RX = bats.reduce(CX)
RY = bats.reduce(CY)

for k in range(RX.maxdim()+1):
    HFk = bats.InducedMap(CF, RX, RY, k)
    print("induced map in dimension {}:".format(k))
    print(HFk.tolist())<jupyter_output>induced map in dimension 0:
[[1]]
induced map in dimension 1:
[[2]]<jupyter_text>The induced map in dimension 0 is the identity.  The induced map in dimension 1 is multiplication by `2 = -1 mod 3`  Zigzag HomologyWe'll now compute a simple zigzag barcode, using the above example.  We'll considera diagram with two (identical) spaces, connected by a single edge which appliesthe reflection map in the above example.<jupyter_code>D = bats.SimplicialComplexDiagram(2,1) # diagram with 2 nodes, 1 edge
D.set_node(0, X)
D.set_node(1, Y)
D.set_edge(0, 0, 1, F) # edge 0: F maps from node 0 to node 1<jupyter_output><empty_output><jupyter_text>We can now apply the `Chain` and `Hom` functors to obtain a diagram of homology vector spaces and maps between them<jupyter_code>CD = bats.ChainFunctor(D, bats.F3())

HD = bats.Hom(CD, 1) # computes homology in dimension 1
ps = bats.barcode(HD, 1) # extracts barcode
for p in ps:
    print(p)<jupyter_output>1 : (0,1) <0,0>
StarcoderdataJupyterStructuredCleanDedup