Skip to content

Commit

Permalink
fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
barnesd8 committed Apr 16, 2024
2 parents 3f06472 + bd44706 commit 9986e95
Show file tree
Hide file tree
Showing 12 changed files with 1,725 additions and 5,309 deletions.
9 changes: 9 additions & 0 deletions doc_source/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,13 @@ @ARTICLE{ml4pers
ISSN={2624-8212},
}

@misc{polanco2019adaptive,
title={Adaptive template systems: Data-driven feature selection for learning with persistence diagrams},
author={Luis Polanco and Jose A. Perea},
year={2019},
eprint={1910.06741},
archivePrefix={arXiv},
primaryClass={cs.LG}
}

@Comment{jabref-meta: databaseType:bibtex;}
72 changes: 72 additions & 0 deletions notebooks/kernel_gpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
@guvectorize(["void(int64[:,:,:], int64[:,:], float64, float64[:])",],"(p,m,n), (m,n), ()->(p)", target='cuda', nopython=True)
def kernel_gpu(dgms0, dgms1, s, result):
"""
This function computes (using gpu) the multiscale heat kernel distance for an array of persistence diagrams based on the formula provided in Ref. :cite:`5 <Reininghaus2015>`.
There are three inputs and these are two persistence diagram arrays and the kernel scale sigma. This function should be used for large size datasets. Please note this function will not work if you do not have a compatible GPU.
Details for compatibility can be found `here <https://numba.readthedocs.io/en/stable/cuda/index.html>`_.
Parameters
----------
dgms0 : ndarray
Object array that includes first persistence diagram set.
dgms1 : ndarray
Object array that includes second persistence diagram set.
sigma : float
Kernel scale.
Returns
-------
result : np array
The kernel matrix
"""
n_train = len(dgms0)
for i in range(n_train):
dgm0=dgms0[i]
dgm1 = dgms1
kSigma0 = 0
kSigma1 = 0
kSigma2 = 0
sigma = s
for k in range(dgm0.shape[0]):
p = dgm0[k,0:2]
if p[0]+p[1]==-2:
continue
for l in range(dgm0.shape[0]):
q = dgm0[l,0:2]
if q[0]+q[1]==-2:
continue
qc = dgm0[l, 1::-1]
pq = (p[0] - q[0])**2 + (p[1] - q[1])**2
pqc = (p[0] - qc[0])**2 + (p[1] - qc[1])**2
kSigma0 += math.exp(-( pq) / (8 * sigma)) - math.exp(-(pqc) / (8 * sigma))
for k in range(dgm1.shape[0]):
p = dgm1[k,0:2]
if p[0]+p[1]==-2:
continue
for l in range(dgm1.shape[0]):
q = dgm1[l,0:2]
if q[0]+q[1]==-2:
continue
qc = dgm1[l, 1::-1]
pq = (p[0] - q[0])**2 + (p[1] - q[1])**2
pqc = (p[0] - qc[0])**2 + (p[1] - qc[1])**2
kSigma1 += math.exp(-( pq) / (8 * sigma)) - math.exp(-(pqc) / (8 * sigma))
for k in range(dgm0.shape[0]):
p = dgm0[k,0:2]
if p[0]+p[1]==-2:
continue
for l in range(dgm1.shape[0]):
q = dgm1[l,0:2]
if q[0]+q[1]==-2:
continue
qc = dgm1[l, 1::-1]
pq = (p[0] - q[0])**2 + (p[1] - q[1])**2
pqc = (p[0] - qc[0])**2 + (p[1] - qc[1])**2
kSigma2 += math.exp(-( pq) / (8 * sigma)) - math.exp(-(pqc) / (8 * sigma))

kSigma0 = kSigma0/(8 * np.pi * sigma)
kSigma1 = kSigma1/(8 * np.pi * sigma)
kSigma2 = kSigma2/(8 * np.pi * sigma)
result[i] = math.sqrt(kSigma1 + kSigma0-2*kSigma2)
Loading

0 comments on commit 9986e95

Please sign in to comment.