-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f287f30
commit 5761dd5
Showing
6 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.tests/*.png | ||
.vscode | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
numpy==1.19.0 | ||
scipy==1.5.0 | ||
numpy | ||
scipy | ||
tensorflow==1.15.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
numpy==1.19.0 | ||
scipy==1.5.0 | ||
tensorflow-gpu==1.15.2 | ||
numpy | ||
scipy | ||
tensorflow-gpu==1.15.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
numpy | ||
scipy | ||
tensorflow-gpu==1.15.3 | ||
networkx | ||
sklearn | ||
matplotlib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import os | ||
import sys | ||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
import emate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from sklearn.neighbors import KernelDensity | ||
from scipy import integrate | ||
import networkx as nx | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
from .context import emate | ||
|
||
try: | ||
import cupy as cp | ||
textCupyImplementation = True | ||
except: | ||
textCupyImplementation = False | ||
|
||
|
||
def calc_cupykpm(W, vals, kde): | ||
num_moments = 140 | ||
num_vecs = 140 | ||
extra_points = 25 | ||
ek, rho = emate.hermitian.cupykpm( | ||
W.tocsr().astype("complex64"), num_moments, num_vecs, extra_points) | ||
|
||
print("Saving the cupyKPM plot..") | ||
plt.hist(vals, density=True, bins=100, alpha=.9, color="steelblue") | ||
plt.scatter(ek.get(), rho.get(), c="tomato", zorder=999, alpha=0.9, marker="d") | ||
plt.savefig("tests/test_kpm_cupy.png", filetype="png") | ||
|
||
log_dens = kde.score_samples(ek.get()[:, np.newaxis]) | ||
|
||
return integrate.simps(ek.get(), np.abs(rho.get()-np.exp(log_dens))) < 0.01 | ||
|
||
def calc_tfkpm(W, vals, kde): | ||
num_moments = 40 | ||
num_vecs = 40 | ||
extra_points = 25 | ||
ek, rho = emate.hermitian.cupykpm( | ||
W.tocsr().astype("complex64"), num_moments, num_vecs, extra_points, device="cpu:0") | ||
|
||
print("Saving the tfKPM plot..") | ||
plt.hist(vals, density=True, bins=100, alpha=.9, color="steelblue") | ||
plt.scatter(ek, rho, c="tomato", zorder=999, alpha=0.9, marker="d") | ||
plt.savefig("tests/test_kpm_tf.png", filetype="png") | ||
|
||
log_dens = kde.score_samples(ek[:, np.newaxis]) | ||
|
||
return integrate.simps(ek, np.abs(rho-np.exp(log_dens))) < 0.01 | ||
|
||
def test_kpm(): | ||
n = 1000 | ||
g = nx.erdos_renyi_graph(n , 3/n) | ||
W = nx.adjacency_matrix(g) | ||
|
||
vals = np.linalg.eigvals(W.todense()).real | ||
|
||
kde = KernelDensity(kernel='gaussian', bandwidth=0.1).fit(vals[:, np.newaxis]) | ||
|
||
assert calc_tfkpm(W, vals, kde) | ||
|
||
if textCupyImplementation: | ||
assert calc_cupykpm(W, vals, kde) | ||
|