Пример #1
0
    def mutual_information(self,
                           X,
                           Y,
                           title=None,
                           nbins_X=50,
                           nbins_Y=50,
                           noise_sigma='all'):
        #import pdb; pdb.set_trace()
        no_nans_idx = np.logical_not(np.logical_or(np.isnan(X), np.isnan(Y)))
        Xq, _, _ = pyentropy.quantise(X[no_nans_idx], nbins_X)
        Yq, _, _ = pyentropy.quantise(Y[no_nans_idx], nbins_Y)
        s = pyentropy.DiscreteSystem(Yq, (1, nbins_Y), Xq, (1, nbins_X))
        s.calculate_entropies()

        # MINE
        mine = MINE()
        mine.compute_score(X.flatten(), Y.flatten())

        # Linear regression
        slope, intercept, r, p, stderr = \
                scipy.stats.linregress(X[no_nans_idx], Y[no_nans_idx])

        #import pdb; pdb.set_trace()
        if title is not None:
            print(title)
        print(" MIC/MI/r^2/p/slope for %s:\t%.3f\t%.3f\t%s\t%s\t%s" %
              (noise_sigma, mine.mic(), s.I(), r**2, p, slope))
Пример #2
0
def calc_ent(var,sp,use_flags,nbins=100,sigma=5*pq.ms):

    b = elephant.conversion.binarize(sp,sampling_rate=pq.kHz)[:-1]
    K = elephant.kernels.GaussianKernel(sigma=sigma)
    r = elephant.statistics.instantaneous_rate(sp,sampling_period=pq.ms,kernel=K).magnitude
    idx = np.logical_and(use_flags.ravel(), np.isfinite(var).ravel())
    X = pye.quantise(var[idx],nbins,uniform='bins')[0].ravel()
    # Y = b[idx].astype('int').ravel()
    Y = r[idx].astype('int').ravel()

    S = pye.DiscreteSystem(X,(1,nbins),Y,(1,np.max(Y)+1))
    S.calculate_entropies(calc=['HX','HY','HXY','SiHXi','HiX','HshX','HiXY','HshXY','ChiX'])
    return(S.H['HX'],S.H['HXY'],S.I(),S)
    def getFitness(self, smMatrix):  #Store the sm state into memory
        fit = 0

        #Fitness function (4) ******************************************
        #Mutual Information between motor command and predicted sensory state.
        sp = smMatrix[1:, 3]
        mot = smMatrix[1:, 2]
        spQ = ent.quantise(sp, 10)
        motQ = ent.quantise(mot, 10)
        s = ent.DiscreteSystem(spQ[0], (1, 10), motQ[0], (1, 10))
        print(str(spQ[0]) + "\n" + str(motQ[0]))
        s.calculate_entropies(method='plugin', calc=['HX', 'HXY'])
        mutInf = s.I()
        fit = mutInf
        print(fit)
        return fit
Пример #4
0
def ent_analyses(blk, X_disc=128, Y_disc=64):
    CP = neoUtils.get_var(blk, 'CP')
    S = float(blk.annotations['s'][2:-1])
    CP /= S
    CP = CP.magnitude
    idx = np.all(np.isfinite(CP), axis=1)
    s = np.empty_like(CP)
    s[:] = np.nan
    s[idx, :] = pye.quantise(CP[idx, :], X_disc, uniform='bins')[0]
    FR = neoUtils.get_rate_b(blk, unit_num=unit_num, sigma=2 * pq.ms)[0]
    FR = pye.quantise(FR, Y_disc, uniform='bins')[0]

    idx = np.all(np.isfinite(s), axis=1)
    X = s.astype('int64').T[:, idx]
    Y = FR[np.newaxis, idx]
    DS = pye.DiscreteSystem(X, (X.shape[0], bins), Y, (1, bins))
    DS.calculate_entropies()

    #TODO: I have created a discrete FR and Stimulus, now I need to perform the actual entropy calcs
    if True:
        raise Exception('This is not done')
    def getFitnessH(self, smMatrix):  #Store the sm state into memory
        fit = 0

        #Fitness function (1) ******************************************
        #Mutual Information between two motors and the first prediced sensor dimension

        sp = smMatrix[1:, 2]  #Only predicts the first sensory outcome.
        mot1 = smMatrix[1:, 6]
        mot2 = smMatrix[1:, 7]
        spQ = ent.quantise(sp, 10)
        motQ1 = ent.quantise(mot1, 10)
        motQ2 = ent.quantise(mot2, 10)
        #          print(motQ1[0])
        #          print(motQ2[0])
        motQ = np.row_stack((motQ1[0], motQ2[0]))
        #          print(motQ)
        s = ent.DiscreteSystem(motQ, (2, 10), spQ[0], (1, 10))
        print(str(spQ[0]) + "\n" + str(motQ))
        s.calculate_entropies(method='pt', calc=['HX', 'HXY'])
        mutInf = s.I()
        fit = mutInf
        print(fit)
        return fit
Пример #6
0
            # drop burn in time
            x_in = x_in[times > drop_before]
            x_e = x_e[times > drop_before]

            # normalize
            x_in = norm(x_in)
            x_e = norm(x_e)

            # prep MI variables
            to_calc = ('HX', 'HY', 'HXY')
            q_in, _, _ = en.quantise(x_in, m)
            q_e, _, _ = en.quantise(x_e, m)

            # MI
            info = en.DiscreteSystem(q_in, (1, m), q_e, (1, m))
            info.calculate_entropies(method='pt', calc=to_calc)
            mi_no = info.I()

            # ---
            ys, layers, phi, rate, stim, params = run(None,
                                                      times,
                                                      pac,
                                                      sigma=s,
                                                      loc=loc,
                                                      stim_seed=j)

            idx = params.idx

            x_in = np.asarray([stim(t, 0) for t in times])
            x_e = ys[:, idx['r_E']].flatten()