Uniform

random unit vector in multi-dimensional space

六月ゝ 毕业季﹏ 提交于 2019-11-29 01:16:19
I'm working on a data mining algorithm where i want to pick a random direction from a particular point in the feature space. If I pick a random number for each of the n dimensions from [-1,1] and then normalize the vector to a length of 1 will I get an even distribution across all possible directions? I'm speaking only theoretically here since computer generated random numbers are not actually random. Bram Cohen One simple trick is to select each dimension from a gaussian distribution, then normalize: from random import gauss def make_rand_vector(dims): vec = [gauss(0, 1) for i in range(dims)]

jQuery Uniform Checkbox does not (un)check

你说的曾经没有我的故事 提交于 2019-11-28 19:10:30
I am using jQuery Uniform to style inputs/selects etcs. However, the checkbox has stopped working. I am appending data sent from an ajax call. Once it's loaded, I use $.uniform.update("input:checkbox") to update the new html. When attempting to (un)check the input it works only once. If I want to (un)check it again, it doesn't change at all. I've attempted changing the Uniform Javascript so that all the actions (ie. click , focus , blur etc) are under the .live function. (ie. .live("click", ). This just stops anything from working. Update: I've read through the Uniform JS entirely and

Uniformity of random numbers taken modulo N

ぃ、小莉子 提交于 2019-11-27 15:32:17
One common way of choosing a random number in [0, n) is to take the result of rand() modulo n : rand() % n . However, even if the results returned by the available rand() implementation are fully uniform, shouldn't there be a problem with the uniformity of the resulting [0, n) numbers when RAND_MAX + 1 does not divide evenly by n ? E.g. suppose RAND_MAX is 2, and n is 2. Then out of 3 possible rand() outputs: 0, 1 and 2, we get 0, 1 and 0 respectively when we use them modulo n . Therefore the output will not be uniform at all. Is this a real problem in practice? What is a better way of

Generating a uniform distribution of INTEGERS in C

为君一笑 提交于 2019-11-27 07:54:45
I've written a C function that I think selects integers from a uniform distribution with range [rangeLow, rangeHigh], inclusive. This isn't homework--I'm just using this in some embedded systems tinkering that I'm doing for fun. In my test cases, this code appears to produce an appropriate distribution. I'm not feeling fully confident that the implementation is correct, though. Could someone do a sanity check and let me know if I've done anything wrong here? //uniform_distribution returns an INTEGER in [rangeLow, rangeHigh], inclusive. int uniform_distribution(int rangeLow, int rangeHigh) {

What is the optimal algorithm for generating an unbiased random integer within a range?

亡梦爱人 提交于 2019-11-26 20:47:14
In this StackOverflow question: Generating random integer from a range the accepted answer suggests the following formula for generating a random integer in between given min and max , with min and max being included into the range: output = min + (rand() % (int)(max - min + 1)) But it also says that This is still slightly biased towards lower numbers ... It's also possible to extend it so that it removes the bias. But it doesn't explain why it's biased towards lower numbers or how to remove the bias. So, the question is: is this the most optimal approach to generation of a random integer

Uniformity of random numbers taken modulo N

半世苍凉 提交于 2019-11-26 17:00:18
问题 One common way of choosing a random number in [0, n) is to take the result of rand() modulo n : rand() % n . However, even if the results returned by the available rand() implementation are fully uniform, shouldn't there be a problem with the uniformity of the resulting [0, n) numbers when RAND_MAX + 1 does not divide evenly by n ? E.g. suppose RAND_MAX is 2, and n is 2. Then out of 3 possible rand() outputs: 0, 1 and 2, we get 0, 1 and 0 respectively when we use them modulo n . Therefore the

Generating a uniform distribution of INTEGERS in C

醉酒当歌 提交于 2019-11-26 13:54:10
问题 I've written a C function that I think selects integers from a uniform distribution with range [rangeLow, rangeHigh], inclusive. This isn't homework--I'm just using this in some embedded systems tinkering that I'm doing for fun. In my test cases, this code appears to produce an appropriate distribution. I'm not feeling fully confident that the implementation is correct, though. Could someone do a sanity check and let me know if I've done anything wrong here? //uniform_distribution returns an

What is the optimal algorithm for generating an unbiased random integer within a range?

半城伤御伤魂 提交于 2019-11-26 07:45:34
问题 In this StackOverflow question: Generating random integer from a range the accepted answer suggests the following formula for generating a random integer in between given min and max , with min and max being included into the range: output = min + (rand() % (int)(max - min + 1)) But it also says that This is still slightly biased towards lower numbers ... It\'s also possible to extend it so that it removes the bias. But it doesn\'t explain why it\'s biased towards lower numbers or how to

Evenly distributing n points on a sphere

给你一囗甜甜゛ 提交于 2019-11-26 03:24:24
问题 I need an algorithm that can give me positions around a sphere for N points (less than 20, probably) that vaguely spreads them out. There\'s no need for \"perfection\", but I just need it so none of them are bunched together. This question provided good code, but I couldn\'t find a way to make this uniform, as this seemed 100% randomized. This blog post recommended had two ways allowing input of number of points on the sphere, but the Saff and Kuijlaars algorithm is exactly in psuedocode I