probability

How do I simulate biased die in python?

拈花ヽ惹草 提交于 2019-11-29 18:44:58
问题 I want to simulate N-sided biased die? def roll(N,bias): '''this function rolls N dimensional die with biasing provided''' # do something return result >> N=6 >> bias=( 0.20,0.20,0.15,0.15,0.14,0.16,) >> roll(N,bias) 2 回答1: A little bit of math here. A regular die will give each number 1-6 with equal probability, namely 1/6 . This is referred to as uniform distribution (the discrete version of it, as opposed to the continuous version). Meaning that if X is a random variable describing the

Determine all combinations of flipping a coin without using “itertools.product”

为君一笑 提交于 2019-11-29 17:46:00
I went through similar posts on the forum but all of them suggest using itertools.product but I was wondering if it can be solved without using it. I want to print all the combinations of outcomes for N flips of a coin. This can be done if N is known in advance. So the number of nested loops will be just N. But if N has to be determined dynamically ( input() function) then I am stuck in implementing it in code. In plain English it is easy to imagine that the number of for loops is proportional to N, but how do I implement it? Do I have to use lambdas or recursion? Below is as example code for

Generating random integers within range with a probability distribution

好久不见. 提交于 2019-11-29 14:42:00
问题 I have a problem where I want to generate a set of random integer values between 1 and 5 inclusive using a probability distribution. Poisson and Inverse Gamma are two distributions that show the characteristics I am after (majority at mean, less higher numbers) that I have found. I am looking at using Apache Commons Math but I wasn't sure how to generate the numbers I wanted using the distributions available. 回答1: From your problem description, it sounds like you actually want a sample

Efficiently determining the probability of a user clicking a hyperlink

China☆狼群 提交于 2019-11-29 12:57:24
So I have a bunch of hyperlinks on a web page. From past observation I know the probabilities that a user will click on each of these hyperlinks. I can therefore calculate the mean and standard deviation of these probabilities. I now add a new hyperlink to this page. After a short amount of testing I find that of the 20 users that see this hyperlink, 5 click on it. Taking into account the known mean and standard deviation of the click-through probabilities on other hyperlinks (this forms a "prior expectation"), how can I efficiently estimate the probability of a user clicking on the new

Weighted random selection using Walker's Alias Method

旧巷老猫 提交于 2019-11-29 11:29:56
I was looking for this algorithm (algorithm which will randomly select from a list of elements where each element has different probability of being picked (weight) ) and found only python and c implementations, after I did a C# one, a bit different (but I think simpler) I thought I should share it, also I need an F# imlementation , if anyone can make it please post an answer using System; using System.Collections.Generic; using System.Linq; namespace ChuckNorris { class Program { static void Main(string[] args) { var oo = new Dictionary<string, int> { {"A",7}, {"B",1}, {"C",9}, {"D",8}, {"E"

Create constrained random numbers?

こ雲淡風輕ζ 提交于 2019-11-29 11:03:47
CLEANED UP TEXT: How can I create m=5 random numbers that add upp to, say n=100. But, the first random number is say, 10 < x1 < 30, the second random nr is 5 < x2 < 20, the third random nr is 10 < x3 < 25, etc. So these five random numbers add up to 100. How can I create these constrained five numbers? . [[ Related problem A1): The standard way to create five random numbers that add up to 100, is to sample four numbers between [0,100], and add the boundaries 0 and 100, and then sort these six numbers [0,x1,x2,x3,x4,100]. The five random numbers I seek, are the deltas. That is, 100 - x[4] =

Select x random elements from a weighted list in C# (without replacement)

▼魔方 西西 提交于 2019-11-29 10:43:56
Update : my problem has been solved, I updated the code source in my question to match with Jason's answer. Note that rikitikitik answer is solving the issue of picking cards from a sample with replacement. I want to select x random elements from a weighted list. The sampling is without replacement. I found this answer: https://stackoverflow.com/a/2149533/57369 with an implementation in Python. I implemented it in C# and tested it. But the results (as described below) were not matching what I expected. I've no knowledge of Python so I'm quite sure I made a mistake while porting the code to C#

Generate a uniformly random point within an annulus (ring) [duplicate]

冷暖自知 提交于 2019-11-29 09:41:43
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Create random number within an annulus I would like to obtain a uniformly obtained random point within an annulus, that is, the area that lies inside a circle of radius R1 , but outside a circle of radius R2 , where R1 > R2 and both circles are centered at the same point. I would like to avoid using rejection sampling. If possible, I would like the solution to be similar to this one —used for calculating random

Plot weighted frequency matrix

痞子三分冷 提交于 2019-11-29 09:24:18
This question is related to two different questions I have asked previously: 1) Reproduce frequency matrix plot 2) Add 95% confidence limits to cumulative plot I wish to reproduce this plot in R: I have got this far, using the code beneath the graphic: #Set the number of bets and number of trials and % lines numbet <- 36 numtri <- 1000 #Fill a matrix where the rows are the cumulative bets and the columns are the trials xcum <- matrix(NA, nrow=numbet, ncol=numtri) for (i in 1:numtri) { x <- sample(c(0,1), numbet, prob=c(5/6,1/6), replace = TRUE) xcum[,i] <- cumsum(x)/(1:numbet) } #Plot the

How to simulate bimodal distribution?

我怕爱的太早我们不能终老 提交于 2019-11-29 09:08:43
I have the following code to generate bimodal distribution but when I graph the histogram. I don't see the 2 modes. I am wondering if there's something wrong with my code. mu1 <- log(1) mu2 <- log(10) sig1 <- log(3) sig2 <- log(3) cpct <- 0.4 bimodalDistFunc <- function (n,cpct, mu1, mu2, sig1, sig2) { y0 <- rlnorm(n,mean=mu1, sd = sig1) y1 <- rlnorm(n,mean=mu2, sd = sig2) flag <- rbinom(n,size=1,prob=cpct) y <- y0*(1 - flag) + y1*flag } bimodalData <- bimodalDistFunc(n=100,cpct,mu1,mu2, sig1,sig2) hist(log(bimodalData)) The problem seems to be just too small n and too small difference between