#print (random) #print (gvec) #gvec=np.zeros(len(sim_gains)) #gvec[0::2]=1. runs = 1 ''' runs=1 gvec=np.zeros((runs,2*Ndish)) for j in range(runs): for i in range(len(sim_gains)): gvec[j,i]=np.random.normal(0,.1,2*Ndish)[i]+sim_gains[i] #gvec=np.append(rand_gains.real,rand_gains.imag) ''' #print (gvec,'gvec') mat = corrcal2.sparse_2level(diag, vecs, src, 2 * lims) #init ''' mat_ones=mat*np.ones(len(data)) mycov=mat.copy() #copy, init app_gains=mycov.apply_gains_to_mat(gvec,ant1,ant2) #nothing #print (np.linalg.pinv(mycov*np.ones((len(data)/2,2))),'my own inv') mycov_inv=mycov.inv() #inv, copy, init #print (mycov_inv*np.ones((len(data),len(data))),'mycov_inv') sd=mycov_inv*data #ans because you're multiplying chisq=np.sum(sd*data) #nothing nn=gvec.size/2 #nothing #print (chisq) normfac=1. chisq=chisq+normfac*( (np.sum(gvec[1::2]))**2 + (np.sum(gvec[0::2])-nn)**2) #nothing print (chisq)
v[edges[i]:edges[i + 1]]) print edges[i], edges[i + 1], mystd v1 = numpy.zeros(2 * vis.size) v1[0::2] = 1 v2 = numpy.zeros(2 * vis.size) v2[1::2] = 1 vecs = numpy.vstack([v1, v2]) src = v1 * 10 big_noise = numpy.zeros(2 * noise.size) big_noise[0::2] = noise big_noise[1::2] = noise big_vis = numpy.zeros(2 * vis.size) big_vis[0::2] = numpy.real(vis) big_vis[1::2] = numpy.imag(vis) mycov = corrcal2.sparse_2level(big_noise, 100 * vecs, 500 * src, 2 * edges) guess = numpy.zeros(2 * len(ant1)) guess[0::2] = 1.0 fac = 1000.0 from scipy.optimize import fmin_cg gvec = numpy.zeros(2 * ant1.max() + 2) gvec[0::2] = 1.0 gvec = gvec + 0.1 * numpy.random.randn(gvec.size) gvec[0] = 1 gvec[1] = 0 asdf = fmin_cg(corrcal2.get_chisq, gvec * fac, corrcal2.get_gradient, (big_vis + 500 * src, mycov, ant1, ant2, fac))
for i in range(len(edges)-1): mystd=numpy.std(u[edges[i]:edges[i+1]])+numpy.std(v[edges[i]:edges[i+1]]) print edges[i],edges[i+1],mystd v1=numpy.zeros(2*vis.size) v1[0::2]=1 v2=numpy.zeros(2*vis.size) v2[1::2]=1 vecs=numpy.vstack([v1,v2]) src=v1*10 big_noise=numpy.zeros(2*noise.size) big_noise[0::2]=noise big_noise[1::2]=noise big_vis=numpy.zeros(2*vis.size) big_vis[0::2]=numpy.real(vis) big_vis[1::2]=numpy.imag(vis) mycov=corrcal2.sparse_2level(big_noise,100*vecs,500*src,2*edges) guess=numpy.zeros(2*len(ant1)) guess[0::2]=1.0 fac=1000.0 from scipy.optimize import fmin_cg gvec=numpy.zeros(2*ant1.max()+2) gvec[0::2]=1.0 gvec=gvec+0.1*numpy.random.randn(gvec.size) gvec[0]=1 gvec[1]=0 asdf=fmin_cg(corrcal2.get_chisq,gvec*fac,corrcal2.get_gradient,(big_vis+500*src,mycov,ant1,ant2,fac))
isinv=(numpy.fromfile(f,'int32',1)[0]!=0); nsrc=numpy.fromfile(f,'int32',1); nblock=numpy.fromfile(f,'int32',1); nvec=numpy.fromfile(f,'int32',1); lims=numpy.fromfile(f,'int32',(nblock+1)) diag=numpy.fromfile(f,'float64',n) vecs=numpy.fromfile(f,'float64',nvec*n) src=numpy.fromfile(f,'float64',nsrc*n) n=n[0] nsrc=nsrc[0] nvec=nvec[0] vecs=vecs.reshape([nvec,n]) if nsrc>0: src=src.reshape([nsrc,n]) mat=corrcal2.sparse_2level(diag,vecs,src,lims,isinv) f=open('ant1.dat');ant1=numpy.fromfile(f,'int64')-1;f.close() f=open('ant2.dat');ant2=numpy.fromfile(f,'int64')-1;f.close() f=open('gtmp.dat');gvec=numpy.fromfile(f,'float64');f.close() f=open('vis.dat');data=numpy.fromfile(f,'float64');f.close() niter=0; t_min=1e-4 t1=time.time() while (time.time()-t1)<t_min: grad=corrcal2.get_gradient(gvec,data,mat,ant1,ant2) niter=niter+1 t2=time.time() nant=gvec.size/2 #time per gradient print 'average time was ' + repr((time.time()-t1)/niter)