Skip to content

Commit

Permalink
This it's related with #14
Browse files Browse the repository at this point in the history
  • Loading branch information
devmessias committed Jul 13, 2020
1 parent 732007e commit a5d480f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
4 changes: 0 additions & 4 deletions tests/context.py

This file was deleted.

41 changes: 29 additions & 12 deletions tests/test_kpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import numpy as np
import matplotlib.pyplot as plt

from .context import emate
#from .context import emate
import emate

try:
import cupy as cp
Expand All @@ -14,9 +15,12 @@


def calc_cupykpm(W, vals, kde):
num_moments = 140
num_vecs = 140
extra_points = 25
import cupy as cp
print("\nCUPY version", cp.__version__, "\n")

num_moments = 50
num_vecs = 50
extra_points = 5
ek, rho = emate.hermitian.cupykpm(
W.tocsr().astype("complex64"), num_moments, num_vecs, extra_points)

Expand All @@ -30,11 +34,15 @@ def calc_cupykpm(W, vals, kde):
return integrate.simps(ek.get(), np.abs(rho.get()-np.exp(log_dens))) < 0.01

def calc_tfkpm(W, vals, kde):
import tensorflow as tf
print("\nTF version", tf.__version__, "\n")

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")
num_vecs = 20
extra_points = 5
ek, rho = emate.hermitian.tfkpm(
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")
Expand All @@ -45,17 +53,26 @@ def calc_tfkpm(W, vals, kde):

return integrate.simps(ek, np.abs(rho-np.exp(log_dens))) < 0.01

def test_kpm():
def test_tfkpm():
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)


def test_cupykpm():
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])

if textCupyImplementation:
assert calc_cupykpm(W, vals, kde)

0 comments on commit a5d480f

Please sign in to comment.