yonatanf avatar yonatanf committed 4d70afc

FIX: removed global matplotlib import from simulated_data

Comments (0)

Files changed (2)

lib/basis_correlations.py

     import scipy.stats as stats
     type = type.lower()
     if type not in set(['pearson', 'kendall', 'spearman']): raise IOError('Specified correlation type is not supported.')
-    if type == 'pearson'  : corr_fun = stats.pearsonr
-    elif type == 'kendall': corr_fun = stats.kendalltau
-    elif type == 'spearman' : corr_fun = stats.spearmanr
-    m,n = np.shape(x)
-    c_mat = np.zeros((n, n))
-    p_mat = np.zeros((n, n))
-    for i in xrange(n):
-        for j in xrange(i, n):
-            if i == j: 
-                c_mat[i][i] = 1
-                p_mat[i][i] = 1
-                continue
-            c_temp, p_temp = corr_fun(x[:,i], x[:,j])
-            c_mat[i][j] = c_temp
-            c_mat[j][i] = c_temp
-            p_mat[i][j] = p_temp
-            p_mat[j][i] = p_temp
+    if type == 'spearman' : 
+        c_mat, p_mat = stats.spearmanr(x)
+    else:
+        if type == 'pearson'  : corr_fun = stats.pearsonr
+        elif type == 'kendall': corr_fun = stats.kendalltau
+        m,n = np.shape(x)
+        c_mat = np.zeros((n, n))
+        p_mat = np.zeros((n, n))
+        for i in xrange(n):
+            for j in xrange(i, n):
+                if i == j: 
+                    c_mat[i][i] = 1
+                    p_mat[i][i] = 1
+                    continue
+                c_temp, p_temp = corr_fun(x[:,i], x[:,j])
+                c_mat[i][j] = c_temp
+                c_mat[j][i] = c_temp
+                p_mat[i][j] = p_temp
+                p_mat[j][i] = p_temp
     return c_mat, p_mat
 
 
     elif algo in ['pearson', 'kendall', 'spearman']:
         for i in range(iter):
             if oprint: print '\tRunning iteration ' + str(i)
-            fracs = comp_fractions(counts)
+            fracs = comp_fractions(counts, method=norm)
             if log:
                 x = np.log(fracs)
             else:
                 x = fracs
-            cor_mat, pval = correlation(x, algo)
+            cor_mat, pval = correlation(array(x), algo)
             cor_list.append(cor_mat)
         cor_array   = np.array(cor_list)
         cor_med = np.median(cor_array,axis = 0) #median correlation

lib/simulate_data.py

 '''
 import numpy as np
 import cPickle as pickle
-import matplotlib.pyplot as plt
 from SurveyMatrix import Survey_matrix
 #from estimate_dist import estimate
 #from numpy.random.mtrand import dirichlet
  
  
 def test_dirichlet():
+    import matplotlib.pyplot as plt
     N = 100
     n = 200
     k = 50
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.