MCPcopy Create free account
hub / github.com/DSL-Lab/GRBM / sampling

Method sampling

grbm.py:272–305  ·  view source on GitHub ↗
(self, v_init, num_steps=1, save_gap=1)

Source from the content-addressed store, hash-verified

270
271 @torch.no_grad()
272 def sampling(self, v_init, num_steps=1, save_gap=1):
273 v_shape = v_init.shape
274 v = v_init.view(v_shape[0], -1)
275 var = self.get_var()
276 var_mean = var.mean().item()
277
278 if self.inference_method == 'Gibbs':
279 samples = self.Gibbs_sampling_vh(v, num_steps=num_steps - 1)
280 samples = [xx[0] for xx in samples] # extract v
281 elif self.inference_method == 'Langevin':
282 samples = self.Langevin_sampling_v(v,
283 num_steps=num_steps - 1,
284 eta=self.Langevin_eta * var_mean,
285 is_anneal=self.is_anneal_Langevin,
286 adjust_step=self.Langevin_adjust_step)
287 elif self.inference_method == 'Gibbs-Langevin':
288 samples = self.Gibbs_Langevin_sampling_vh(
289 v,
290 num_steps=num_steps - 1,
291 num_steps_Langevin=self.Langevin_step,
292 eta=self.Langevin_eta * var_mean,
293 is_anneal=self.is_anneal_Langevin,
294 adjust_step=self.Langevin_adjust_step)
295 samples = [xx[0] for xx in samples] # extract v
296
297 # use conditional mean as the last sample
298 h = torch.bernoulli(self.prob_h_given_v(samples[-1], var))
299 mu = self.prob_v_given_h(h)
300 v_list = [(0, v_init)] + [(ii + 1, samples[ii].view(v_shape).detach())
301 for ii in range(num_steps - 1)
302 if (ii + 1) % save_gap == 0
303 ] + [(num_steps, mu.view(v_shape).detach())]
304
305 return v_list
306
307 @torch.no_grad()
308 def positive_grad(self, v):

Callers

nothing calls this directly

Calls 6

get_varMethod · 0.95
Gibbs_sampling_vhMethod · 0.95
Langevin_sampling_vMethod · 0.95
prob_h_given_vMethod · 0.95
prob_v_given_hMethod · 0.95

Tested by

no test coverage detected