Beispiel #1
0
 def load(_, transp=False, slices=slice(None), mmap_mode=None, sprint=True, **kwa):
     '''Load files to a dictionnary.
     mmap_mode='r' for memory access.
     '''
     items = _.find(subk=['adress'], **kwa)
     mats, titles = [], []
     for k in sorted(items.keys()):
         if slices != None:
             tmp = array(data2array(items[k]['adress'], mmap_mode='r')[slices])
         else:
             tmp = data2array(items[k]['adress'], mmap_mode=mmap_mode)
         
         try:    _[k]['shape']
         except: _[k]['shape'] = tmp.shape
             
         if transp: mats.append(tmp.T)
         else:      mats.append(tmp)
             
         titles.append( k )  
         
     nruter = {}
     for k in range(len(mats)):
         nruter[titles[k]] = mats[k]
         
     if sprint: print _.size(items)
     return nruter
Beispiel #2
0
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])
Beispiel #3
0
 def display(_, titles=None, dispOpt={}, transp=False, sGM=False, **kwa):
     '''Display from finding function using display tools.
     Profites of the loading function to add the files shape in the database.
     '''
     from Tools.display import mapMatrices
     items = _.find(**kwa)
     mats = []
     if titles == None:
         titles = []
         upti = True
     else:
         upti = False
         
     for k in sorted(items.keys()):
         tmp = data2array(items[k]['adress'])
         
         try:    _[k]['shape']
         except: _[k]['shape'] = tmp.shape
         if sGM:
             tmp -= tmp.mean()
             
         if transp: mats.append(tmp.T)
         else:      mats.append(tmp)
         
         if upti:
             titles.append( items[k]['name'] )  
     if upti:
         titles = dimTitles(titles)
         
     mapMatrices(mats, lTitl= titles, **dispOpt)
Beispiel #4
0
 def __init__(_, new=False, size=False, dir=defaultDir):
     _.dir = dir
     if not new:
         from Tools.ext import data2array
         _.update(data2array(_.dir, dic=True))
         #_.delete(adress=['CFSS','Norm'])
         if size: 
             print _.size()
Beispiel #5
0
dir1S = main + '/Cand_S/'
dir1X = main + '/Cand_X/'
dir2S = main + typ2 + '/Cand_S/'
dir2X = main + typ2 + '/Cand_X/'
mkdir(dir2S)
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)
Beispiel #6
0
# **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)
    
    
Beispiel #7
0
        'tauT': 80,
        'P': 0.86,
        'G': 900.
    }

    out = ['x', 'A']

    other = {'init': 'ext', 'rperiod': 100}

    dir_ = '../SearchForPatt/SG_900_pC/Cand_S'
    pars = findParameters(dir_)
    ksix = zeros((0, 998))
    ksiA = zeros((0, 998))
    for f0 in pars['f0']:
        pattAd = dir_ + '/patterns_P_0.86_f0_%.2f.npy' % f0
        kx = data2array(pattAd.replace('Cand_S', 'Cand_X'))
        kA = data2array(pattAd.replace('Cand_X', 'Cand_S'))
        ksix = concatenate((ksix, kx))
        ksiA = concatenate((ksiA, kA))
    T0 = 20000  # 0.1 ms
    TF = 80000  # 0.1 ms
    sx = 0.2
    sT = 0.2
    x, A = [], []

    ############################################################################################'
    # **Loop**
    tic()
    for iii in range(100):
        # Init
        m = randint(ksix.shape[0])
Beispiel #8
0
        '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)
Beispiel #9
0
        del sys.argv[1]
    else:
        print 'Options invalides :', option, '->', sys.argv[0]

dir_priA = './%s/Cand_S' % di
dir_prix = './%s/Cand_X' % di
mkdir(dir_priA)
mkdir(dir_prix)
dir_sub = '/patterns_P_%.2f_f0_%.2f.npy' % (p1, p2)
#dir_sub = '/patterns_P_%.2f_G_%.2f.npy' %(p1,p2)

############################################################################################'
# **Main**
if not os.path.exists(dir_prix + dir_sub):
    multi_dens = arange(0.02, 0.981, 0.03)  # (33)
    N = data2array(co).shape[0]
    all_pattx = zeros((3300, N))
    all_pattA = zeros((3300, N))

    conn = {
        'connAd': co,  #Pdir('Connectomes/p05-pg-epi_1.txt'),
        'normType': '1'
    }

    noise = {'colors': None}

    model = {
        'model': 'HopfieldBasedStatic',
        'threshold': 'local',
        'tauT': 0,
        'P': p1,