https://github.com/MathieuCarriere/tda-tutorials
Doimiy homologiya
Ushbu demo doimiy homologiyani hisoblash uchun Dionisdan qanday foydalanishni tushuntiradi. Birinchi zarur import.
In [59]:
from dionysus import Simplex, Filtration, StaticPersistence, \
vertex_cmp, data_cmp, data_dim_cmp, \
DynamicPersistenceChains
from math import sqrt
Biz 2-simpleks (uchburchak) ABC ning doimiy homologiyasini hisoblaymiz. Filtrlash quyidagicha amalga oshiriladi: birinchi navbatda uchburchakning yuqori cho'qqisi (C), so'ngra qolgan cho'qqilari (A va B), so'ngra pastki cheti (AB), so'ngra qolgan qirralari (AC va BC) qo'shiladi. va nihoyat uchburchak to'ldiriladi (ABC).
In [60]:
scx = [Simplex((2,), 0), # C
Simplex((0,), 1), # A
Simplex((1,), 1), # B
Simplex((0,1), 2), # AB
Simplex((1,2), 3), # BC
Simplex((0,2), 3), # AC
Simplex((0,1,2), 4), # ABC
]
Endi doimiy homologiya hisoblab chiqiladi.
In [62]:
f = Filtration(scx, data_cmp)
p = DynamicPersistenceChains(f)
p.pair_simplices()
smap = p.make_simplex_map(f)
Endi hisoblangan qat'iylik diagrammasini chiqaring. Filtrlashda paydo bo'lgan har bir muhim hujayra uchun Tug'ilish va O'lim vaqti, shuningdek, uni o'ldiradigan hujayra (uning juftligi) beriladi. Abadiy saqlanib qoladigan xususiyatlarda Death qiymati inf ga o'rnatiladi.
In [69]:
print "{:>10}{:>10}{:>10}{:>10}".format("First", "Second", "Birth", "Death")
for i in (i for i in p if i.sign()):
b = smap[i]
if i.unpaired():
print "{:>10}{:>10}{:>10}{:>10}".format(b, '', b.data, "inf")
else:
d = smap[i.pair()]
print "{:>10}{:>10}{:>10}{:>10}".format(b, d, b.data, d.data)
First Second Birth Death
<2> 0 inf
<0> <1, 2> 1 3
<1> <0, 1> 1 2
<0, 2> <0, 1, 2> 3 4
Bu bizning misolimizni tugatadi. Qo'shimcha ma'lumot uchun Dionis misollariga qarang, masalan, $\alpha$-shakllar misoli (qaysi biri asoslangan).
This tutorial is probably also available as a Jupyter notebook in the demo folder in the polymake source and on github.
Different versions of this tutorial: latest release, release 4.6, release 4.5, release 4.4, release 4.3, release 4.2, release 4.1, release 4.0, release 3.6, nightly master
Introduction to topaz
This tutorial tries to give the user a first idea about the features of the topaz application of polymake. We take a look at a variety of small examples.
First, we have to make topaz the current application. For this you can either start polymake with the option -A topaz,
polymake -A topaz
or, if you've already started polymake, type
> application 'topaz';
in the polymake shell.
Simplicial complexes
The most important object of the topaz application is the simplicial complex. There are several ways of obtaining one.
From faces
For example, you can specify some faces of the complex. You can pass them as an Array< Set >, or Array< Array >:
> # $s = new SimplicialComplex(INPUT_FACES=>[new Set(0), new Set(0,1), new Set(1,2,3)]);
> $s = new SimplicialComplex(INPUT_FACES=>[[0],[0,1],[1,2,3]]);
As you can see, redundancies are allowed – [0] is not a facet of the complex, and thus not necessary for encoding $s. You can compute the inclusion maximal faces like this:
> print $s->FACETS;
{0 1}
{1 2 3}
You can also pass the FACETS to the constructor, but be aware that in that case the vertices must be numbered increasingly starting with 0 and redundancies are prohibited.
Take a look at your complex using
> $s->VISUAL;
For more information on visualizing simplicial complex, see the section below.
polymake can compute the Hasse diagram of a simplicial complex (watch out, this gets really large for large complexes!). To print all the faces of the complex together with their rank in the face lattice, do this:
> print $s->HASSE_DIAGRAM->DECORATION;
({-1} 4)
({0 1} 2)
({1 2 3} 3)
({0} 1)
({1} 1)
({1 2} 2)
({1 3} 2)
({2 3} 2)
({} 0)
({2} 1)
({3} 1)
The first entry of each pair denotes the face, the second is the rank. The {-1}-node is a dummy representing the whole complex. the {}-node is the empty face. If you want to look at a pretty graph representation, try the visualization:
> $s->VISUAL_FACE_LATTICE;
Using clients
There are several clients that construct common simplicial complexes (for a comprehensive list, see the topaz documentation). An example is the torus client:
> $t = torus();
Of course, polymake can compute the reduced integer homology groups of a simplicial complex, so we can convice ourselves this is a torus:
> print $t->MANIFOLD;
true
> print $t->HOMOLOGY;
({} 0)
({} 2)
({} 1)
The i-th line represents the ii-th homology module. The curly braces contain torsion coefficients with multiplicity, the second pair entry denotes the Betti number. The empty curly braces indicate that $t is torsion-free. You can see a non-empty torsion group here (using the rows_numbered client for a pretty print with the corresponding dimensions):
> print rows_numbered( real_projective_plane()->HOMOLOGY );
0:{} 0
1:{(2 1)} 0
2:{} 0
As expected, the first homology group has torsion coefficient 2 with multiplicity 1 and all Betti numbers are zero.
As boundary complex
If your complex is a pseudo-manifold, you can obtain a new complex from its boundary. For example, this produces a triangulation of the 22-sphere:
> $bs = simplex(3)->BOUNDARY;
> print $bs->SPHERE;
true
Triangulating polytopes
The triangulation of a polytope is a simplicial complex, too. The TRIANGULATION gets stored in a property of the polytope. We use the cube client from the polytope application to demonstrate:
> $c = polytope::cube(3);
> $tc = $c->TRIANGULATION;
> print $tc->FACETS;
{0 1 2 4}
{1 2 3 4}
{1 3 4 5}
{2 3 4 6}
{3 4 5 6}
{3 5 6 7}
Geometric realizations
The topaz application is primarily designed to deal with abstract simplicial complexes that do not come with coordinates for an embedding in euclidean space. There is a special object subtype named GeometricSimplicialComplex that has extra properties for dealing with coodinates.
You can pass the coordinates to the constructor. Take care to choose an embedding without crossings!
> $s = new GeometricSimplicialComplex(INPUT_FACES=>[[0],[0,1],[1,2,3]], COORDINATES=>[[1,0],[1,1],[0,2],[2,2]]);
Some clients produce complexes with geometric realization…
> $b = ball(3);
> # print a dense representation of the sparse matrix
> print dense( $b->COORDINATES );
0 0 0
1 0 0
0 1 0
0 0 1
…some others provide the option geometric_realization so you can decide whether to invest the extra computing time.
> $bs = barycentric_subdivision($b,geometric_realization=>1);
Again, see the topaz documentation for a comprehensive list.
Visualization
Visualization of simplicial complexes uses the VISUAL property. Check out
> help 'objects/SimplicialComplex/methods/Visualization/VISUAL';
VISUAL(Options) -> Visual::SimplicialComplex
Visualizes the complex.
If __G_DIM__ < 4, the __GRAPH__ and the facets
are visualized using the __COORDINATES__.
Otherwise, the spring embedder and the __GRAPH__ are used to
produce coordinates for the visualization.
If __JavaView__ is used to visualize the complex, all faces of
one facet build a geometry in the jvx-file, so you may 1>0>2>
Do'stlaringiz bilan baham: |