Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from numpy.random import randn
- from numpy import sqrt,row_stack,array,dot,transpose,sum,zeros,inner,zeros,mean,float32
- def GMMGaussianMC(N=100):
- T=100;mu=0.1;sigma=0.2
- invT = 1./T
- coverage=zeros((2,N),dtype=int)
- d = array([[-1,0],[0,0]],dtype=float32)
- xmat = mu + sigma*randn(T,N)
- muhats = invT * sum(xmat, axis=0)
- f1s = xmat - muhats
- sigma_hats = sqrt(invT * sum(f1s**2,axis=0))
- f2s = f1s**2 - sigma_hats**2
- f = row_stack((f1s,f2s))
- for n in xrange(0,N-1):
- #d is now inv(d) as it is easy to compute
- d[1,1] = (-2*sigma_hats[n])
- temp = f[:,n].reshape(2,T)
- S=invT*inner(temp,temp)
- V=dot(dot(d,S),d)
- SE_mu = sqrt(invT*V[0,0])
- SE_sigma = sqrt(invT*V[1,1])
- coverage[0,n]=(abs(muhats[n]-mu)<1.96*SE_mu)
- coverage[1,n]=(abs(sigma_hats[n]-sigma)<1.96*SE_sigma)
- y=mean(coverage,axis=1)
- return y
- if __name__=='__main__':
- #import cProfile
- #cProfile.run('GMMGaussianMC(100000)','prof_jason.dat')
- import time
- t1=time.time()
- y=GMMGaussianMC(100000)
- print time.time()-t1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement