torch.distributions.Poisson
class Poisson extends Distributionnew Poisson(rate: number | Tensor, options?: DistributionOptions)
- readonly
rate(Tensor) - – Rate parameter (expected number of events).
- readonly
arg_constraints(unknown) - readonly
support(unknown) - readonly
mean(Tensor) - readonly
mode(Tensor) - readonly
variance(Tensor)
Poisson distribution: models the count of events in a fixed time interval.
Parameterized by rate λ (expected number of events). Fundamental for modeling counts and discrete phenomena. Essential for:
- Modeling count data (events, arrivals, occurrences)
- Point processes and event counting
- Approximate binomial when n is large, p is small
- Generative modeling of discrete sequences
- Network analysis (degree distributions)
- Rare event modeling
The probability mass function: P(X = k) = (λ^k * e^(-λ)) / k! for k = 0, 1, 2, ...
- Mean = Variance: The rate λ equals both mean and variance (special property)
- Integer samples: Always produces non-negative integers 0, 1, 2, ...
- Tail behavior: Probabilities decrease roughly as λ/k for large k
- Binomial limit: Good approximation when n np (rare events)
- Exponential duality: Inter-event times are exponential; count is Poisson
- Decomposability: Sum of independent Poissons is still Poisson
- Overdispersion: Real count data often has variance mean (use Negative Binomial)
- Rate must be positive: rate ≤ 0 causes errors
- Unbounded support: Can sample arbitrarily large integers (rare)
- Model assumption: Real counts often more dispersed than Poisson (Negative Binomial)
- Large rates: Computation can be inefficient for very large λ
Examples
// Average 4 events per interval
const dist = new torch.distributions.Poisson(4);
const count = dist.sample(); // typically 1-7, centered at 4
const counts = dist.sample([1000]); // 1000 samples
// Rare event: low rate
const rare = new torch.distributions.Poisson(0.5);
const sample = rare.sample(); // mostly 0s, some 1s, rarely 2+
// Common events: high rate
const common = new torch.distributions.Poisson(10);
const sample = common.sample(); // mostly 8-12, bell-curve around 10
// Real-world example: customer arrivals per hour
const arrival_rate = 2.5; // 2.5 customers per hour
const arrival_dist = new torch.distributions.Poisson(arrival_rate);
const customers_this_hour = arrival_dist.sample(); // count of arrivals
const customers_next_8hrs = arrival_dist.sample([8]); // 8 hourly samples
// Network degree distribution: social network connections
const avg_connections = 5; // average friends per person
const degree_dist = new torch.distributions.Poisson(avg_connections);
const person_connections = degree_dist.sample(); // how many friends?
// Batched distributions with different rates
const rates = torch.tensor([1, 4, 10]); // different mean counts
const dist = new torch.distributions.Poisson(rates);
const samples = dist.sample(); // [3] shaped samples
// First usually 0-2, second around 4, third around 8-12
// Mean = Variance: distinguish from other distributions
const dist = new torch.distributions.Poisson(5);
const mean = dist.mean; // 5
const variance = dist.variance; // also 5 (unique property!)
// Probability of specific counts
const dist = new torch.distributions.Poisson(3);
const prob_zero = dist.log_prob(0).exp(); // P(X = 0) = e^(-3)
const prob_five = dist.log_prob(5).exp(); // P(X = 5) = 3^5 * e^(-3) / 5!