jupyter notebook - ValueError: need more than 1 value to unpack in network reconstruction -


from io import stringio  import numpy np import random #import networkx nx import os import io sklearn.linear_model import lasso sklearn import metrics multiprocessing import pool  data = np.loadtxt('c1.txt') # adjlist.txt #print data[:,2] fadj = np.matrix(data[:,2]) print fadj  def cal_phi(s,ni,sim):     """ calculate phi matrix , y vector     args:         s: binary state timeseries array         ni: index of node         sim: hamming similarity threshold     returns:         phi: phi matrix         yv: y vector     """     = ni     idof0, = np.where(s[:-1,i]==0)     s0 = s[idof0,:]     y1 = s[idof0+1,i]     lbase,num_nodes = s0.shape     x = s0     #~ base = np.random.randint(0,lbase,size=num_nodes)     base = range(lbase)     random.shuffle(base)     base = x[base[:num_nodes],:]     base = np.transpose(base)     hammatrix = num_nodes - (np.dot(x,base)+np.dot((1-x),(1-base)))     yv = np.zeros((num_nodes,1))     phi = np.zeros((num_nodes,num_nodes))     ibase in xrange(num_nodes):         idofsim, = np.where(hammatrix[:,ibase]<sim)         phi[ibase,:] = np.mean(s0[idofsim,:],0)         yv[ibase,0] = np.mean(y1[idofsim])     del base     #~ print phi,yv     del s     return phi,yv    def cal_x(phi,yv,nt=0.5):     """ calculate x vector lasso     args:         phi: phi matrix m*n dimension         yv: y vectors m*1 dimension         nt: fraction of used equations     returns:         xv: solution of x vector     """     m,n = phi.shape     nt = int(nt*n)     xv = 0     in xrange(5):         ntv = np.random.randint(0,m,size=nt)         #~ print ntv[0]         phi = phi[ntv,:]         yv = yv[ntv,0]         clf = lasso(alpha=0.0001,fit_intercept=false,max_iter=100000) #100000         clf.fit(phi,yv)         xv += clf.coef_/5.0     return xv    def cal_auc(xx,xv):     fpr,tpr,threshold = metrics.roc_curve(xx,xv)     auc = metrics.auc(fpr,tpr)     return auc   def cal_aupr(xx,xv):     pre,rec,threshold = metrics.precision_recall_curve(np.array(xx),np.array(xv))     aupr = metrics.auc([1-i in rec],pre)     return aupr  def cal_sr(xv,fadj=np.matrix(data[:,2])):  #adj.txt: # fadj='adjlist.txt' :fadj=np.matrix(data[:,2])     """ calculate success rates     args:         xv: dict, results of lasso         fadj: file name of exact adjacency matrix     """     auc = 0     aupr = 0     # new line:     xx = np.loadtxt(fadj,dtype=int) # fadj[:,2]: 3rd column of data has been loaded:     ii in xv:         xxi = xx[:,ii]         xvi = xv[ii]         auc += cal_auc(xxi,xvi)         aupr += cal_aupr(xxi,xvi)     return (auc/len(xv),aupr/len(xv))  def cal_individual(s,ii,sim):     #print ii,     phi,yv = cal_phi(s,ii,sim)     xv = cal_x(phi,yv,0.1)     ##print ii,xv     return (ii,xv)   def calall(s,num_nodes): #    print nl,     stemp = s[:,:]     sim = 0.45     sim = sim * num_nodes     xv = {}     pool = pool(2)     results = [pool.apply_async(cal_individual,(stemp,ii,sim)) ii in xrange(num_nodes)]     roots = [r.get() r in results]     xv={rts[0]:rts[1] rts in roots}     print '\n finished 1 network'     #auroc,aupr = cal_auroc_aupr(xv)     auroc,aupr = cal_sr(xv)     return (auroc,aupr)   ## main function def main(num_node):     s = np.loadtxt('binaryd.txt',dtype=int) # datasetfinal.txt: #binaryd.txt     ltime,num_nodes = s.shape     #print ltime,num_nodes     auroc,aupr = calall(s,num_nodes)     #auroc = (auroc * aupr)**0.5     return auroc,aupr  if __name__ == '__main__':     import gc     num_nodes = 100 #size of graph # 100     ii = np.arange(100)     print 'start'     auroc,aupr = main(num_nodes) # main function       xv = main(num_nodes) # newline     print 'auroc: %s'%auroc     print 'aupr: %s'%aupr     #print 'ii:%s'%ii # added new line:     gc.collect() 

my question has answers in stack overflow, not able debug goes wrong. getting following error:

traceback (most recent call last): file "test2.py", line 141, in auroc,aupr = main(num_nodes) # main function
file "test2.py", line 130, in main ltime,num_nodes = s.shape valueerror: need more 1 value unpack

any suggestions me out fix issue.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -