Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

Pembangkitan

Bilangan Acak
Diskret
Gustriza erda
TABLE OF CONTENTS
01 Bernouli Distribution

02 Binomial Distribution

03 Poisson Distribution

04 Geometric Distribution

05 Negative Binomial Distribution

06 Hypergeometric Distribution
Pembangkitan Bilangan Acak Diskret
Pembangkitan Bilangan Acak Diskret
Pembangkitan Bilangan Acak Diskret
3

1 2
6

4 5
01
Bernouli
Distribution
01
Bernouli
Distribution
Bernouli Distribution

The Bernoulli distribution is a discrete


distribution having two possible outcomes
labelled by n=0 and n=1 in which n=1
("success") occurs with probability p and n=0
("failure") occurs with probability q=1-p,
where 0<p<1.
Bernouli Distribution

1. Will you pass or fail a test?


2. Will your favorite sports team win or lose their next
match?
3. Will you be accepted or rejected for that job you applied
for?
4. Will you roll a six in the opening round of your favorite
board game?
5. Will you win or lose the lottery?
Generate random numbers from B(1,p)
using U(0,1) distribution, where p is the
probability of success.
Ten random numbers from
One random number from B(1,0.5) distribution
B(1,0.5) distribution
n=10
p=0.5 X={}
U=runif(1,0,1) p=0.5
U for(i in 1:n)
if(U<=p) X=1 else X=0 {
print(X) U=runif(1,0,1)
X if(U<=p) {X[i]=1} else {X[i]=0}
}
print(X)
02
Binomial
Distribution
Binomial Distribution

● The number of observations or trials is fixed. In


other words, you can only figure out the
probability of something happening if you do it a
certain number of times.
● Each observation or trial is independent
● The probability of success is exactly the same
from one trial to another.
Generate random numbers from B(n,p)
using U(0,1) distribution, where n is the
number of trials and p is the probability of
success.
Five random numbers from
B(10,0.5) distribution

m=5 *No. of Binomial random variales


n=10 *No. of Bernoulli random variales
One random number from Y={}
B(10,0.5) distribution p=0.5
for(j in 1:m)
{
n=10 X={}
X={} for(i in 1:n)
p=0.5 {
for(i in 1:n) U=runif(1)
{ if(U<=p) X[i]=1 else X[i]=0
U=runif(1) }
if(U<=p) X[i]=1 else X[i]=0 Y[j]=sum(X)
} }
Y=sum(X) print(Y)
print(Y)
03
Poisson
Distribution
Poisson Distribution

● A Poisson distribution is a tool that helps to


predict the probability of certain events happening
when you know how often the event has
occurred. It gives us the probability of a given
number of events happening in a fixed interval of
time.
n=10
Ten random numbers lm=2
x={}
from P(2) for(i in 1:n)
distribution {
P=1;x[i]=0
while(P>exp(-lm))
{
P=P*runif(1,0,1)
x[i]=x[i]+1
}
x[i]=x[i]-1
}
print(x)
04
Geometric
Distribution
Geometric Distribution

● The geometric distribution represents the number


of failures before you get a success in a series of
Bernoulli trials.
Generate random numbers from G(p)
distribution, (p is the probability of success)
using U(0,1) distribution
Ten random numbers from
G(0.5) distribution

n=10
X={}
One random number from p=0.5
G(0.5) distribution for(i in 1:n)
{
U=runif(1)
X[i]=as.integer(log(U)/log(1-p))
p=0.5
}
U=runif(1)
print(X)
X=as.integer(log(U)/log(1-p))
print(X)
05
Negative
Binomial
Distribution
Negative Binomial Distribution
1. the number of trials, n is not fixed.
2. Each trial is independent.
3. Only two outcomes are possible
(Success and Failure).
4. Probability of success (p) for each trial
is constant.
5. A random variable Y= the number of
trials needed to make r successes..

A negative binomial distribution (also


called the Pascal Distribution) is a discrete
probability distribution for random
variables in a negative binomial
experiment.
One random number from m=5 # NB random numbers
r=10
NB(10,0.5) distribution p=0.5
Y={} Five random
r=10
for(j in 1:m) numbers from
p=0.5
X={}
{ NB(10,0.5)
X={}
for(i in 1:r)
for(i in 1:r)
distribution
{
{
U=runif(1)
U=runif(1)
X[i]=as.integer(log(U)/log(1-
X[i]=as.integer(log(U)/log(1-p))
p))
}
}
Y[j]=sum(X)
Y=sum(X)
}
print(Y)
print(Y)
06
Hypergeometric
Distribution
Geometric Distribution

● The hypergeometric distribution is a probability distribution that’s very similar to the binomial
distribution.
● In fact, the binomial distribution is a very good approximation of the hypergeometric distribution as
long as you are sampling 5% or less of the population.
N=10
M=5
Three random n=3
numbers from x={}
H(10,5,3) for(j in 1:n)
{
distribution x[j]=0
for(i in 1:n)
{
if(runif(1)<=((M-x[j])/(N-i+1)))
x[j]=x[j]+1
}
}
print(x)
Any question?

You might also like