Sunday, January 5, 2025

UNIT I Bayes Theorem

 

Bayes' Theorem for Civil Engineering Students with a Rural Background

Definition of Conditional Probability

Conditional probability measures the probability of an event , given that another event has already occurred. It is expressed as:

P(AB)=P(AB)P(B),provided P(B)>0.P(A|B) = \frac{P(A \cap B)}{P(B)}, \quad \text{provided } P(B) > 0.

Where:

  • P(AB): Probability of occurring given that has occurred.
  • P(AB): Joint probability of and occurring together.
  • P(B): Probability of event .

Applications in Civil Engineering

Conditional probability helps civil engineers:

  1. Assess failure probabilities of structures under specific conditions (e.g., earthquakes or floods).
  2. Evaluate material strength based on environmental conditions (e.g., corrosion due to humidity).
  3. Estimate traffic congestion given weather or construction conditions.

1. Definition of Bayes' Theorem

Bayes' Theorem is a mathematical formula used to update the probability of an event based on new evidence. It relates the conditional probability of two events and helps in decision-making under uncertainty.

Formula:

P(AB)=P(BA)P(A)P(B)P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)}

Where::

  • P(AB): Probability of event A occurring given that B has occurred (posterior probability).
  • P(BA): Probability of event B given that A occurred (likelihood).
  • P(A): Probability of event A occurring (prior probability).
  • P(B): Total probability of B.

2. Real-Life Example in Civil Engineering

Consider a rural road construction project:

  • Problem Context: You want to assess the probability that the soil in a site is suitable for road construction (AA), given the results of a preliminary soil test (BB).

  • Known Data:

    • Historical data shows 70% of the sites in the area have suitable soil (P(A)=0.7P(A) = 0.7).
    • The test has a 90% chance of correctly identifying suitable soil (P(BA)=0.9P(B|A) = 0.9).
    • For unsuitable soil, the test shows suitability 20% of the time (P(Bnot A)=0.2P(B|\text{not }A) = 0.2).
    • P(not A)=1P(A)=0.3P(\text{not }A) = 1 - P(A) = 0.3.
  • Objective: Compute the probability that the soil is suitable given the test indicates suitability (P(AB)P(A|B)).


3. Solution Using Bayes' Theorem

From the theorem:

P(AB)=P(BA)P(A)P(B)P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)}
  1. Find P(B)P(B):

    P(B)=P(BA)P(A)+P(Bnot A)P(not A)P(B) = P(B|A) \cdot P(A) + P(B|\text{not }A) \cdot P(\text{not }A)

    Substituting:

    P(B)=(0.9×0.7)+(0.2×0.3)=0.63+0.06=0.69P(B) = (0.9 \times 0.7) + (0.2 \times 0.3) = 0.63 + 0.06 = 0.69
  2. Calculate P(AB)P(A|B):

    P(AB)=(0.9×0.7)0.69=0.630.690.913P(A|B) = \frac{(0.9 \times 0.7)}{0.69} = \frac{0.63}{0.69} \approx 0.913

4. Interpretation

After observing a positive test result, the probability of the soil being suitable increases from the prior probability (0.70.7) to the posterior probability (0.9130.913). This helps engineers decide whether to proceed with construction.


5. Simplified Explanation for Students

  • Think of AA as "good soil" and BB as "test result shows good soil."
  • Bayes' Theorem combines historical soil data with the reliability of the test to give a revised probability.
  • Example analogy: Deciding whether a harvested crop will grow well based on soil tests and past experiences.

6. Practical Teaching Tip

To make this relatable:

  • Use local examples (e.g., testing materials for durability in bridges or soil erosion in rural areas).
  • Explain the test’s reliability as "how often the test gets it right."
  • Engage students with interactive activities, such as a mock soil test experiment with probabilities.

Here are two additional numerical examples of Bayes' Theorem tailored for civil engineering scenarios:


Example 3: Assessing the Risk of Flood Damage

Scenario: A rural civil engineer is analyzing a riverbank to assess the risk of flood damage (AA) based on the results of satellite imagery showing high water levels (BB).

Data:

  • P(A)=0.4P(A) = 0.4: 40% of the riverbanks in the area are at risk of flood damage.
  • P(BA)=0.85P(B|A) = 0.85: 85% of at-risk riverbanks show high water levels on satellite imagery.
  • P(Bnot A)=0.3P(B|\text{not }A) = 0.3: 30% of non-at-risk riverbanks also show high water levels.
  • P(not A)=1P(A)=0.6P(\text{not }A) = 1 - P(A) = 0.6.

Objective: Find P(AB)P(A|B), the probability of flood risk given high water levels on satellite imagery.


Solution:

  1. Find P(B)P(B):

    P(B)=P(BA)P(A)+P(Bnot A)P(not A)P(B) = P(B|A) \cdot P(A) + P(B|\text{not }A) \cdot P(\text{not }A)

    Substituting values:

    P(B)=(0.850.4)+(0.30.6)=0.34+0.18=0.52P(B) = (0.85 \cdot 0.4) + (0.3 \cdot 0.6) = 0.34 + 0.18 = 0.52
  2. Apply Bayes’ Theorem:

    P(AB)=P(BA)P(A)P(B)P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)}

    Substituting:

    P(AB)=0.850.40.52=0.340.520.654P(A|B) = \frac{0.85 \cdot 0.4}{0.52} = \frac{0.34}{0.52} \approx 0.654

Result: If high water levels are detected, there is a 65.4% chance the riverbank is at risk of flood damage.


Example 4: Testing Concrete Strength

Scenario: A civil engineer tests concrete strength (AA) using a compression test (BB). Strong concrete has a compressive strength of 30 MPa or higher.

Data:

  • P(A)=0.6P(A) = 0.6: 60% of the concrete batches are strong.
  • P(BA)=0.9P(B|A) = 0.9: 90% of strong concrete passes the compression test.
  • P(Bnot A)=0.2P(B|\text{not }A) = 0.2: 20% of weak concrete also passes the compression test.
  • P(not A)=1P(A)=0.4P(\text{not }A) = 1 - P(A) = 0.4.

Objective: Calculate P(AB)P(A|B), the probability that the concrete is strong given that it passes the compression test.


Solution:

  1. Find P(B)P(B):

    P(B)=P(BA)P(A)+P(Bnot A)P(not A)P(B) = P(B|A) \cdot P(A) + P(B|\text{not }A) \cdot P(\text{not }A)

    Substituting:

    P(B)=(0.90.6)+(0.20.4)=0.54+0.08=0.62P(B) = (0.9 \cdot 0.6) + (0.2 \cdot 0.4) = 0.54 + 0.08 = 0.62
  2. Apply Bayes’ Theorem:

    P(AB)=P(BA)P(A)P(B)P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)}

    Substituting:

    P(AB)=0.90.60.62=0.540.620.871P(A|B) = \frac{0.9 \cdot 0.6}{0.62} = \frac{0.54}{0.62} \approx 0.871

Result: If the concrete passes the compression test, there is an 87.1% chance that it is strong.


Summary of Examples

  1. Flood Damage: 65.4% chance of risk if satellite imagery shows high water levels.
  2. Concrete Strength: 87.1% chance of strong concrete if it passes the compression test.

These examples highlight how Bayes' Theorem updates probabilities based on real-world evidence, aiding decision-making in civil engineering. Let me know if you’d like further clarification!


Here are two numerical examples of Bayes' Theorem specifically tailored for water resource engineering:


Example 5: Predicting Contamination in a Reservoir

Scenario: A water resource engineer is assessing whether a reservoir is contaminated (AA) based on a water quality test (BB) that detects harmful chemical levels.

Data:

  • P(A)=0.3P(A) = 0.3: 30% of reservoirs in the region are contaminated.
  • P(BA)=0.95P(B|A) = 0.95: The test correctly detects contamination 95% of the time.
  • P(Bnot A)=0.1P(B|\text{not }A) = 0.1: The test falsely indicates contamination 10% of the time for uncontaminated reservoirs.
  • P(not A)=1P(A)=0.7P(\text{not }A) = 1 - P(A) = 0.7.

Objective: Calculate P(AB)P(A|B), the probability that the reservoir is contaminated given a positive test result.


Solution:

  1. Find P(B)P(B):

    P(B)=P(BA)P(A)+P(Bnot A)P(not A)P(B) = P(B|A) \cdot P(A) + P(B|\text{not }A) \cdot P(\text{not }A)

    Substituting:

    P(B)=(0.950.3)+(0.10.7)=0.285+0.07=0.355P(B) = (0.95 \cdot 0.3) + (0.1 \cdot 0.7) = 0.285 + 0.07 = 0.355
  2. Apply Bayes’ Theorem:

    P(AB)=P(BA)P(A)P(B)P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)}

    Substituting:

    P(AB)=0.950.30.355=0.2850.3550.803P(A|B) = \frac{0.95 \cdot 0.3}{0.355} = \frac{0.285}{0.355} \approx 0.803

Result: If the water quality test indicates contamination, there is an 80.3% chance that the reservoir is actually contaminated.


Example 6: Flood Risk Assessment for a Dam

Scenario: An engineer is assessing the risk of a dam experiencing a dangerous flood event (AA) based on rainfall data (BB) from meteorological models.

Data:

  • P(A)=0.2P(A) = 0.2: 20% chance of a flood event in the region annually.
  • P(BA)=0.85P(B|A) = 0.85: Meteorological models accurately predict heavy rainfall 85% of the time during a flood event.
  • P(Bnot A)=0.25P(B|\text{not }A) = 0.25: Models predict heavy rainfall 25% of the time even when there’s no flood event.
  • P(not A)=1P(A)=0.8P(\text{not }A) = 1 - P(A) = 0.8.

Objective: Calculate P(AB)P(A|B), the probability of a flood given the prediction of heavy rainfall.


Solution:

  1. Find P(B)P(B):

    P(B)=P(BA)P(A)+P(Bnot A)P(not A)P(B) = P(B|A) \cdot P(A) + P(B|\text{not }A) \cdot P(\text{not }A)

    Substituting:

    P(B)=(0.850.2)+(0.250.8)=0.17+0.2=0.37P(B) = (0.85 \cdot 0.2) + (0.25 \cdot 0.8) = 0.17 + 0.2 = 0.37
  2. Apply Bayes’ Theorem:

    P(AB)=P(BA)P(A)P(B)P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)}

    Substituting:

    P(AB)=0.850.20.37=0.170.370.459P(A|B) = \frac{0.85 \cdot 0.2}{0.37} = \frac{0.17}{0.37} \approx 0.459

Result: If heavy rainfall is predicted, there is a 45.9% chance of a dangerous flood event occurring.


Summary of Examples

  1. Reservoir Contamination: 80.3% chance of contamination if the water quality test is positive.
  2. Dam Flood Risk: 45.9% chance of a flood if heavy rainfall is predicted.

These examples demonstrate how Bayes' Theorem helps integrate environmental data and uncertainty into water resource decision-making. Let me know if you’d like further clarification or variations!

Bayes' Theorem for Discrete and Continuous Random Variables


General Formula

  1. For Discrete Random Variables: Bayes' Theorem applies to events or outcomes that are countable. Given two discrete random variables AA and BB:

    P(A=aB=b)=P(B=bA=a)P(A=a)P(B=b)P(A = a | B = b) = \frac{P(B = b | A = a) \cdot P(A = a)}{P(B = b)}

    Where:

    P(B=b)=aAP(B=bA=a)P(A=a)P(B = b) = \sum_{a \in A} P(B = b | A = a) \cdot P(A = a)
  2. For Continuous Random Variables: When working with continuous variables XX and YY, we use probability density functions (PDFs). The conditional PDF of XX given YY is:

    fXY(xy)=fYX(yx)fX(x)fY(y)f_{X|Y}(x|y) = \frac{f_{Y|X}(y|x) \cdot f_X(x)}{f_Y(y)}

    Where:

    fY(y)=fYX(yx)fX(x)dxf_Y(y) = \int_{-\infty}^\infty f_{Y|X}(y|x) \cdot f_X(x) \, dx

Example 1: Discrete Random Variables

Scenario: An engineering team monitors two machines, M1M_1 and M2M_2. The machines produce defective parts DD.

  • P(M1)=0.6P(M_1) = 0.6, P(M2)=0.4P(M_2) = 0.4 (prior probabilities).
  • Probability of a defective part:
    • P(DM1)=0.1P(D | M_1) = 0.1
    • P(DM2)=0.2P(D | M_2) = 0.2

Objective: If a defective part is observed, find the probability that it came from M1M_1, P(M1D)P(M_1 | D).


Solution:

  1. Calculate P(D)P(D):

    P(D)=P(DM1)P(M1)+P(DM2)P(M2)P(D) = P(D | M_1) \cdot P(M_1) + P(D | M_2) \cdot P(M_2) P(D)=(0.10.6)+(0.20.4)=0.06+0.08=0.14P(D) = (0.1 \cdot 0.6) + (0.2 \cdot 0.4) = 0.06 + 0.08 = 0.14
  2. Apply Bayes’ Theorem:

    P(M1D)=P(DM1)P(M1)P(D)P(M_1 | D) = \frac{P(D | M_1) \cdot P(M_1)}{P(D)} P(M1D)=0.10.60.14=0.060.140.429P(M_1 | D) = \frac{0.1 \cdot 0.6}{0.14} = \frac{0.06}{0.14} \approx 0.429

Result: There is a 42.9% chance that a defective part came from M1M_1.


Example 2: Continuous Random Variables

Scenario: In water resource engineering, an engineer measures the flow rate (XX) and rainfall (YY) at a river basin. The joint behavior of XX and YY is described by the following PDFs:

  • fXY(xy)=2xf_{X|Y}(x|y) = 2x for 0xy0 \leq x \leq y, and 00 otherwise.
  • fY(y)=1f_Y(y) = 1 for 0y10 \leq y \leq 1, and 00 otherwise.

Objective: Find the conditional density fXY(xy)f_{X|Y}(x|y) for a given y=0.5y = 0.5, and calculate the probability P(X0.4Y=0.5)P(X \leq 0.4 | Y = 0.5).


Solution:

  1. Find fXY(xy)f_{X|Y}(x|y): The given PDF fXY(xy)=2xf_{X|Y}(x|y) = 2x for 0xy0 \leq x \leq y, and fY(y)=1f_Y(y) = 1 implies that:

    fXY(xy)={2xif 0x0.5,0otherwise.f_{X|Y}(x|y) = \begin{cases} 2x & \text{if } 0 \leq x \leq 0.5, \\ 0 & \text{otherwise.} \end{cases}
  2. Calculate P(X0.4Y=0.5)P(X \leq 0.4 | Y = 0.5):

    P(X0.4Y=0.5)=00.4fXY(x0.5)dxP(X \leq 0.4 | Y = 0.5) = \int_0^{0.4} f_{X|Y}(x|0.5) \, dx

    Substituting fXY(x0.5)=2xf_{X|Y}(x|0.5) = 2x:

    P(X0.4Y=0.5)=00.42xdx=[x2]00.4=0.42=0.16P(X \leq 0.4 | Y = 0.5) = \int_0^{0.4} 2x \, dx = \left[ x^2 \right]_0^{0.4} = 0.4^2 = 0.16

Result: The conditional probability that the flow rate is 0.4\leq 0.4 given Y=0.5Y = 0.5 is 0.160.16.


Summary

  • Discrete Example: Calculating probabilities for defective parts from different machines.
  • Continuous Example: Finding conditional probabilities for flow rate given rainfall.

Example 1: Discrete Example - Calculating Probabilities for Defective Parts from Machines

Scenario:
An engineering workshop has two machines, M1M_1 and M2M_2, producing parts. The probability of selecting a part from M1M_1 is P(M1)=0.6P(M_1) = 0.6, and from M2M_2, P(M2)=0.4P(M_2) = 0.4.

  • Probability that a part is defective given it came from M1M_1: P(DM1)=0.1P(D|M_1) = 0.1.
  • Probability that a part is defective given it came from M2M_2: P(DM2)=0.2P(D|M_2) = 0.2.

A randomly selected part is found to be defective.

Objective:
What is the probability that this defective part came from M1M_1, i.e., P(M1D)P(M_1|D)?


Solution: Step-by-Step

  1. Understand the Problem:

    • We need P(M1D)P(M_1|D), the probability that the defective part came from M1M_1.
    • Apply Bayes' Theorem for discrete probabilities: P(M1D)=P(DM1)P(M1)P(D)P(M_1|D) = \frac{P(D|M_1) \cdot P(M_1)}{P(D)}
  2. Calculate P(D)P(D):
    Using the law of total probability:

    P(D)=P(DM1)P(M1)+P(DM2)P(M2)P(D) = P(D|M_1) \cdot P(M_1) + P(D|M_2) \cdot P(M_2)

    Substituting values:

    P(D)=(0.10.6)+(0.20.4)=0.06+0.08=0.14P(D) = (0.1 \cdot 0.6) + (0.2 \cdot 0.4) = 0.06 + 0.08 = 0.14
  3. Apply Bayes' Theorem: Substitute P(DM1)P(D|M_1), P(M1)P(M_1), and P(D)P(D) into the formula:

    P(M1D)=0.10.60.14P(M_1|D) = \frac{0.1 \cdot 0.6}{0.14}

    Calculate:

    P(M1D)=0.060.140.429P(M_1|D) = \frac{0.06}{0.14} \approx 0.429

Final Answer:
There is a 42.9% probability that the defective part came from M1M_1.


Example 2: Continuous Example - Finding Conditional Probability of Flow Rate Given Rainfall

Scenario:
An engineer monitors the flow rate (XX) of a river and rainfall (YY) in a catchment area. The joint PDF of XX and YY is:

fX,Y(x,y)={4xy,0x1,0y1,0,otherwise.f_{X,Y}(x, y) = \begin{cases} 4xy, & 0 \leq x \leq 1, 0 \leq y \leq 1, \\ 0, & \text{otherwise.} \end{cases}

Find fXY(xy)f_{X|Y}(x|y), the conditional PDF of XX given YY, and calculate P(X0.5Y=0.8)P(X \leq 0.5 | Y = 0.8).


Solution: Step-by-Step

  1. Understand the Problem:

    • fXY(xy)f_{X|Y}(x|y) is the conditional PDF of XX given YY, defined as: fXY(xy)=fX,Y(x,y)fY(y)f_{X|Y}(x|y) = \frac{f_{X,Y}(x, y)}{f_Y(y)}
    • fY(y)f_Y(y) is the marginal PDF of YY, given by: fY(y)=01fX,Y(x,y)dxf_Y(y) = \int_0^1 f_{X,Y}(x, y) \, dx
  2. Find fY(y)f_Y(y): Substitute fX,Y(x,y)=4xyf_{X,Y}(x, y) = 4xy into the integral:

    fY(y)=014xydxf_Y(y) = \int_0^1 4xy \, dx

    Simplify the integral:

    fY(y)=4y01xdx=4y[x22]01=4y12=2yf_Y(y) = 4y \int_0^1 x \, dx = 4y \left[ \frac{x^2}{2} \right]_0^1 = 4y \cdot \frac{1}{2} = 2y
  3. Find fXY(xy)f_{X|Y}(x|y): Using the formula for conditional PDF:

    fXY(xy)=fX,Y(x,y)fY(y)=4xy2yf_{X|Y}(x|y) = \frac{f_{X,Y}(x, y)}{f_Y(y)} = \frac{4xy}{2y}

    Simplify:

    fXY(xy)=2x,0x1f_{X|Y}(x|y) = 2x, \quad 0 \leq x \leq 1
  4. Calculate P(X0.5Y=0.8)P(X \leq 0.5 | Y = 0.8): Integrate the conditional PDF fXY(x0.8)=2xf_{X|Y}(x|0.8) = 2x over [0,0.5][0, 0.5]:

    P(X0.5Y=0.8)=00.52xdxP(X \leq 0.5 | Y = 0.8) = \int_0^{0.5} 2x \, dx

    Solve the integral:

    P(X0.5Y=0.8)=[x2]00.5=(0.5)202=0.25P(X \leq 0.5 | Y = 0.8) = \left[ x^2 \right]_0^{0.5} = (0.5)^2 - 0^2 = 0.25

Final Answer:
The probability that the flow rate is 0.5\leq 0.5 given Y=0.8Y = 0.8 is 0.25 (25%).


Summary

  • Discrete Example: Probability of a defective part originating from a specific machine.
  • Continuous Example: Conditional probability of flow rate given specific rainfall.

These step-by-step solutions help students understand how conditional probability is applied in both discrete and continuous scenarios. Let me know if you need further clarification!

No comments:

Post a Comment

UNIT II Statistical Probability

Statistical Probability Distributions for Civil Engineering Applications Statistical probability distributions –Students’ t, Chi – square an...