def funcNbofAttr(P, G): endDir = 'G_%.3f_P_%.5f.npy' %(G,P) try: pattsx = data2array(dir_prix + '/patterns_' + endDir, mmap_mode="r+") pattsA = data2array(dir_priA + '/patterns_' + endDir, mmap_mode="r+") return len(pattsx) except: try: pattsx = data2array(dir_prix + '/allPatt_' + endDir) pattsA = data2array(dir_priA + '/allPatt_' + endDir) except: N = data2array(dco).shape[0] pattsx = zeros((mmax,N)) pattsA = zeros((mmax,N)) conn = {'connAd': dco, 'normType': '1'} noise = {'colors': None} model = {'model': 'HopfieldBasedStatic', 'threshold': 'local', 'tauT': 0, 'P': P, 'G': G} out = [] other = {'init': 'rand', 'dens': rand(),} #p2,!!!!!!!!!!!!!! RAND for d in range(mmax): eva = main.evaCure(evaCon=conn, evaNoi=noise, evaMod=model, out=out, **other) eva.toEquilibrium() pattsx[d] = eva.evaMod.x.copy() pattsA[d] = eva.evaMod.A.copy() array2data(pattsx, dir_prix + '/allPatt_' + endDir) array2data(pattsA, dir_priA + '/allPatt_' + endDir) patts = pattsx # !!!!!!!!! S = sortBy(patts.mean(1) - patts.mean(), inverse=1)[0] C1, freq = preClustering(patts[S], sim_coef=sim_coef, sim_func=similarity_Euclidean) C2, freq = preClustering(patts[S][C1], freq=freq, sim_coef=sim_coef, sim_func=fPearsonCorrelation) SC, freq = sortBy(freq, inverse=1) array2data(pattsx[S][C1][C2][SC], dir_prix + '/patterns_' + endDir) array2data(pattsA[S][C1][C2][SC], dir_priA + '/patterns_' + endDir) array2data(freq, dir_priT + '/tendances_' + endDir) os.system('rm ' + dir_prix + '/allPatt_' + endDir) os.system('rm ' + dir_priA + '/allPatt_' + endDir) return len(pattsx[S][C1][C2][SC])
def save(_, dir_=None): '''Save the database in the directory .dir by default or specified during the initialization. If dir_ is specified, it change the directory of the database while saving it. ''' try: size = humanSize(path.getsize(_.dir)) if dir_: _.dir = dir_ array2data(_, _.dir) print 'Saved here : %s (%s, %i items)' %(_.dir, size, _.len()) except: print 'Problem with the adresses.' return None
mkdir(dir2X) sim_coef = 0.9 #endFName = '_P_%.2f_f0_%.2f.npy' %(p1,p2) endFName = '_P_%.2f_G_%.2f.npy' % (p1, p2) fileName = 'patterns' + endFName ############################################################################################' # **Main** if not adressExists(dir2X + fileName): tic() pattsX = data2array(dir1X + fileName, mmap_mode="r+") #.reshape((3300,998)) pattsS = data2array(dir1S + fileName, mmap_mode="r+") #.reshape((3300,998)) patts = pattsX #!!! S = sortBy(patts.mean(1) - patts.mean(), inverse=1)[0] C1, freq = preClustering(patts[S], sim_coef=sim_coef, sim_func=similarity_Euclidean) C2, freq = preClustering(patts[S][C1], freq=freq, sim_coef=sim_coef, sim_func=fPearsonCorrelation) SC, freq = sortBy(freq, inverse=1) array2data(pattsX[S][C1][C2][SC], dir2X + fileName) array2data(pattsS[S][C1][C2][SC], dir2S + fileName) array2data(freq, dir2X + '/tendances' + endFName) tac()
eva = main.evaCure(evaCon=conn, evaNoi=noise, evaMod=model, out=out, **other) #Run for i in range(T0): eva.update() eva.evaNoi.updateNoise(stdD_x=sx, stdD_T=sT) for i in range(TF): eva.update() #Save x.append(array(eva.out['x'])) A.append(array(eva.out['A']).mean(1)) del eva print iii tac() ############################################################################################' # **Save** array2data(array(x), './DL/x_%i.npy' % p1) del x array2data(array(A), './DL/A_%i.npy' % p1) del A else: print 'File exists.'
# **Parameters** while len(sys.argv) > 1: option = sys.argv[1]; del sys.argv[1] if option == '-G': G = float(sys.argv[1].replace(',','.')); del sys.argv[1] elif option == '-sx': sx = float(sys.argv[1].replace(',','.')); del sys.argv[1] elif option == '-sT': sT = float(sys.argv[1].replace(',','.')); del sys.argv[1] elif option == '-dir': dir_= str(sys.argv[1]); del sys.argv[1] else: print 'Options invalides :',option,'->',sys.argv[0] mdir = '/home/mathieuG/TCS/%s' %dir_ name = 'G_%.2f_sx_%.3f_sT_%.3f.npy' %(G, sx, sT) dir_DFC = mdir + '/DFC_998/' dir_TC = mdir + '/TC_998/' try: mkdir(dir_DFC) except: pass ############################################################################################' # **Main** if not adressExists(dir_DFC + name): TC = data2array(dir_TC + name) FCs = windowedFCs(TC, window=6000, jump=100) DFC = windowedCorrelations(FCs) array2data(DFC, dir_DFC + name)
############################################################################################' # **Loop** tic() for iii in range(100): # Init other.update({'dens':rand()}) eva = main.evaCure(evaCon=conn, evaNoi=noise, evaMod=model, out=out, **other) #Run for i in range(T0): eva.update() #Save x.append( array(eva.out['x']) ) A.append( array(eva.out['A']).mean(1) ) del eva print iii tac() ############################################################################################' # **Save** array2data(array(x), './SL_0/x_%i.npy'%p1); del x array2data(array(A), './SL_0/A_%i.npy'%p1); del A else: print 'File exists.'
noise = {'colors': None} model = { 'model': 'HopfieldBasedStatic', 'threshold': 'global', 'tauT': 0, 'P': p1, 'G': p2 } #900} out = [] other = { 'init': 'rand', 'dens': 0.3, #rand(), #p2, 'rperiod': 100 } for d in range(3300): eva = main.evaCure(evaCon=conn, evaNoi=noise, evaMod=model, out=out, **other) eva.toEquilibrium() all_pattx[d] = eva.evaMod.x.copy() all_pattA[d] = eva.evaMod.A.copy() array2data(all_pattx, dir_prix + dir_sub) array2data(all_pattA, dir_priA + dir_sub)
eva = main.evaCure(evaCon=conn, evaNoi=noise, evaMod=model, out=out, **other) #Run for i in range(T0): eva.update() eva.evaNoi.updateNoise(stdD_x=sx, stdD_T=sT) for i in range(TF): eva.update() #Save x.append(array(eva.out['x'])) A.append(array(eva.out['A']).mean(1)) del eva print iii tac() ############################################################################################' # **Save** array2data(array(x), './SG/x_%i.npy' % p1) del x array2data(array(A), './SG/A_%i.npy' % p1) del A else: print 'File exists.'
S = sortBy(patts.mean(1) - patts.mean(), inverse=1)[0] C1, freq = preClustering(patts[S], sim_coef=sim_coef, sim_func=similarity_Euclidean) C2, freq = preClustering(patts[S][C1], freq=freq, sim_coef=sim_coef, sim_func=fPearsonCorrelation) SC, freq = sortBy(freq, inverse=1) array2data(pattsx[S][C1][C2][SC], dir_prix + '/patterns_' + endDir) array2data(pattsA[S][C1][C2][SC], dir_priA + '/patterns_' + endDir) array2data(freq, dir_priT + '/tendances_' + endDir) os.system('rm ' + dir_prix + '/allPatt_' + endDir) os.system('rm ' + dir_priA + '/allPatt_' + endDir) return len(pattsx[S][C1][C2][SC]) ############################################################################################' # **Main** dir_sub = '/dP_G_%.3f_r_%i.npy' %(G, revert) if not adressExists(dir_priC + dir_sub): mkdir(dir_prix) mkdir(dir_priA) mkdir(dir_priT) mkdir(dir_priC) if revert: x = [0.95, 2.00] else: x = [0.00, 1.05] dx = paramExplo(funcNbofAttr, nb=[7,1], ax='x', x=x, y=[G], revert=revert) array2data(dx, dir_priC + dir_sub)
'tauT': 80, 'P': P, 'G': 900., } noise = {'stdD_x': sx, 'stdD_T': sT, 'colors': ['white', 'white']} out = ['x'] other = {'init': 'rand', 'dens': 0.5, 'rperiod': 100, 'dur': '20m'} eva = main.evaCure(evaCon=conn, evaNoi=noise, evaMod=model, out=out, **other) eva.updateTillEnd() TC = eva.out['x'] array2data(TC, dir_TC + '/TC_998_' + name) if not adressExists(dir_FC + '/FC_998_' + name): try: TC = array(TC) except: TC = data2array(dir_TC + '/TC_998_' + name) tic() FC = fPearsonCorrelation(TC) tac('h') array2data(FC, dir_FC + '/FC_998_' + name)
'tauT': 80, 'P': P, 'G': 900., } noise = {'stdD_x': sx, 'stdD_T': sT, 'colors': ['white', 'white']} out = ['x'] other = {'init': 'rand', 'dens': 0.5, 'rperiod': 100, 'dur': '20m'} eva = main.evaCure(evaCon=conn, evaNoi=noise, evaMod=model, out=out, **other) eva.updateTillEnd() TC = eva.out['x'] array2data(TC[len(TC) / 20:], dir_TC + '/TC_998_' + name) if not adressExists(dir_FC + '/FC_998_' + name): try: TC = array(TC) except: TC = data2array(dir_TC + '/TC_998_' + name) tic() FC = fPearsonCorrelation(TC) tac('h') array2data(FC, dir_FC + '/FC_998_' + name)