Machine Learning Foundation HW1

Q9: Consider a bin with infinitely many marbles, and let μ be the fraction of orange marbles in the bin, and ν is the fraction of orange marbles in a sample of 10 marbles. If μ=0.5, what is the probability of ν=μ? Please choose the closest number.

Explanation

u是罐子中的黄色小球概率,v是样本中的黄色小球概率,u=0.5。题目中已规定v=u=0.5,则10个样本中黄色球的个数为10*v=5,剩下的绿色球的个数为10-5=5。

最后实际上是要求解:取出来的10个样本中,黄色小球为5个 绿色小球为5个的概率。

注意,要用v来计算样本中各类小球的数量,这仅仅代表取样结果。真实取样时,要用罐子中的实际概u来求解。)

Ref:Class Forum

Probability Computation

10000個裡面有10個不良品 不良比例為0.001
取樣25個 滿足二項式分布,假設取到k個不良品

–> C(25,k) (0.999)^(n-k)*(0.001)^k

  1. 取不到不良品 k=0
    C(25,0) 0.999^25*1=0.999^25= 0.9753…
  2. 取到不良品 K不等於0
    =1-P(取不到不良品)
    =1-C(25,0) 0.999^25*1=0.0247…

Ref: 取樣

Solution Implement by Octave

ans = samplingProbability(u,n)

function ans = samplingProbability(u,n)
k = n * u;
ans = c(n,k)*u^k*(1-u)^(n-k);
endfunction

function ans = c(n,k)
ans = factorial(n)/factorial(n-k)/factorial(k);
endfunction

Q11 If μ=0.5, what is the actual probability of ν<=0.1?

Explanation

probability of v <= 0.1 means probability of (v = 0 or v = 1)

=> P(A∪B)

Probability Theorem

機率 P(A∩B) 稱 為 A 和 B 的 聯 合 機 率 (joint probability) 。

加法法則 (addition rule) :

  1. 若 A 和 B 為同一空間中的兩個事件,則

    P(A∪B) = P(A) + P(B) − P(A∩B)
  2. 若 A 和 B 為互斥事件(mutually exclusive events),則

    P(A∪B) = P(A) + P(B)

Ref:基礎機率概念

Therefore let event A: v =0, event B: v = 0.1:

P(A∪B) = P(A) + P(B) = P(0) + P(0.1)

Solution Implement by Octave

ans = samplingProbability_v(u, v = 0, n) + samplingProbability_v(u, v = 0.1, n)

function ans = samplingProbability_v(u,v,n)
k = n * v;
ans = c(n,k)*u^k*(1-u)^(n-k);
endfunction

Q13 Consider four kinds of dice in a bag, with the same (super large) quantity for each kind.

A: all even numbers are colored orange, all odd numbers are colored green

B: all even numbers are colored green, all odd numbers are colored orange

C: all small (1-3) are colored orange, all large numbers (4­-6) are colored green

D: all small (1­-3) are colored green, all large numbers (4-6) are colored orange

If we pick 5 dice from the bag, what is the probability that we get 5 orange 1’s?

Explanation

As the problem mentions:

Please note that the dice is not meant to be thrown for random experiments in this problem. They are just used to bind the six faces together.

so we don’t need to compute the probability of throwing dice.

Probability Computation

  1. Think about probabilty of getting 1 dice with orange 1

    => P(getting 1 dice with orange 1) = P(get B dice) + P(get C dice)
  2. Probability of getting 5 dice with orange 1

    => P(getting 1 dice with orange 1) ^ 5

Q14 If we pick 5 dice from the bag, what is the probability that we get “some number” that is purely orange?

Explanation

Recall Q13, the probability of getting 5 dice with orange 1 can be also written as:

P(get 5 orange 1) = outcome of 'B or C' / all outcome = 2^5 / 4^5
P(得到5個orange1) = 拿到B或C的出象 / 所有的出象 = 2^5 / 4^5

So the probability of getting 5 dice with orange ‘some #’ can be represented as

P(get 5 orange #) = outcome of 'dice for orange #'/ all outcome

Outcome of ‘dice for orange #’

outcome of 'dice for orange #' 
= (outcome of 'B or C for orange 1'
\+ outcome of 'A or C for orange 2'
\.\.\.
\+ outcome of 'A or D for orange 6')
= outcome of AC, BC, AD, BD
= O(AC ∪ BC ∪ AD ∪ BD)

- O(event) = number of outcome of the event.

However, AC, BC, AD, BD is not mutually exclusive events:
they repeats for all A, all B, all C, all D condition
i.e

AC BC AD BD
AAAAA BBBBB AAAAA BBBBB A, B repeats => -2
CCCCC CCCCC DDDDD DDDDD C, D repeats => -2
ACA.. CB… AAD.. BDD.. no repeat

Therefore,

outcome of 'dice for orange #' 
= O(AC ∪ BC ∪ AD ∪ BD)
= O(AC) + O(BC) + O(AD) + O(BD) - O(A,B) - O(C,D)
= O(AC) + O(BC) + O(AD) + O(BD) - 4