MCPcopy Index your code
hub / github.com/HobbitLong/PyContrast / draw

Method draw

pycontrast/memory/alias_multinomial.py:49–65  ·  view source on GitHub ↗

Draw N samples from multinomial :param N: number of samples :return: samples

(self, N)

Source from the content-addressed store, hash-verified

47 self.alias = self.alias.cuda()
48
49 def draw(self, N):
50 """
51 Draw N samples from multinomial
52 :param N: number of samples
53 :return: samples
54 """
55 K = self.alias.size(0)
56
57 kk = torch.zeros(N, dtype=torch.long, device=self.prob.device).random_(0, K)
58 prob = self.prob.index_select(0, kk)
59 alias = self.alias.index_select(0, kk)
60 # b is whether a random number is greater than q
61 b = torch.bernoulli(prob)
62 oq = kk.mul(b.long())
63 oj = alias.mul((1-b).long())
64
65 return oq + oj

Callers 2

forwardMethod · 0.80
forwardMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected