19efebad71288796c490f7dfcc4092afee646611,stellargraph/data/explorer.py,,naive_weighted_choices,#Any#Any#,295
Before Change
// divide the interval [0, sum(weights)) into len(weights)
// subintervals [x_i, x_{i+1}), where the width x_{i+1} - x_i ==
// weights[i]
subinterval_ends = []
running_total = 0
for w in weights:
if w < 0:
raise ValueError("Detected negative weight: {}".format(w))
running_total += w
subinterval_ends.append(running_total)
// pick a place in the overall interval
x = rs.random() * running_total
// find the subinterval that contains the place, by looking for the
// first subinterval where the end is (strictly) after it
After Change
requires a lot of preprocessing (normalized probabilties), and
does a lot of conversions/checks/preprocessing internally.
probs = np.cumsum(weights)
idx = np.searchsorted(probs, rs.random() * probs[-1], side="left")
return idx
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 7
Instances
Project Name: stellargraph/stellargraph
Commit Name: 19efebad71288796c490f7dfcc4092afee646611
Time: 2020-05-27
Author: kieranricardo@hotmail.com
File Name: stellargraph/data/explorer.py
Class Name:
Method Name: naive_weighted_choices
Project Name: ContextLab/hypertools
Commit Name: ab4c3743ec1c77d67ddede9fb400b55b3778e39b
Time: 2016-12-17
Author: andrew.heusser@gmail.com
File Name: python/hypertools/reduce.py
Class Name:
Method Name: reducePCA
Project Name: ContextLab/hypertools
Commit Name: 1430ab58648b4bd189f232ae2acc8b86ce2fd9aa
Time: 2016-12-17
Author: andrew.heusser@gmail.com
File Name: python/hypertools/reduce.py
Class Name:
Method Name: reducePCA