first_run = True if (args.method == "kernel"): print "Using kernelAS" activeSearch = asI.kernelAS() wMat = dataConn.getFinalFeatureMatrix(args.wordlimit,args.skip_stemmer, args.num_cpus, message_count, args.out_to_database, args.in_from_database, 0,0) restart_save = wMat.copy() activeSearch.initialize(wMat) elif (args.method == "shari"): print "Using shariAS" activeSearch = asI.shariAS() A = dataConn.getAffinityMatrix(args.wordlimit,args.skip_stemmer,args.num_cpus, message_count, args.out_to_database, args.in_from_database, 0,0) # Feeding in the dense version to shari's code because the sparse version is not implemented activeSearch.initialize(np.array(A.todense())) elif (args.method == "naiveshari"): print "Using naieveShariAS" activeSearch = asI.naiveShariAS() A = dataConn.getAffinityMatrix(args.wordlimit,args.skip_stemmer,args.num_cpus, message_count, args.out_to_database, args.in_from_database, 0,0) # Feeding in the dense version to shari's code because the sparse version is not implemented activeSearch.initialize(np.array(A.todense())) else: print "Invalid method argument. See help (run with -h)" sys.exit() # track the message ID that we're currently presenting the user for evaluation currentMessage = -1 #@app.route(...) #def login(): # username = request.args.get('username') # password = request.args.get('password')
def test_interface2 (): verbose = True nac = np.allclose #ts_data = ef.load_timestamps (tsfile) Xfull = load_sparse_csr('Xfull1.npz') print Xfull.shape # Xfull = Xfull[np.squeeze(np.asarray(np.nonzero(Xfull.sum(axis=1))[0])),:] # Xfull = Xfull[:,np.squeeze(np.asarray(np.nonzero(Xfull.sum(axis=0))[1]))] # r,n = Xfull.shape # print Xfull.shape # Xfull = Xfull[np.squeeze(np.asarray(np.nonzero(Xfull.sum(axis=1))[0])),:] # Xfull = Xfull[:,np.squeeze(np.asarray(np.nonzero(Xfull.sum(axis=0))[1]))] # getting rid of features which are zero for all these elements n = 300 r = 600 X = Xfull[:,:n] X = X[np.squeeze(np.array(np.nonzero(X.sum(axis=1))[0])),:] X = X[:,np.squeeze(np.array(np.nonzero(X.sum(axis=0))[1]))] X = X[:r,:] X = X[np.squeeze(np.array(np.nonzero(X.sum(axis=1))[0])),:] X = X[:,np.squeeze(np.array(np.nonzero(X.sum(axis=0))[1]))] print X.shape #X = np.load('X11.npy') r,n = X.shape nt = int(0.05*n) num_eval = 50 Y = np.array([1]*nt + [0]*(n-nt), dtype=int) pi = sum(Y)/len(Y) init_pt = 5 # import IPython # IPython.embed() A = np.array((X.T.dot(X)).todense()) t1 = time.time() prms = ASI.Parameters(pi=pi,sparse=True, verbose=verbose) kAS = ASI.kernelAS(prms) kAS.initialize(X) sAS = ASI.naiveShariAS(prms) sAS.initialize(A) import IPython IPython.embed() kAS.firstMessage(init_pt) fs2 = [kAS.f] sAS.firstMessage(init_pt) fs3 = [sAS.f] import IPython IPython.embed() for i in range(num_eval): idx1 = kAS.getNextMessage() idx2 = sAS.getNextMessage() print('NEXT') print idx1==idx2 print nac(kAS.f, sAS.f) # import IPython # IPython.embed() kAS.setLabelCurrent(Y[idx1]) sAS.setLabelCurrent(Y[idx2]) fs2.append(kAS.f) fs3.append(sAS.f) t2 = time.time() # f1,h1,s1,fs1,dtinv1 = AS.kernel_AS (Xfull, Y, pi=pi, num_eval=num_eval, init_pt=init_pt, verbose=verbose,all_fs=True,tinv=True,sparse=True) t3 = time.time() # checks = [np.allclose(fs1[i],fs2[i]) for i in range(len(fs1))] import IPython IPython.embed()
def test_warm_start (): verbose = True nac = np.allclose #ts_data = ef.load_timestamps (tsfile) Xfull = load_sparse_csr('Xfull1.npz') # print Xfull.shape # Xfull = Xfull[np.squeeze(np.asarray(np.nonzero(Xfull.sum(axis=1))[0])),:] # Xfull = Xfull[:,np.squeeze(np.asarray(np.nonzero(Xfull.sum(axis=0))[1]))] # # r,n = Xfull.shape # print Xfull.shape # Xfull = Xfull[np.squeeze(np.asarray(np.nonzero(Xfull.sum(axis=1))[0])),:] # Xfull = Xfull[:,np.squeeze(np.asarray(np.nonzero(Xfull.sum(axis=0))[1]))] # getting rid of features which are zero for all these elements n = 300 r = 600 X = Xfull[:,:n] X = X[np.squeeze(np.array(np.nonzero(X.sum(axis=1))[0])),:] X = X[:,np.squeeze(np.array(np.nonzero(X.sum(axis=0))[1]))] X = X[:r,:] X = X[np.squeeze(np.array(np.nonzero(X.sum(axis=1))[0])),:] X = X[:,np.squeeze(np.array(np.nonzero(X.sum(axis=0))[1]))] print X.shape #X = np.load('X11.npy') r,n = X.shape nt = int(0.05*n) num_eval = 50 Y = np.array([1]*nt + [0]*(n-nt), dtype=int) nr.shuffle(Y) pi = sum(Y)/len(Y) init_pt = 5 # import IPython # IPython.embed() A = np.array((X.T.dot(X)).todense()) t1 = time.time() prms = ASI.Parameters(pi=pi,sparse=True, verbose=verbose) kAS = ASI.kernelAS(prms) kAS.initialize(X) kAS2 = ASI.kernelAS(prms) sAS = ASI.shariAS(prms) sAS2 = ASI.naiveShariAS(prms) # import IPython # IPython.embed() init_lbls = {init_pt:1} kAS.firstMessage(init_pt) fs2 = [kAS.f] for i in range(num_eval): idx1 = kAS.getNextMessage() kAS.setLabelCurrent(Y[idx1]) init_lbls[idx1] = Y[idx1] # sAS.setLabelCurrent(Y[idx2]) # fs2.append(kAS.f) # fs3.append(sAS.f) print("Batch initializing:") print("Kernel AS:") kAS2.initialize(X, init_lbls) print("Shari AS:") sAS.initialize(A, init_lbls) print("Naive Shari AS:") sAS2.initialize(A, init_lbls) import IPython IPython.embed()
args.out_to_database, args.in_from_database, 0, 0) restart_save = wMat.copy() activeSearch.initialize(wMat) elif (args.method == "shari"): print "Using shariAS" activeSearch = asI.shariAS() A = dataConn.getAffinityMatrix(args.wordlimit, args.skip_stemmer, args.num_cpus, message_count, args.out_to_database, args.in_from_database, 0, 0) # Feeding in the dense version to shari's code because the sparse version is not implemented activeSearch.initialize(np.array(A.todense())) elif (args.method == "naiveshari"): print "Using naieveShariAS" activeSearch = asI.naiveShariAS() A = dataConn.getAffinityMatrix(args.wordlimit, args.skip_stemmer, args.num_cpus, message_count, args.out_to_database, args.in_from_database, 0, 0) # Feeding in the dense version to shari's code because the sparse version is not implemented activeSearch.initialize(np.array(A.todense())) else: print "Invalid method argument. See help (run with -h)" sys.exit() # track the message ID that we're currently presenting the user for evaluation currentMessage = -1 #@app.route(...) #def login():