boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - weighted selection problem
相关主题
一个算法问题
这里有人用过mokaFive么?和VMWare什么区别? (转载)
[合集] Returning heavy weight object in C++ function
请教个算法问题
web service refactor 工具求推荐
怎样把“jackie chan"的字样去掉? (转载)
R已经是第六大语言了....
Weighted Graph Challenge 一道面试题
存储 n 个directed weighted graph进数据库
这个问题有什么好的解法(或现成code)吗?
相关话题的讨论汇总
话题: 25%话题: weighted话题: 30话题: selection话题: weights
进入Programming版参与讨论
1 (共1页)
w*****3
发帖数: 8
1
given an array, select an index based on their weights,
randomly, but proportional to the weights.
e.g.
(10,30) => (25%,75%)
(30,30,30,30) => (25%,25%,25%,25%)
k****u
发帖数: 133
2
what is your question?
X****r
发帖数: 3557
3
1. Calculate partial sum of the weights:
e.g. [10, 20, 30, 40] => [10, 30, 60, 100]
2. Generate a random number between 0 and the total weight,
(including 0 but not including the total weight),
For the above example, generate a random number in [0, 100),
let's say 56.
3. Search the array of partial sums to find the smallest
number than is greater than the random number. You can use
binary search. The index of this number is what you want.
For the above example, the number is 60, so weighted rand

【在 w*****3 的大作中提到】
: given an array, select an index based on their weights,
: randomly, but proportional to the weights.
: e.g.
: (10,30) => (25%,75%)
: (30,30,30,30) => (25%,25%,25%,25%)

1 (共1页)
进入Programming版参与讨论
相关主题
这个问题有什么好的解法(或现成code)吗?
请教CNN中的convolution layer中每个kernel需要设计吗?
help understanding code (random number)
Randomization of an array
Random Switch Between Two Different URLs
ask a Javascript question
程序员的前途
ask a C question about random number
How to generate random number in driver (build in DDK)
help: generate random IP address
相关话题的讨论汇总
话题: 25%话题: weighted话题: 30话题: selection话题: weights