def _mk_weights()

in hype/graph_dataset.pyx [0:0]


    def _mk_weights(self, npc.ndarray[npc.long_t, ndim=2] idx, npc.ndarray[npc.double_t, ndim=1] weights):
        cdef int i
        cdef long t, h
        cdef set Tl, Th
        cdef npc.ndarray[npc.long_t, ndim=1] A
        cdef npc.ndarray[npc.double_t, ndim=1] S

        self._weights.resize(self.N)

        for i in range(idx.shape[0]):
            t = idx[i, 0]
            h = idx[i, 1]
            self.counts[h] += weights[i]
            self._weights[t][h] = weights[i]

        self.counts = self.counts ** self.sample_dampening

        if self.burnin:
            # Setup the necessary data structures for "Alias Method"
            # See Lua Torch impl: https://github.com/torch/torch7/blob/master/lib/TH/generic/THTensorRandom.c
            # Alias method: https://en.wikipedia.org/wiki/Alias_method
            S = (self.counts / np.sum(self.counts)) * self.counts.shape[0]
            A = np.arange(0, self.counts.shape[0], dtype=np.long)
            Tl = set(list((S < 1).nonzero()[0]))
            Th = set(list((S > 1).nonzero()[0]))

            while len(Tl) > 0 and len(Th) > 0:
                j = Tl.pop()
                k = Th.pop()
                S[k] = S[k] - 1 + S[j]
                A[j] = k
                if S[k] < 1:
                    Tl.add(k)
                elif S[k] > 1:
                    Th.add(k)
            self.S = S
            self.A = A