Exemplo n.º 1
0
    def get_HvM(self, ):

        # Read Meta
        Meta = ReadMeta(neuralfeaturesdir)
        DF_img = Meta.get_DF_img()
        DF_neu = Meta.get_DF_neu()
        times = Meta.get_times()

        # Read Neural data
        Data = ReadData(datadir, DF_neu)
        IT, V4 = Data.get_data()

        D = Mapping.get_Neu_trial_V36(IT[1:], [70, 170], times)
        image_indices = np.random.randint(low=0, high=D.shape[1], size=ni)
        D = D[:, image_indices, :]
        D = np.swapaxes(D, 0, 1)
        nf = D.shape[1]
        nt = D.shape[2]

        mu = np.zeros((self.nf, self.ni))
        sd = np.zeros((self.nf, self.ni))
        for f in range(self.nf):
            for i in range(self.ni):
                mu[f, i] = D[i, f, :].mean()
                sd[f, i] = D[i, f, :].std()
        hf = h5py.File(resultdir + 'HvM_stats.h5', 'w')
        hf.create_dataset('mu', data=mu)
        hf.create_dataset('sd', data=sd)
        hf.close()

        # #test synthetic as HvM
        # nf = 168
        # nt = 46
        # noise_dist = 'poisson'
        # sds = np.logspace(-1, 1, num=int(nf))
        # D = np.zeros((ni, nf, nt))
        # D_mean = np.random.rand(ni, nf)
        # for tr in range(nt):
        #     D[:, :, tr] = D_mean
        #
        # noise1 = np.zeros((ni, nf, int(nt * splitfract)))
        # noise2 = np.zeros((ni, nf, int(nt * splitfract)))
        # for i in range(ni):
        #     if noise_dist == 'normal':
        #         n = np.random.rand()
        #         noise1[i] = np.array([np.random.normal(0, sd + n, size=int(nt * splitfract)) for sd in sds])
        #         noise2[i] = np.array([np.random.normal(0, sd + n, size=int(nt * splitfract)) for sd in sds])
        #     elif noise_dist == 'poisson':
        #         n = np.random.rand()
        #         noise1[i] = np.array([np.random.poisson(sd + n, size=int(nt * splitfract)) for sd in sds])
        #         noise2[i] = np.array([np.random.poisson(sd + n, size=int(nt * splitfract)) for sd in sds])
        #
        #     D[:, :, :int(nt * splitfract)] = D[:, :, :int(nt * splitfract)] + noise1
        #     D[:, :, int(nt * splitfract):] = D[:, :, int(nt * splitfract):] + noise2

        # to test  HvM as syntheic
        # hf = h5py.File(resultdir+'D.h5', 'w')
        # hf.create_dataset('D', data=D)
        # hf.close()

        sds = []
        Collinearity = 'HvM'
        noise_dist = 'HvM'

        return D