def objective_U(): targets = { 'f':quadratic_Poisson, 'barrier':eig_barrier } targets = kolia_theano.reparameterize(targets,UVs(NRGC)) list_targets= kolia_theano.reparameterize({'eigsM':eigsM, 'invM':invM },UVs(NRGC), reducer=lambda r,x: r + [x], zero=[]) targets.update( list_targets ) return kolia_theano.Objective( init_params={'U': U }, differentiate=['f'], **targets )
def objective_UV1(): targets = { 'f':quadratic_Poisson, 'barrier':eig_pos_barrier } targets = kolia_theano.reparameterize(targets,UVs(NRGC)) return kolia_theano.Objective( init_params={'V1': R['V'] , 'U': R['U'] }, differentiate=['f'], mode='FAST_RUN' , **targets )
(N_spikes,STA,STC), U, V1, bbar, Cb , STAB = simulate_data.LNLNP(NL=NL,N=24) Nsub, Ncone = U.shape NRGC, Nsub = V1.shape def callback( objective , params ): print 'Objective: ' , objective.f(params) , ' barrier: ', objective.barrier(params) true = {'U' : U , 'V1': V1 } data = {'STAs':np.vstack(STA) , 'STCs':np.vstack([stc[np.newaxis,:] for stc in STC]), 'V2':V2*np.ones(Nsub) , 'N':NRGC } targets = { 'f':quadratic_Poisson, 'barrier':eig_barrier } targets = kolia_theano.reparameterize(targets,UVs(NRGC)) objective = kolia_theano.Objective( init_params=true, differentiate=['f'], callback=callback, **targets ) optimizer = optimize.optimizer( objective.where(**data) ) trupar = true for i in range(2): trupar = optimizer(init_params=trupar) trupar = objective.unflat(trupar) init_params = {'U' : 0.0001+0.05*R.random(size=U.shape ) , 'V1': 0.0001+0.05*R.random(size=V1.shape) }