Browse Source

Simplify weighted sequential strategy

pull/2261/head
Hironsan 1 year ago
parent
commit
41a254381f
1 changed files with 2 additions and 2 deletions
  1. 4
      backend/examples/assignment/strategies.py

4
backend/examples/assignment/strategies.py

@ -45,8 +45,8 @@ class WeightedSequentialStrategy(BaseStrategy):
def assign(self) -> List[Assignment]:
assignments = []
ratio = list(np.round(np.cumsum(self.weights) / 100 * self.dataset_size).astype(int))
ratio = [0] + ratio[:-1] + [self.dataset_size]
cumsum = np.cumsum([0] + self.weights)
ratio = np.round(cumsum / 100 * self.dataset_size).astype(int)
for user, (start, end) in enumerate(zip(ratio, ratio[1:])): # Todo: use itertools.pairwise
assignments.extend([Assignment(user=user, example=example) for example in range(start, end)])
return assignments

Loading…
Cancel
Save