Beispiel #1
0
def hmm_sample(h: HyperParams, params, rng: random.Generator):
    a0, a, b = map(partial(quantized_cdf_to_mass, h), params)
    xs = []
    for t in range(h.T):
        z = rng.choice(h.latent_K, p=a[z] if t else a0)
        xs.append(rng.choice(h.obs_K, p=b[z]))
    return np.array(xs)
Beispiel #2
0
 def iteration(self):
     i = randint(self.Lx)
     j = randint(self.Ly)
 
     en_old = self.energy_local(i,j)
     old_s = self.Spin[i,j]
     self.Spin[i,j] = (old_s + Generator.choice([1,2]) + 1)%3 -1
     en_new = self.energy_local(i,j)
     deltaE = en_new - en_old
 
     if deltaE > 0:
         p = np.exp(-deltaE)     
         if random.rand() > p :
             self.Spin[i,j] = old_s