BRAGA

02 Writing02-02 Notes02-02-374

Union (General)

Published 16 Apr 20263 min read
Contents
  1. 01Deep Breakdown
  2. 02Flowchart
  3. 03Real-world use
  4. 04The formula, piece by piece
  5. 05The formula in words
  6. 06Critical Concepts
  7. 07Step-by-step calculation (tiny example)
  8. 08Code examples
P(A∪B)=P(A)+P(B)−P(A∩B)P(A \cup B) = P(A) + P(B) - P(A \cap B)
(1)

Deep Breakdown

What it tells me (Situation Awareness): The inclusion-exclusion principle for two events. When computing the probability that at least one of AA or BB occurs, simply adding P(A)+P(B)P(A) + P(B) overcounts the region where both occur. Subtracting P(A∩B)P(A \cap B) corrects this. Used in any scenario involving "at least one of these two things happens."

Flowchart

P(A∪B) = P(atleast one of A orB)Add P(A) + P(B):overcounts A∩BSubtractP(A∩B): fixdouble-countP(A∪B) = P(A) +P(B) - P(A∩B)Special case:mutuallyexclusive →P(A∩B)=0

Real-world use

Where it is used

Fraud detection: P(flag by rule 1 OR rule 2)P(\text{flag by rule 1 OR rule 2}). A/B test multi-arm scenarios. Email deliverability: P(spam∪promotion folder)P(\text{spam} \cup \text{promotion folder}). Any Boolean OR of probabilistic events.

Problem it solves

Computes the probability that at least one of two overlapping events occurs, avoiding double-counting their intersection.

How it solves the problem

Venn diagram logic: A∪BA \cup B = region covered by AA plus region covered by BB minus the overlapping region counted twice.

Example in a business

Two fraud detection rules each have 10% false positive rates and share 3% of flagged cases. Combined false positive rate: P(flag 1∪flag 2)=0.10+0.10−0.03=0.17P(\text{flag 1} \cup \text{flag 2}) = 0.10 + 0.10 - 0.03 = 0.17.

The formula, piece by piece

P(A∪B)=P(A)+P(B)−P(A∩B)P(A \cup B) = P(A) + P(B) - P(A \cap B)

  • P(A∪B)P(A \cup B): probability that A OR B (or both) occur.
  • P(A)+P(B)P(A) + P(B): sum of individual probabilities.
  • −P(A∩B)-P(A \cap B): remove the double-counted intersection.

The formula in words

"The probability of AA OR BB equals the probability of AA plus the probability of BB minus the probability of both AA and BB occurring together."

Critical Concepts

  • If AA and BB are mutually exclusive: P(A∩B)=0P(A \cap B) = 0, so P(A∪B)=P(A)+P(B)P(A \cup B) = P(A) + P(B).
  • Extends to nn events via inclusion-exclusion: alternating sum of intersections.
  • Upper bound (union bound): P(A∪B)≤P(A)+P(B)P(A \cup B) \leq P(A) + P(B).
  • Python: compute each term separately, then combine.

Step-by-step calculation (tiny example)

Step 1: Define events P(A)=0.4P(A) = 0.4, P(B)=0.3P(B) = 0.3, P(A∩B)=0.1P(A \cap B) = 0.1.

Step 2: Apply formula P(A∪B)=0.4+0.3−0.1=0.6P(A \cup B) = 0.4 + 0.3 - 0.1 = 0.6

Step 3: Sanity check P(A∪B)<P(A)+P(B)P(A \cup B) < P(A) + P(B) because events overlap: correct.

Code examples

Beginner example (Python)

python
# Combined fraud detection rate
p_rule1 = 0.10
p_rule2 = 0.10
p_both = 0.03   # Both rules trigger on same transaction
p_flagged = p_rule1 + p_rule2 - p_both
print(f"P(flagged by either rule) = {p_flagged:.2f}")   # 0.17

Beginner example (R)

r
p_rule1 <- 0.10; p_rule2 <- 0.10; p_both <- 0.03
p_flagged <- p_rule1 + p_rule2 - p_both
cat("P(flagged by either rule) =", p_flagged, "\n")  # 0.17

Professional example (Python)

python
import numpy as np

def union_probability(p_a: float, p_b: float, p_a_and_b: float) -> float:
    """Compute P(A∪B) via inclusion-exclusion. Args: p_a: P(A), probability of event A. p_b: P(B), probability of event B. p_a_and_b: P(A∩B), probability of both events. Returns: P(A∪B). Raises: ValueError: If inputs are invalid probabilities. """
    for val, name in [(p_a, "P(A)"), (p_b, "P(B)"), (p_a_and_b, "P(A∩B)")]:
        if not 0 <= val <= 1:
            raise ValueError(f"{name}={val} is not a valid probability")
        return p_a + p_b - p_a_and_b   # Multi-rule alert system analysis
detection_scenarios = [ ("Rule A + Rule B", 0.15, 0.12, 0.04), ("Model + Rule", 0.30, 0.20, 0.08), ("Independent", 0.10, 0.08, 0.10 * 0.08),
]
print(f"{'Scenario':<22} {'P(A)':>6} {'P(B)':>6} {'P(A∩B)':>8} {'P(A∪B)':>8}")
for scenario_name, p_a, p_b, p_ab in detection_scenarios:
    p_union = union_probability(p_a, p_b, p_ab)
print(f"{scenario_name:<22} {p_a:>6.3f} {p_b:>6.3f} {p_ab:>8.4f} {p_union:>8.4f}")

Source: AIO p. 84

#probability-statistics#probability-theory#axioms-and-basic-probability

Keyboard shortcuts

Single keys, ignored while typing in a field or with Cmd, Ctrl or Alt held.

0
Home
1 2 3 4
Work, Writing, Tools, About
j / k
Next / previous section on this page
n / p
Next / previous project or essay
u
Up one level
l
Deutsch
t
Light or dark theme
?
This list
Esc
Close