Repository: neurodata/graspy
Pull request #40 (2018-10-01 04:29:15)

Renaming
Change graphstats -> graspy


Patch:
diff --git a/graphstats/simulations/__init__.py b/graphstats/simulations/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/graphstats/__init__.py b/graspy/__init__.py
similarity index 100%
rename from graphstats/__init__.py
rename to graspy/__init__.py
diff --git a/graphstats/embed/__init__.py b/graspy/embed/__init__.py
similarity index 100%
rename from graphstats/embed/__init__.py
rename to graspy/embed/__init__.py
diff --git a/graphstats/embed/ase.py b/graspy/embed/ase.py
similarity index 100%
rename from graphstats/embed/ase.py
rename to graspy/embed/ase.py
diff --git a/graphstats/embed/embed.py b/graspy/embed/embed.py
similarity index 100%
rename from graphstats/embed/embed.py
rename to graspy/embed/embed.py
diff --git a/graphstats/embed/lpm.py b/graspy/embed/lpm.py
similarity index 100%
rename from graphstats/embed/lpm.py
rename to graspy/embed/lpm.py
diff --git a/graphstats/embed/lse.py b/graspy/embed/lse.py
similarity index 100%
rename from graphstats/embed/lse.py
rename to graspy/embed/lse.py
diff --git a/graphstats/embed/omni.py b/graspy/embed/omni.py
similarity index 100%
rename from graphstats/embed/omni.py
rename to graspy/embed/omni.py
diff --git a/graphstats/embed/svd.py b/graspy/embed/svd.py
similarity index 100%
rename from graphstats/embed/svd.py
rename to graspy/embed/svd.py
diff --git a/graspy/simulations/__init__.py b/graspy/simulations/__init__.py
new file mode 100644
index 00000000..13eebab1
--- /dev/null
+++ b/graspy/simulations/__init__.py
@@ -0,0 +1,1 @@
+from .simulations import *
\ No newline at end of file
diff --git a/graphstats/simulations/simulations.py b/graspy/simulations/simulations.py
similarity index 94%
rename from graphstats/simulations/simulations.py
rename to graspy/simulations/simulations.py
index d2a2a5ae..0d1984ec 100644
--- a/graphstats/simulations/simulations.py
+++ b/graspy/simulations/simulations.py
@@ -6,13 +6,15 @@
 # Copyright (c) 2018. All rights reserved.
 
 import numpy as np
-from graphstats.utils import import_graph, symmetrize
+from ..utils import import_graph, symmetrize
 
 
 def cartprod(*arrays):
-     N = len(arrays)
-     return np.transpose(np.meshgrid(*arrays, indexing='ij'), 
-                      np.roll(np.arange(N + 1), -1)).reshape(-1, N)
+    N = len(arrays)
+    return np.transpose(
+        np.meshgrid(*arrays, indexing='ij'), np.roll(np.arange(N + 1),
+                                                     -1)).reshape(-1, N)
+
 
 def weighted_sbm(n, P, Wt=1, directed=False, loops=False, Wtargs=None):
     """
@@ -91,7 +93,7 @@ def weighted_sbm(n, P, Wt=1, directed=False, loops=False, Wtargs=None):
         if Wt.shape != Wtargs.shape:
             er_msg = "Wt is of shape {}, but Wtargs is of shape {}."
             er_msg += " They should have the same shape."
-            raise ValueError(er_msg) 
+            raise ValueError(er_msg)
     else:
         # reshape to make an ndarray for each community
         Wt = np.full(P.shape, Wt, dtype=object)
@@ -108,12 +110,15 @@ def weighted_sbm(n, P, Wt=1, directed=False, loops=False, Wtargs=None):
         else:
             jrange = range(i, K)
         for j in jrange:
-            wt = Wt[i, j]; wtargs = Wtargs[i, j]; p = P[i, j]
+            wt = Wt[i, j]
+            wtargs = Wtargs[i, j]
+            p = P[i, j]
             # identify submatrix for community i, j
             # cartesian product to identify edges for community i,j pair
             cprod = cartprod(cmties[i], cmties[j])
             # get idx in 1d coordinates by ravelling
-            triu = np.ravel_multi_index((cprod[:,0], cprod[:,1]), dims=A.shape)
+            triu = np.ravel_multi_index(
+                (cprod[:, 0], cprod[:, 1]), dims=A.shape)
             pchoice = np.random.uniform(size=len(triu))
             # connected with probability p
             triu = triu[pchoice < p]
@@ -127,12 +132,13 @@ def weighted_sbm(n, P, Wt=1, directed=False, loops=False, Wtargs=None):
         A = A - np.diag(np.diag(A))
     if not directed:
         A = symmetrize(A)
-    return(A)
+    return (A)
     if not loops:
         A = remove_loops(A)
     if not directed:
         A = symmetrize(A)
-    return(A)
+    return (A)
+
 
 def binary_sbm(n, P, directed=False, loops=False):
     """
@@ -163,7 +169,8 @@ def binary_sbm(n, P, directed=False, loops=False):
         A: array-like, shape (n, n)
             the adjacency matrix.
     """
-    return(weighted_sbm(n, P, directed=directed, loops=loops))
+    return (weighted_sbm(n, P, directed=directed, loops=loops))
+
 
 def zi_nm(n, M, wt=1, directed=False, loops=False, **kwargs):
     """
@@ -210,7 +217,7 @@ def zi_nm(n, M, wt=1, directed=False, loops=False, **kwargs):
     else:
         # get all indices including diagonal
         er_msg = "n(n-1)"
-        Mmax = n*(n-1)
+        Mmax = n * (n - 1)
 
     A = np.zeros((n, n))
     # check if directedness is desired
@@ -226,7 +233,7 @@ def zi_nm(n, M, wt=1, directed=False, loops=False, **kwargs):
         # to loops argument
         idx = np.triu_indices(n, k=int(loops == False))
         er_msg += "/2"
-        Mmax = Mmax/2
+        Mmax = Mmax / 2
 
     # check whether M exceeds the maximum possible M
     if M > Mmax:
@@ -255,7 +262,8 @@ def zi_nm(n, M, wt=1, directed=False, loops=False, **kwargs):
     A[triu] = wt
     if not directed:
         A = symmetrize(A)
-    return(A)
+    return (A)
+
 
 def zi_np(n, p, wt=1, directed=False, loops=False, **kwargs):
     """
@@ -313,7 +321,7 @@ def zi_np(n, p, wt=1, directed=False, loops=False, **kwargs):
     else:
         # get all indices including diagonal
         er_msg = "n(n-1)"
-        Mmax = n*(n-1)
+        Mmax = n * (n - 1)
 
     A = np.zeros((n, n))
     # check if directedness is desired
@@ -329,7 +337,7 @@ def zi_np(n, p, wt=1, directed=False, loops=False, **kwargs):
         # to loops argument
         idx = np.triu_indices(n, k=int(loops == False))
         er_msg += "/2"
-        Mmax = Mmax/2
+        Mmax = Mmax / 2
 
     # select uniformly btwn 0 and 1; retain edges with pchosen < p
     # get triu in 1d coordinates by ravelling
@@ -350,7 +358,8 @@ def zi_np(n, p, wt=1, directed=False, loops=False, **kwargs):
     A[triu] = wt
     if not directed:
         A = symmetrize(A)
-    return(A)
+    return (A)
+
 
 def er_nm(n, M):
     """
@@ -373,7 +382,8 @@ def er_nm(n, M):
     -------
         A: array-like, shape (n, n)
     """
-    return(zi_nm(n, M, wt=1))
+    return (zi_nm(n, M, wt=1))
+
 
 def er_np(n, p):
     """
@@ -392,4 +402,4 @@ def er_np(n, p):
     -------
         A: array-like, shape (n, n)
     """
-    return(zi_np(n, p, wt=1))
\ No newline at end of file
+    return (zi_np(n, p, wt=1))
diff --git a/graphstats/utils/__init__.py b/graspy/utils/__init__.py
similarity index 100%
rename from graphstats/utils/__init__.py
rename to graspy/utils/__init__.py
diff --git a/graphstats/utils/utils.py b/graspy/utils/utils.py
similarity index 100%
rename from graphstats/utils/utils.py
rename to graspy/utils/utils.py
diff --git a/docs/bpedigo/ase_clustering.ipynb b/notebooks/bpedigo/ase_clustering.ipynb
similarity index 100%
rename from docs/bpedigo/ase_clustering.ipynb
rename to notebooks/bpedigo/ase_clustering.ipynb
diff --git a/setup.py b/setup.py
index e6a933e7..5ac87329 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ from setuptools.command.install import install
 from subprocess import check_output, call
 from sys import platform
 
-PACKAGE_NAME = 'graphstats'
+PACKAGE_NAME = 'graspy'
 DESCRIPTION = 'A set of python modules for graph statistics'
 with open('README.md', 'r') as f:
     LONG_DESCRIPTION = f.read()


Test patch:
diff --git a/tests/test_base_embed.py b/tests/test_base_embed.py
index b5aec914..5465de06 100644
--- a/tests/test_base_embed.py
+++ b/tests/test_base_embed.py
@@ -1,12 +1,12 @@
 import unittest
-import graphstats as gs
+import graspy as gs
 import numpy as np
 import networkx as nx
-from graphstats.embed.embed import BaseEmbed
-from graphstats.simulations.simulations import er_nm
+from graspy.embed.embed import BaseEmbed
+from graspy.simulations.simulations import er_nm
+
 
 class TestBaseEmbed(unittest.TestCase):
-    
     def test_baseembed_er(self):
         k = 4
         embed = BaseEmbed(k=k)
diff --git a/tests/test_io.py b/tests/test_io.py
index baa5dbd3..fb69f5e7 100644
--- a/tests/test_io.py
+++ b/tests/test_io.py
@@ -1,8 +1,8 @@
 import unittest
-import graphstats as gs
+import graspy as gs
 import numpy as np
 import networkx as nx
-from graphstats.utils import utils as gus
+from graspy.utils import utils as gus
 
 
 class TestInput(unittest.TestCase):
diff --git a/tests/test_lpm.py b/tests/test_lpm.py
index 2d5a3ae2..5119936d 100644
--- a/tests/test_lpm.py
+++ b/tests/test_lpm.py
@@ -1,29 +1,27 @@
 import unittest
-import graphstats as gs
+import graspy as gs
 import numpy as np
 import networkx as nx
-from graphstats.embed.lpm import LatentPosition
+from graspy.embed.lpm import LatentPosition
 
 
 class TestLPM(unittest.TestCase):
+    @classmethod
+    def setUpClass(cls):
+        n = 10
+        d = 5
+        cls.X = np.random.rand(n, d).reshape((n, d))
+        cls.Y = np.random.rand(n, d).reshape((n, d))
 
-	@classmethod
-	def setUpClass(cls):
-		n = 10
-		d = 5
-		cls.X = np.random.rand(n, d).reshape((n, d))
-		cls.Y = np.random.rand(n, d).reshape((n, d))
+    def test_symmetric(self):
+        lpm = LatentPosition(self.X, self.X)
+        self.assertTrue(lpm.is_symmetric())
+        self.assertTrue(lpm.Y is None)
+        np.testing.assert_equal(lpm.X, self.X)
 
-
-	def test_symmetric(self):
-		lpm = LatentPosition(self.X, self.X)
-		self.assertTrue(lpm.is_symmetric())
-		self.assertTrue(lpm.Y is None)
-		np.testing.assert_equal(lpm.X, self.X)
-
-	def test_asymmetric(self):
-		lpm = LatentPosition(self.X, self.Y)
-		self.assertFalse(lpm.is_symmetric())
-		self.assertFalse(lpm.Y is None)
-		np.testing.assert_equal(lpm.X, self.X)
-		np.testing.assert_equal(lpm.Y, self.Y)
+    def test_asymmetric(self):
+        lpm = LatentPosition(self.X, self.Y)
+        self.assertFalse(lpm.is_symmetric())
+        self.assertFalse(lpm.Y is None)
+        np.testing.assert_equal(lpm.X, self.X)
+        np.testing.assert_equal(lpm.Y, self.Y)
diff --git a/tests/test_omni.py b/tests/test_omni.py
index 314a2df2..b071d677 100644
--- a/tests/test_omni.py
+++ b/tests/test_omni.py
@@ -4,9 +4,9 @@ import networkx as nx
 from numpy import array_equal, allclose
 from numpy.linalg import norm
 
-from graphstats.embed.omni import OmnibusEmbed, _get_omni_matrix
-from graphstats.simulations.simulations import er_np
-from graphstats.utils.utils import symmetrize, is_symmetric
+from graspy.embed.omni import OmnibusEmbed, _get_omni_matrix
+from graspy.simulations.simulations import er_np
+from graspy.utils.utils import symmetrize, is_symmetric
 
 
 def generate_data(n, seed=1):
diff --git a/tests/test_sims.py b/tests/test_sims.py
index 6977c66b..40e261b3 100644
--- a/tests/test_sims.py
+++ b/tests/test_sims.py
@@ -1,9 +1,9 @@
 import unittest
-import graphstats as gs
+import graspy as gs
 import numpy as np
 import networkx as nx
-from graphstats.simulations.simulations import *
-from graphstats.utils.utils import is_symmetric, is_loopless
+from graspy.simulations.simulations import *
+from graspy.utils.utils import is_symmetric, is_loopless
 
 
 def remove_diagonal(A):
diff --git a/tests/test_spectral_embed.py b/tests/test_spectral_embed.py
index 7ef3bff0..0732e795 100644
--- a/tests/test_spectral_embed.py
+++ b/tests/test_spectral_embed.py
@@ -1,13 +1,14 @@
 import unittest
-import graphstats as gs
+import graspy as gs
 import numpy as np
 import networkx as nx
-from graphstats.embed.ase import AdjacencySpectralEmbed
-from graphstats.embed.lse import LaplacianSpectralEmbed  
-from graphstats.simulations.simulations import er_np, er_nm, weighted_sbm
+from graspy.embed.ase import AdjacencySpectralEmbed
+from graspy.embed.lse import LaplacianSpectralEmbed
+from graspy.simulations.simulations import er_np, er_nm, weighted_sbm
 from sklearn.cluster import KMeans
 from sklearn.metrics import adjusted_rand_score
 
+
 def _kmeans_comparison(data, labels, n_clusters):
     """
     Function for comparing the ARIs of kmeans clustering for arbitrary number of data/labels
@@ -29,17 +30,18 @@ def _kmeans_comparison(data, labels, n_clusters):
             of k-means clustering on the i-th data/labels
 
     """
-    
-    if len(data) != len(labels): 
+
+    if len(data) != len(labels):
         raise ValueError('Must have same number of labels and data')
 
     aris = []
     for i in range(0, len(data)):
         kmeans_prediction = KMeans(n_clusters=n_clusters).fit_predict(data[i])
         aris.append(adjusted_rand_score(labels[i], kmeans_prediction))
-    
+
     return aris
 
+
 def _test_output_dim(self, method, *args, **kwargs):
     k = 4
     embed = method(k=k)
@@ -50,15 +52,16 @@ def _test_output_dim(self, method, *args, **kwargs):
     self.assertEqual(embed.lpm.X.shape, (n, 4))
     self.assertTrue(embed.lpm.is_symmetric())
 
+
 def _test_sbm_er_binary_undirected(self, method, P, *args, **kwargs):
     np.random.seed(8888)
-        
+
     num_sims = 50
     verts = 200
-    communities = 2 
+    communities = 2
 
     verts_per_community = [100, 100]
-    
+
     sbm_wins = 0
     er_wins = 0
     for sim in range(0, num_sims):
@@ -81,15 +84,16 @@ def _test_sbm_er_binary_undirected(self, method, P, *args, **kwargs):
         self.assertEqual(X_sbm.shape, (verts, communities))
         self.assertEqual(X_er.shape, (verts, communities))
 
-        aris = _kmeans_comparison((X_sbm, X_er), (labels_sbm, labels_er), communities)
+        aris = _kmeans_comparison((X_sbm, X_er), (labels_sbm, labels_er),
+                                  communities)
         sbm_wins = sbm_wins + (aris[0] > aris[1])
         er_wins = er_wins + (aris[0] < aris[1])
     #print(sbm_wins)
     #print(er_wins)
-    self.assertTrue(sbm_wins > er_wins)    
+    self.assertTrue(sbm_wins > er_wins)
+
 
 class TestAdjacencySpectralEmbed(unittest.TestCase):
-    
     def test_output_dim(self):
         _test_output_dim(self, AdjacencySpectralEmbed)
 
@@ -97,17 +101,15 @@ class TestAdjacencySpectralEmbed(unittest.TestCase):
         P = np.array([[0.8, 0.2], [0.2, 0.8]])
         _test_sbm_er_binary_undirected(self, AdjacencySpectralEmbed, P)
 
-class TestLaplacianSpectralEmbed(unittest.TestCase):
 
+class TestLaplacianSpectralEmbed(unittest.TestCase):
     def test_output_dim(self):
         _test_output_dim(self, LaplacianSpectralEmbed)
-    
+
     def test_sbm_er_binary_undirected(self):
         P = np.array([[0.8, 0.2], [0.2, 0.3]])
         _test_sbm_er_binary_undirected(self, LaplacianSpectralEmbed, P)
 
 
-if __name__ == '__main__': 
+if __name__ == '__main__':
     unittest.main()
-
-        
\ No newline at end of file
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 3ab4c2f6..e4aa19f9 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -1,10 +1,11 @@
 import unittest
-import graphstats as gs
+import graspy as gs
 import numpy as np
 import networkx as nx
-from graphstats.utils import utils as gus
+from graspy.utils import utils as gus
 from math import sqrt
 
+
 class TestInput(unittest.TestCase):
     @classmethod
     def setUpClass(cls):
@@ -34,14 +35,12 @@ class TestInput(unittest.TestCase):
             gus.import_graph(None)
 
     def test_to_laplace_IDAD(self):
-        A = np.array([[0, 1, 0],
-                      [1, 0, 1],
-                      [0, 1, 0]])
-
-        expected_L_normed = ([[1, -1/(sqrt(2)), 0],
-                              [-1/(sqrt(2)), 1, -1/(sqrt(2))],
-                              [0, -1/(sqrt(2)), 1]])
-                              
+        A = np.array([[0, 1, 0], [1, 0, 1], [0, 1, 0]])
+
+        expected_L_normed = ([[1, -1 / (sqrt(2)),
+                               0], [-1 / (sqrt(2)), 1, -1 / (sqrt(2))],
+                              [0, -1 / (sqrt(2)), 1]])
+
         L_normed = gus.to_laplace(A, form='I-DAD')
 
         self.assertTrue(np.allclose(L_normed, expected_L_normed, rtol=1e-04))
@@ -50,5 +49,6 @@ class TestInput(unittest.TestCase):
         with self.assertRaises(TypeError):
             gus.to_laplace(self.A, form='MOM')
 
+
 if __name__ == '__main__':
     unittest.main()