Exemplo n.º 1
0
    def __init__(self, num_subfunctions_ratio=0.05):
        self.name = 'GLM'

        print('Initializing parameters...')
        #self.params = glm.setParameters(m=5000, dh=10, ds=50) # small
        self.params = glm.setParameters(m=5000, dh=10, ds=49) # small
        #self.params = glm.setParameters(m=20000, dh=100, ds=500) # large
        #self.params = glm.setParameters(m=20000, dh=25, ds=256, n=5) # huge
        #self.params = glm.setParameters(m=1e5, dh=10, ds=256, n=50) # Jascha huge
        #self.params = glm.setParameters(m=1e5, n=100, ds=256, dh=10) # shared

        ## initialize parameters
        print('Generating model...')
        self.theta_true = glm.generateModel(self.params)
        self.theta_init = glm.generateModel(self.params)
        for key in self.theta_init.keys():
            self.theta_init[key] /= 1e3

        print('Simulating model to generate data...')
        self.data = glm.generateData(self.theta_true, self.params)
        batch_size = self.data['x'].shape[0]

        trueMinimum, trueGrad = self.f_df(self.theta_true, (0, batch_size))
        print('Minimum for true parameters %g'%(trueMinimum))

        print('Norm of the gradient at the minimum:')
        for key in trueGrad.keys():
            print('grad[' + key + ']: %g'%(np.linalg.norm(trueGrad[key])))

        # print out some network information
        glm.visualizeNetwork(self.theta_true, self.params, self.data)

        # break the data up into minibatches

        self.N = int(np.ceil(np.sqrt(batch_size)*num_subfunctions_ratio))
        self.subfunction_references = []
        samples_per_subfunction = int(np.floor(batch_size/self.N))
        for mb in range(self.N):
            start_idx = mb*samples_per_subfunction
            end_idx = (mb+1)*samples_per_subfunction
            self.subfunction_references.append((start_idx, end_idx,))

        self.full_objective_references = self.subfunction_references
    def __init__(self, num_subfunctions_ratio=0.05, baseDir='/home/nirum/data/retina/glm-feb-19/'):
    #def __init__(self, num_subfunctions_ratio=0.05, baseDir='/home/nirum/data/retina/glm-feb-19/small'):
        self.name = 'GLM'

        print('Initializing parameters...')

        ## FOR CUSTOM SIZES
        #self.params = glm.setParameters(m=5000, dh=10, ds=50) # small
        #self.params = glm.setParameters(m=5000, dh=10, ds=49) # small
        #self.params = glm.setParameters(m=20000, dh=100, ds=500) # large
        #self.params = glm.setParameters(m=20000, dh=25, ds=256, n=5) # huge
        #self.params = glm.setParameters(m=1e5, dh=10, ds=256, n=50) # Jascha huge
        #self.params = glm.setParameters(m=1e5, n=100, ds=256, dh=10) # shared

        ## FROM EXTERNAL DATA FILES
        # load sizes of external data
        shapes = np.load(join(baseDir, 'metadata.npz'))

        # set up GLM parameters
        self.params = glm.setParameters(dh=40, ds=shapes['stimSlicedShape'][1], n=shapes['rateShape'][1])
        #self.params = glm.setParameters(dh=40, ds=shapes['stimSlicedShape'][1], n=2)

        ## initialize parameters
        print('Generating model...')
        #self.theta_true = glm.generateModel(self.params)
        self.theta_init = glm.generateModel(self.params)
        for key in self.theta_init.keys():
            self.theta_init[key] /= 1e3

        #print('Simulating model to generate data...')
        #self.data = glm.generateData(self.theta_true, self.params)

        # load external data files as memmapped arrays
        print('Loading external data...')
        self.data = glm.loadExternalData('stimulus_sliced.dat', 'rates.dat', shapes, baseDir=baseDir)

        # all the data
        batch_size = self.data['x'].shape[0]
        #batch_size = 10000

        print('ready to go!')

        #trueMinimum, trueGrad = self.f_df(self.theta_true, (0, batch_size))
        #print('Minimum for true parameters %g'%(trueMinimum))

        #print('Norm of the gradient at the minimum:')
        #for key in trueGrad.keys():
            #print('grad[' + key + ']: %g'%(np.linalg.norm(trueGrad[key])))

        # print out some network information
        #glm.visualizeNetwork(self.theta_true, self.params, self.data)

        # break the data up into minibatches

        self.N = int(np.ceil(np.sqrt(batch_size)*num_subfunctions_ratio))
        self.subfunction_references = []
        samples_per_subfunction = int(np.floor(batch_size/self.N))
        for mb in range(self.N):
            print(mb, self.N)
            start_idx = mb*samples_per_subfunction
            end_idx = (mb+1)*samples_per_subfunction
            self.subfunction_references.append((start_idx, end_idx,))

        self.full_objective_references = self.subfunction_references
        print('initialized ...')
Exemplo n.º 3
0
    def __init__(self,
                 num_subfunctions_ratio=0.05,
                 baseDir='/home/nirum/data/retina/glm-feb-19/'):
        #def __init__(self, num_subfunctions_ratio=0.05, baseDir='/home/nirum/data/retina/glm-feb-19/small'):
        self.name = 'GLM'

        print('Initializing parameters...')

        ## FOR CUSTOM SIZES
        #self.params = glm.setParameters(m=5000, dh=10, ds=50) # small
        #self.params = glm.setParameters(m=5000, dh=10, ds=49) # small
        #self.params = glm.setParameters(m=20000, dh=100, ds=500) # large
        #self.params = glm.setParameters(m=20000, dh=25, ds=256, n=5) # huge
        #self.params = glm.setParameters(m=1e5, dh=10, ds=256, n=50) # Jascha huge
        #self.params = glm.setParameters(m=1e5, n=100, ds=256, dh=10) # shared

        ## FROM EXTERNAL DATA FILES
        # load sizes of external data
        shapes = np.load(join(baseDir, 'metadata.npz'))

        # set up GLM parameters
        self.params = glm.setParameters(dh=40,
                                        ds=shapes['stimSlicedShape'][1],
                                        n=shapes['rateShape'][1])
        #self.params = glm.setParameters(dh=40, ds=shapes['stimSlicedShape'][1], n=2)

        ## initialize parameters
        print('Generating model...')
        #self.theta_true = glm.generateModel(self.params)
        self.theta_init = glm.generateModel(self.params)
        for key in self.theta_init.keys():
            self.theta_init[key] /= 1e3

        #print('Simulating model to generate data...')
        #self.data = glm.generateData(self.theta_true, self.params)

        # load external data files as memmapped arrays
        print('Loading external data...')
        self.data = glm.loadExternalData('stimulus_sliced.dat',
                                         'rates.dat',
                                         shapes,
                                         baseDir=baseDir)

        # all the data
        batch_size = self.data['x'].shape[0]
        #batch_size = 10000

        print('ready to go!')

        #trueMinimum, trueGrad = self.f_df(self.theta_true, (0, batch_size))
        #print('Minimum for true parameters %g'%(trueMinimum))

        #print('Norm of the gradient at the minimum:')
        #for key in trueGrad.keys():
        #print('grad[' + key + ']: %g'%(np.linalg.norm(trueGrad[key])))

        # print out some network information
        #glm.visualizeNetwork(self.theta_true, self.params, self.data)

        # break the data up into minibatches

        self.N = int(np.ceil(np.sqrt(batch_size) * num_subfunctions_ratio))
        self.subfunction_references = []
        samples_per_subfunction = int(np.floor(batch_size / self.N))
        for mb in range(self.N):
            print(mb, self.N)
            start_idx = mb * samples_per_subfunction
            end_idx = (mb + 1) * samples_per_subfunction
            self.subfunction_references.append((
                start_idx,
                end_idx,
            ))

        self.full_objective_references = self.subfunction_references
        print('initialized ...')