probability

Uniform distribution in a small range to generate precise big probability

旧时模样 提交于 2019-12-13 04:30:45
问题 Currently I'm using a uniform distribution to generate a winning probability. For a probability of let's say 1% I define a winning number 47 then I do a mt_rand(1,100) and if the number is 47 the user win. Which is fine. This work well for small probability like 1/100'000 but when I want a probability of let's say 40% which is 1/0.4 = 2.5 I cannot make mt_rand(1,2.5) I have to do mt_rand(1,2) or mt_rand(1,3) which mean respectively 50% and 33% . How should I do to get a 40% probability? 回答1:

how to plot joint distribtuion of 2 random variable having 1000 data

ⅰ亾dé卋堺 提交于 2019-12-13 04:07:20
问题 here is the code i wrote to generate probability distribtuion of two random variable. now i would like to plot JPD. clear all; clc; x1 = randn(1000,1); x2 = 10*randn(1000,1); [count_1, b] = hist(x1, 25); %25 bins pd1 = count_1 / length(x1) / (b(2) - b(1)); % probability distribution function of x1 [count_2, bn] = hist(x2, 25); %25 bins pd2 = count_2 / length(x2) / (bn(2) - bn(1)); % probabitlity distribtuion function of x2 %subplot(2,2,1), plot(x,s1) %subplot(2,2,2),plot(x,s2) %subplot(2,2,1)

How to control the probability of random selection?

為{幸葍}努か 提交于 2019-12-13 02:55:46
问题 I want to select a user from a user list randomly, but I want the VIP users have higher probability to be selected, how to implement such a algorithm? Sample data: $users = array( array('name'=>'user1', 'is_vip'=>false), array('name'=>'user2', 'is_vip'=>false), array('name'=>'user3', 'is_vip'=>false), array('name'=>'user4', 'is_vip'=>false), array('name'=>'user5', 'is_vip'=>false), array('name'=>'user6', 'is_vip'=>true), array('name'=>'user7', 'is_vip'=>false), array('name'=>'user8', 'is_vip'

Reorganise 2x36 dataframe to a 6x6 dataframe. Dice throw visualisation

核能气质少年 提交于 2019-12-13 02:37:31
问题 I've created a data-frame of all the possible outcomes from a dice throw as 2x36 dataframe. d1 d2 1 1 1 2 2 1 3 3 1 4 4 1 5 5 1 6 6 1 7 1 2 8 2 2 9 3 2 10 4 2 11 5 2 12 6 2 13 1 3 14 2 3 15 3 3 16 4 3 17 5 3 18 6 3 19 1 4 20 2 4 21 3 4 22 4 4 23 5 4 24 6 4 25 1 5 26 2 5 27 3 5 28 4 5 29 5 5 30 6 5 31 1 6 32 2 6 33 3 6 34 4 6 35 5 6 36 6 6 To make this visually more pleasing I want to re-organise it as a 6x6 table. [,1] [,2] [,3] [,4] [,5] [,6] [1,] "1 1" "1 2" "1 3" "1 4" "1 5" "1 6" [2,] "2

How to decide group assignments in Dirichlet process clustering

旧巷老猫 提交于 2019-12-13 01:43:26
问题 As in the Dirichlet clustering, the dirichlet process can be represented by the following: Chinese Restaurant Process Stick Breaking Process Poly Urn Model For instance, if we consider Chinese Restaurant Process the process is as follows: Initially the restaurant is empty The first person to enter (Alice) sits down at a table (selects a group). The second person to enter (Bob) sits down at a table. Which table does he sit at? He sits down at a new table with probability α/(1+α) He sits with

How to calculate probabilities using numpy.histogram and then use it for calculating KL divergence?

女生的网名这么多〃 提交于 2019-12-12 23:55:05
问题 In the following code, the density=True returns probability density function at each bin. Now if have to calculate P(x), can I say that hist is showing probabilities? For example if the first bin's mean value is 0.5 can I say that at x=0.5 probability is hist[0] ? I have to use KL divergence which uses P(x). x = np.array([0,0,0,0,0,3,3,2,2,2,1,1,1,1,]) hist,bin_edges= np.histogram(x,bins=10,density=True) 回答1: When you set density=True , NumPy returns a probability density function (lets say p

Sampling from discrete probability distribution from first principles

家住魔仙堡 提交于 2019-12-12 18:33:17
问题 I have a set S={a1,a2,a3,a4,a5,......,an}. The probability with which each of the element is selected is {p1,p2,p3,p4,p5,...,pn} respectively (where ofcourse p1+p2+p3+p4+p5+....+pn=1}. I want to simulate an experiment which does that. However I wish to do that without any libraries (i.e from first principles) I'm using the following method: 1) I map the elements on the real number line as follows X(a1)=1; X(a2)=2; X(a3)=3; X(a4)=4; X(a5)=5;....,X(an)=n 2) Then I calculate the cumulative

Generate all possible permutations from four integer lists in R

▼魔方 西西 提交于 2019-12-12 18:31:21
问题 (Very) amateur coder and statistician working on a problem in R. I have four integer lists: A, B, C, D. A <- [1:133] B <- [1:266] C <- [1:266] D <- [1:133, 267-400] I want R to generate all of the permutations from picking 1 item from each of these lists (I know this code will take forever to run), and then take the mean of each of those permutations. So, for instance, [1, 100, 200, 400] -> 175.25. Ideally what I would have at the end is a list of all of these means then. Any ideas? 回答1: Here

Fitting a distribution given the histogram using scipy

这一生的挚爱 提交于 2019-12-12 18:17:53
问题 I would like to fit a distribution using scipy (in my case, using weibull_min) to my data. Is it possible to do this given the Histogram, and not the data points? In my case, because the histogram has integer bins of size 1, I know that I can extrapolate my data in the following way: import numpy as np orig_hist = np.array([10, 5, 3, 2, 1]) ext_data = reduce(lambda x,y: x+y, [[i]*x for i, x in enumerate(orig_hist)]) In this case, ext_data would hold this: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,

Selecting Random Item from List given probability of each item

与世无争的帅哥 提交于 2019-12-12 18:13:57
问题 Sorry about badly phrased title.... I have an object called NGram class NGram { //other properties double Probability {get; set;} //Value between 1 and 0 } Now suppose I have a list of these objects such that... List<NGrams> grams = GetNGrams(); Debug.Assert(grams.Sum(x => x.Probability) == 1); How can I select a random item from this list while factoring in the probability distribution. For instance, suppose grams[0].Probability == 0.5 then there should be a 50% chance of selecting grams[0]