Skip to content

Commit

Permalink
Merge pull request #534 from 2017pxy/master
Browse files Browse the repository at this point in the history
FIX: fix bugs in set_distribution in sampler.
  • Loading branch information
2017pxy authored Nov 23, 2020
2 parents 1f90a68 + 09fb2c9 commit c00e74f
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions recbole/sampler/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,24 @@ class AbstractSampler(object):
used_ids (numpy.ndarray): The result of :meth:`get_used_ids`.
"""
def __init__(self, distribution):
self.distribution = distribution
self.distribution = None
self.set_distribution(distribution)
self.used_ids = self.get_used_ids()

def set_distribution(self, distribution):
"""Set the distribution of sampler.
Args:
distribution (str): Distribution of the negative items.
"""
if self.distribution == distribution:
return
self.distribution = distribution
self.random_list = self.get_random_list()
random.shuffle(self.random_list)
self.random_pr = 0
self.random_list_length = len(self.random_list)

self.used_ids = self.get_used_ids()

def get_random_list(self):
"""
Returns:
Expand Down Expand Up @@ -155,12 +164,6 @@ def get_used_ids(self):
last = used_item_id[phase] = cur
return used_item_id

def set_distribution(self, distribution):
if self.distribution == distribution:
return
self.distribution = distribution
self.random_list = self.get_random_list()

def set_phase(self, phase):
"""Get the sampler of corresponding phase.
Expand Down Expand Up @@ -301,12 +304,6 @@ def get_random_list(self):
else:
raise NotImplementedError('Distribution [{}] has not been implemented'.format(self.distribution))

def set_distribution(self, distribution):
if self.distribution == distribution:
return
self.distribution = distribution
self.random_list = self.get_random_list()

def get_used_ids(self):
"""
Returns:
Expand Down

0 comments on commit c00e74f

Please sign in to comment.