probability

An variant of Knuth shuffle

瘦欲@ 提交于 2020-01-11 09:23:44
问题 This is a very hard but interesting probability question related to Knuth shuffle. When looping for each element, the swap is performed for the current element with any random element from the whole array (not within the elements left), then what is the probabilty of the original i th element ending up at the j th position? 回答1: The Knuth shuffle is as follows (in Python, but it could be pseudocode) for i in range(len(v)): swap(v, i, randrange(i, len(v)) The naïve shuffle is very similar, but

Generating a probability distribution

社会主义新天地 提交于 2020-01-09 09:24:05
问题 Given an array of size n I want to generate random probabilities for each index such that Sigma(a[0]..a[n-1])=1 One possible result might be: 0 1 2 3 4 0.15 0.2 0.18 0.22 0.25 Another perfectly legal result can be: 0 1 2 3 4 0.01 0.01 0.96 0.01 0.01 How can I generate these easily and quickly? Answers in any language are fine, Java preferred. 回答1: The task you are trying to accomplish is tantamount to drawing a random point from the N-dimensional unit simplex. http://en.wikipedia.org/wiki

How do I determine the bias of an algorithm?

僤鯓⒐⒋嵵緔 提交于 2020-01-07 01:28:40
问题 Let's say I have an algorithm that is supposed to represent a coin flip. How do I determine the bias of this coin? Specifically, I have written the algorithm in this JSFiddle. The fiddle runs a series of 20 tests. Each test flips the coin 100 times and tallies the results. At the end of the series it reports Heads/Tails for the total number of flips across all tests. This result seems to be approaching 1 (from both sides), but I have not done any rigorous testing of this. Note, this is not

How to control the probability of picking a number?

≡放荡痞女 提交于 2020-01-06 20:55:12
问题 I am building a game, I want to pick a random number between 0 to n , I want to make that picking a higher number will have lower chances. So I asked this question, and based on amit answer, I wrote this: public class Test { private static Random random = new Random(); public static void main(String[] ars) { int n = 30; float x = 5f; int[] results = new int[n]; for (float i = 1; i <= 10000; i++) { int choose = pickANumber(n, x); results[choose]++; } for (int i = 0; i < results.length; i++) {

MCMC Sampling a Maxwellian Curve Using Python's emcee

扶醉桌前 提交于 2020-01-05 04:59:17
问题 I am trying to introduce myself to MCMC sampling with emcee. I want to simply take a sample from a Maxwell Boltzmann distribution using a set of example code on github, https://github.com/dfm/emcee/blob/master/examples/quickstart.py. The example code is really excellent, but when I change the distribution from a Gaussian to a Maxwellian, I receive the error, TypeError: lnprob() takes exactly 2 arguments (3 given) However it is not called anywhere where it is not given the appropriate

Same probability for every hour in a loop with randomForest

大憨熊 提交于 2020-01-04 07:52:35
问题 I am predicting probabilities per hour for every observation with a random forest model. But for some reason the prediction for every hour within a observation is the same. This shouldn't be the case since the probability is different for every hour. I have masked some data for privacy reasons. heres a sample of my data, where ti is the hours variable: $ y : Factor w/ 2 levels "0","1": 1 2 1 1 2 2 1 2 2 1 ... $ geslacht : Factor w/ 2 levels "Dhr.","Mevr.": 2 2 1 1 1 2 1 1 2 2 ... $ ti :

c++ discrete distribution sampling with frequently changing probabilities

一笑奈何 提交于 2020-01-03 14:15:10
问题 Problem: I need to sample from a discrete distribution constructed of certain weights e.g. {w1,w2,w3,..}, and thus probability distribution {p1,p2,p3,...}, where pi=wi/(w1+w2+...). some of wi's change very frequently, but only a very low proportion of all wi's. But the distribution itself thus has to be renormalised every time it happens, and therefore I believe Alias method does not work efficiently because one would need to build the whole distribution from scratch every time. The method I

Ruby: Using rand() in code but writing tests to verify probabilities

天涯浪子 提交于 2020-01-03 08:50:14
问题 I have some code which delivers things based on weighted random. Things with more weight are more likely to be randomly chosen. Now being a good rubyist I of couse want to cover all this code with tests. And I want to test that things are getting fetched according the correct probabilities. So how do I test this? Creating tests for something that should be random make it very hard to compare actual vs expected. A few ideas I have, and why they wont work great: Stub Kernel.rand in my tests to

Ruby: Using rand() in code but writing tests to verify probabilities

余生长醉 提交于 2020-01-03 08:50:03
问题 I have some code which delivers things based on weighted random. Things with more weight are more likely to be randomly chosen. Now being a good rubyist I of couse want to cover all this code with tests. And I want to test that things are getting fetched according the correct probabilities. So how do I test this? Creating tests for something that should be random make it very hard to compare actual vs expected. A few ideas I have, and why they wont work great: Stub Kernel.rand in my tests to

Selecting nodes with probability proportional to trust

六眼飞鱼酱① 提交于 2020-01-02 09:38:51
问题 Does anyone know of an algorithm or data structure relating to selecting items, with a probability of them being selected proportional to some attached value? In other words: http://en.wikipedia.org/wiki/Sampling_%28statistics%29#Probability_proportional_to_size_sampling The context here is a decentralized reputation system and the attached value is therefore the value of trust one user has in another. In this system all nodes either start as friends which are completely trusted or unknowns