由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - weighted selection problem
相关主题
一个算法问题存储 n 个directed weighted graph进数据库
这里有人用过mokaFive么?和VMWare什么区别? (转载)这个问题有什么好的解法(或现成code)吗?
[合集] Returning heavy weight object in C++ function请教CNN中的convolution layer中每个kernel需要设计吗?
请教个算法问题help understanding code (random number)
web service refactor 工具求推荐Randomization of an array
怎样把“jackie chan"的字样去掉? (转载)Random Switch Between Two Different URLs
R已经是第六大语言了....ask a Javascript question
Weighted Graph Challenge 一道面试题程序员的前途
相关话题的讨论汇总
话题: 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版参与讨论
相关主题
程序员的前途web service refactor 工具求推荐
ask a C question about random number怎样把“jackie chan"的字样去掉? (转载)
How to generate random number in driver (build in DDK)R已经是第六大语言了....
help: generate random IP addressWeighted Graph Challenge 一道面试题
一个算法问题存储 n 个directed weighted graph进数据库
这里有人用过mokaFive么?和VMWare什么区别? (转载)这个问题有什么好的解法(或现成code)吗?
[合集] Returning heavy weight object in C++ function请教CNN中的convolution layer中每个kernel需要设计吗?
请教个算法问题help understanding code (random number)
相关话题的讨论汇总
话题: 25%话题: weighted话题: 30话题: selection话题: weights