示例#1
0
def pux_sampling(x, A, C, invC, sampleNr):
   h = size(x, 0)
   w = size(x, 1)
   s2 = 0.5; # sigma squared
   x = x.reshape(h*w)
   zarr = zeros(size(x))
   ident = identity(size(x))
   c = zeros(sampleNr)
   m = zeros((sampleNr, h*w))
   s = zeros((sampleNr, h*w, h*w))
   zsum = 0
   nsum = 0
   acat = dot(A, dot(C, A.T))
   ata = dot(A.T, A)
   for i in range(0, sampleNr):
      z = random.gammavariate(2,2)
      c[i] = multi_norm(x, zarr, s2*ident + z**2*acat)
      zsum += z*c[i]
      nsum += c[i]
      s[i] = linalg.inv(invC + z/s2*ata)
      m[i] = z/s2*dot(s[i]*A.T,x)
      
   c = c/sum(c); # normalization
   
   return [c, m, s, zsum/nsum]
示例#2
0
def pux_integration(x, sat, icorr, s, s2, start, end, pointNr):
   # see example usage in posterior_covariance.py
   # s[i] = linalg.inv(invC + z_a[i]/s2*ata)
   # icorr[i] = linalg.inv(s2*ident + z_a[i]**2*acat)
   # sat[i] = s[i]*A.T
   h = size(x, 0)
   w = size(x, 1)
   x = x.reshape(h*w)
   zarr = zeros(size(x))
   c = zeros(pointNr)
   m = zeros((pointNr, size(sat,1)))
   zsum = 0
   nsum = 0
   z_a = linspace(start, end, pointNr)
   g_dist = stats.gamma(2., loc = 0., scale = 2.)
   for i in range(0,pointNr):
      z = z_a[i]
      c[i] = g_dist.pdf(z)*multi_norm(x, zarr, icorr[i], inverted=True)
      zsum += z*c[i]
      nsum += c[i]
#      s[i] = linalg.inv(invC + z/s2*ata)
      m[i] = z/s2*dot(sat[i],x)
   print (sum(c))
   c = c/sum(c); # normalization
   
   return [c, m, zsum/nsum]