Update notebooks and scripts
This commit is contained in:
parent
aedd94d4af
commit
69afa83517
41 changed files with 2896 additions and 469 deletions
|
@ -3,6 +3,13 @@ import dionysus as d
|
|||
|
||||
|
||||
def diagram_array(dgm):
|
||||
"""Convert a Dionysus diagram to a Numpy array.
|
||||
|
||||
:param dgm: Dionysus Diagram
|
||||
|
||||
:return: a Numpy array of tuples representing the points in the
|
||||
diagram.
|
||||
"""
|
||||
res = []
|
||||
for p in dgm:
|
||||
if p.death != np.inf:
|
||||
|
@ -11,8 +18,19 @@ def diagram_array(dgm):
|
|||
|
||||
|
||||
def SW_approx(dgm1, dgm2, M):
|
||||
"""Approximate computation of the Sliced Wasserstein kernel.
|
||||
|
||||
:param dgm1: first Diagram
|
||||
:param dgm2: second Diagram
|
||||
:param M int: number of directions
|
||||
|
||||
:return: The approximate value of the Sliced Wasserstein kernel of
|
||||
dgm1 and dgm2, sampled over M dimensions.
|
||||
"""
|
||||
dgm1 = diagram_array(dgm1)
|
||||
dgm2 = diagram_array(dgm2)
|
||||
if dgm1.size == 0 or dgm2.size == 0:
|
||||
return 0
|
||||
# Add \pi_\delta(dgm1) to dgm2 and vice-versa
|
||||
proj1 = dgm1.dot([1, 1])/np.sqrt(2)
|
||||
proj2 = dgm2.dot([1, 1])/np.sqrt(2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue