def FALMopt( objective , u, v2 , mus=np.array([30.,3.,0.3])): #mus=np.array([0.1,1.,10.])): # lambdas = np.zeros(v2.size) data = {'STAs':np.vstack(R['statistics']['stimulus']['STA']) , 'STCs':np.vstack([stc[np.newaxis,:] for stc in R['statistics']['stimulus']['STC']]), 'V2':v2 , 'U': u , 'N':NRGC , 'N_spikes':R['N_spikes'] , 'Ncones':Ncones , 'centers':centers , 'indices':indices , 'lam':lam , 'lambdas':lambdas } obj_V1 = objective.where(**data).with_callback(callback) optimize_L2 = FALMS.add_L2_term( obj_V1 , gtol=1e-3 ) init = (0.001 + 0.01 * Rand.rand(NRGC,u.shape[0])).flatten() r = {} def falms_callback(falmer): print ' L0: ', falmer[1][falmer[1]<>0].shape[0] for mu in mus: print print print 'mu: ', mu reg_L1 = FALMS.L1_L2( mu ) params = FALMS.falms(init,optimize_L2,reg_L1,mu=0.01,ftol=2e-7,callback=falms_callback) r[mu] = params print [ (mu,par['M'][par['M']<>0].shape[0]) for mu,par in sorted(r.items())] return r
projected_params = MaxLike(projected_init_params,projected_data) r['projected_ML'] = [{'theta': np.dot(q['theta'],T) , \ 'M':np.dot(np.dot(np.transpose(T),q['M']),T)} for q in projected_params] reinjected_A = np.concatenate([np.concatenate([np.array([q['theta']]),q['M']]) \ for q in r['projected_ML']]) reinjected_UA,reinjected_SA,reinjected_VA = svd(reinjected_A) save() for i,params in enumerate(init_params): for rho in np.array([0.001,0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.1,0.25,0.5,1.]): print print print 'RHO: ', rho, ' RGC ', i reg_L1 = FALMS.L1_L2( rho ) params = FALMS.falms(params,optimize_L2,reg_L1,ftol=2e-7,callback=falms_callback) r['L1'][i][rho] = params print [ (rh,par['M'][par['M']<>0].shape[0]) for rh,par in sorted(r['L1'][i].items())] save() plot_vectors([[q['theta'] for q in r['true'] ], [q['theta'] for q in r['ML'] ], \ [q['theta'] for q in r['analytical']], [q['theta'] for q in r['projected_ML']]]) plot_matrices([r['true'][0]['M'], r['ML'][0]['M'], r['analytical'][0]['M'], r['projected_ML'][0]['M']]) plot_projection_of_U( onto = np.transpose(reinjected_VA[0:Nsub,:]), name='svd(theta,M)', figure=5) plot_projection_of_U( onto = np.transpose( VI[0:Nsub,:]), name='svd(STA,STC)', figure=6)