Mathematical Foundations

V.9 · Statistics

Which parameter gives the observed data their greatest likelihood?

Compare a learner-selected Bernoulli parameter with the optimizer derived from the actual success count, including all-success, all-failure and empty-data cases.

Move a candidate, find the data-derived optimum

Actual fixed sequence: [1, 0, 1, 1, 0]. Successes: 3; failures: 2.

Next outcome 1= 0.6
Next outcome 0= 0.4
Likelihood over candidate parameters
Likelihood over candidate parametersObserved Bernoulli data: 1, 0, 1, 1, 0. 3 successes, 2 failures. Bernoulli MLE = 0.6. The optimizer follows the observed success count, not a density maximum over observations.0.03801600.51

θ · solid curve is actual ordered-data likelihood · dot is the candidate · dashed marker is MLE

Log-likelihood ≈ -3.36506

Observed Bernoulli data: 1, 0, 1, 1, 0. 3 successes, 2 failures. Bernoulli MLE = 0.6. The optimizer follows the observed success count, not a density maximum over observations.

Ordered-data likelihood
0.03456
Log-likelihood (natural log)
−3.365058
Maximal data likelihood
0.03456
Log-likelihood gap to optimum
0
Data-derived maximizing parameter
0.6

= exact finite-data/model quantity · ≈ binary64 approximation; empirical results describe this run

from 0 to 1, up to 2 decimal places

Bernoulli MLE = 0.6. The optimizer follows the observed success count, not a density maximum over observations.

L(θ)=θ3(1−θ)2L(\theta)=\theta^{3}(1-\theta)^{2}
ℓ(θ)=3log⁡θ+2log⁡(1−θ)≈−3.36506\ell(\theta)=3\log\theta+2\log(1-\theta)\approx-3.36506
θ^=kn=0.6\hat\theta=\frac{k}{n}=0.6

Keep observed data fixed

Observed sequence: 1, 0, 1, 1, 0. The ordered-sequence model has no binomial count coefficient.

L(θ)=θ3(1−θ)2L(\theta)=\theta^{3}(1-\theta)^{2}

Compare a learner-selected Bernoulli parameter with the optimizer derived from the actual success count, including all-success, all-failure and empty-data cases.

Intuition

A candidate parameter can agree more or less well with the fixed observations. MLE selects the candidate that assigns those observations the greatest likelihood. It is an estimator defined by a rule; its result changes when different data are observed.

Definition

For a closed candidate domain [0,1][0,1], define argmax⁡θ∈[0,1]L(θ;D)\operatorname{argmax}_{\theta\in[0,1]}L(\theta;D). For nonempty Bernoulli data the unique maximizing estimate is θ^=k/n\hat\theta=k/n, including 0 and 1 when failures or successes are complete. For empty data, every candidate ties because L=1L=1.

Mechanics

Move candidate θ and inspect its exact likelihood, natural log-likelihood and gap from the maximum. The dashed marker and inspector show the data-derived optimizer independently of the candidate control. The optimum may be an exact fraction that cannot be entered with the control’s two-decimal precision; its marker and reported value retain that exact mathematical estimate.

Derivation

For 0<k<n0<k<n, ℓ′(θ)=k/θ−(n−k)/(1−θ)=0\ell\prime(\theta)=k/\theta-(n-k)/(1-\theta)=0 gives θ=k/n\theta=k/n. The second derivative ℓ′′(θ)=−k/θ2−(n−k)/(1−θ)2<0\ell\prime\prime(\theta)=-k/\theta^2-(n-k)/(1-\theta)^2<0 proves a unique interior maximum. For k=n, likelihood increases to 1; for k=0, it decreases from 0. These cases use boundary monotonicity rather than an invalid interior derivative equation.

Worked examples

The canonical sequence has 3 successes out of 5, so MLE is 3/5. A candidate 2/5 gives likelihood 2/3 of the maximum, and the log-likelihood gap is log⁡(3/2)≈0.405465\log(3/2)\approx0.405465. All successes give MLE 1; all failures give MLE 0. No observations give no unique optimizer, not a default estimate of 1/2.

Worked example: Move a candidate, find the data-derived optimum

Actual fixed sequence: [1, 0, 1, 1, 0]. Successes: 3; failures: 2.

Next outcome 1= 0.6
Next outcome 0= 0.4
Likelihood over candidate parameters
Likelihood over candidate parametersObserved Bernoulli data: 1, 0, 1, 1, 0. 3 successes, 2 failures. Bernoulli MLE = 0.6. The optimizer follows the observed success count, not a density maximum over observations.0.03801600.51

θ · solid curve is actual ordered-data likelihood · dot is the candidate · dashed marker is MLE

Log-likelihood ≈ -3.36506

Observed Bernoulli data: 1, 0, 1, 1, 0. 3 successes, 2 failures. Bernoulli MLE = 0.6. The optimizer follows the observed success count, not a density maximum over observations.

Ordered-data likelihood
0.03456
Log-likelihood (natural log)
−3.365058
Maximal data likelihood
0.03456
Log-likelihood gap to optimum
0
Data-derived maximizing parameter
0.6

= exact finite-data/model quantity · ≈ binary64 approximation; empirical results describe this run

from 0 to 1, up to 2 decimal places

Bernoulli MLE = 0.6. The optimizer follows the observed success count, not a density maximum over observations.

L(θ)=θ3(1−θ)2L(\theta)=\theta^{3}(1-\theta)^{2}
ℓ(θ)=3log⁡θ+2log⁡(1−θ)≈−3.36506\ell(\theta)=3\log\theta+2\log(1-\theta)\approx-3.36506
θ^=kn=0.6\hat\theta=\frac{k}{n}=0.6

Keep observed data fixed

Observed sequence: 1, 0, 1, 1, 0. The ordered-sequence model has no binomial count coefficient.

L(θ)=θ3(1−θ)2L(\theta)=\theta^{3}(1-\theta)^{2}

Replay the observed data, log evaluation and valid optimizing or mode rule.

Executable reference code

Run both standalone files. The pedagogical version exposes exact mechanics and valid mode cases; the NumPy companion makes array operations explicit. Assertions use literal hand-worked outputs and do not tune data to a preferred estimate.

code/python/statistics_mle.py
"""Runnable mle reference with explicit boundary policy."""
from fractions import Fraction as F
def mle(data):
    if any(x not in [0,1] for x in data):raise ValueError('binary observations required')
    return F(sum(data),len(data)) if data else None
assert mle([1,0,1,1,0])==F(3,5)
assert mle([1,1,1])==1 and mle([0,0,0])==0
assert mle([]) is None  # Every theta maximizes the empty likelihood.
print(mle([1,0,1,1,0]))
code/python/statistics_mle_numpy.py
"""Runnable mle reference with explicit boundary policy."""
import numpy as np
def mle(data):
    x=np.asarray(data)
    if np.any((x!=0)&(x!=1)):raise ValueError('binary observations required')
    return x.mean() if x.size else None
assert mle([1,0,1,1,0])==.6
assert mle([1,1,1])==1 and mle([0,0,0])==0 and mle([]) is None
print(mle([1,0,1,1,0]))

Explore

Flip one actual observation and predict how k/n changes. Add a success or a failure and compare the candidate with the new exact optimum. Try boundary presets and the empty sequence. Explain why a sharply peaked likelihood still does not become a normalized probability distribution over θ by itself.

Common mistakes and counterexamples

Do not maximize over hypothetical data at a fixed parameter; that asks for a most probable outcome. MLE maximizes over parameters with the observed data fixed. MLE does not automatically provide a confidence interval, a posterior probability or a causal interpretation. Boundary estimates can be correct optimizers even when they are fragile predictions for new observations.

Numerical considerations

The MLE k/n, exact candidate likelihood and maximum likelihood remain rational. Floating log-likelihood comparisons use natural logs and stable log1p. At a zero-likelihood candidate the gap is +∞; both non-finite values receive explicit messages. Derived maximizing fractions are never rounded back into the two-decimal input state. No general optimizer or expression evaluator is needed for this analytic model.

Engineering and ML connections

Bernoulli MLE is the empirical success rate. More complex probabilistic models may require numerical optimization, but the statistical objective and the search algorithm remain distinct. Training likelihood assesses observed data; useful deployment predictions also require validation, uncertainty analysis and model checking.

Exercises

Work from fixed observed data, distinguish statistical objects, and check corrective feedback with a worked solution.

calculation

Data-derived optimizer

For observed sequence [1,0,1,1,0], give the Bernoulli MLE.

calculation

Boundary solutions

Give the MLE for [1,1,1], then for [0,0,0].

calculation

Compare candidate to optimum

For the canonical data, give L(2/5) divided by L(3/5).

explanation

Empty data

What is the Bernoulli MLE when the observed sequence is empty?

Choose one answer

explanation

Probability versus likelihood

Which maximum is being sought in Bernoulli MLE?

Choose one answer

Summary and checkpoints

Derive the interior estimator, prove its maximum, handle both boundaries and empty data, and compare an actual candidate with the analytic optimizer. Keep the estimated parameter separate from a density maximum over possible observations.

The map of the book

97 of 97 chapters written · eight Parts

demo Foundation demo Try the live vector example Open as a page

Part I

Mathematical Language

The notation and mental objects everything else uses.

9 of 9 chapters written

  1. I.1 Scalars, quantities, units, powers and roots available
  2. I.2 Coordinates and points available
  3. I.3 Vectors: components, magnitude, and direction reference chapter available
  4. I.4 Algebraic expressions, equations and inequalities available
  5. I.5 Functions as input → transformation → output available
  6. I.6 Essential function families available
  7. I.7 Sets, intervals, and relations available
  8. I.8 Indexed quantities and summation available
  9. I.9 The notation map for ML available

Part II

Linear Algebra

Matrices as transformations: the strongest foundation in the book.

19 of 19 chapters written

  1. II.1 Vector addition and subtraction available
  2. II.2 Scalar multiplication and vector scaling available
  3. II.3 Norms, magnitude, and normalization available
  4. II.4 Dot product, angle, and orthogonality available
  5. II.5 Projection and distance to a direction available
  6. II.6 Linear combinations and span available
  7. II.7 Linear independence, basis, and coordinates available
  8. II.8 Matrices as linear transformations available
  9. II.9 Matrix × vector available
  10. II.10 Matrix × matrix as composition available
  11. II.11 Transpose and orthogonality available
  12. II.12 Determinant: orientation and area/volume scaling available
  13. II.13 Linear systems as intersecting constraints available
  14. II.14 Gaussian elimination and row operations available
  15. II.15 Rank and invertibility available
  16. II.16 Inverse matrices available
  17. II.17 Eigenvalues and eigenvectors available
  18. II.18 Orthogonal bases and least-squares geometry available
  19. II.19 Singular Value Decomposition available

Part III

Calculus

Change, local approximation, and sensitivity made visible.

15 of 15 chapters written

  1. III.1 Limits through approach available
  2. III.2 Continuity and local behavior available
  3. III.3 Derivative as secant → tangent available
  4. III.4 Derivative as rate of change and local linear model available
  5. III.5 Derivative rules available
  6. III.6 Chain rule available
  7. III.7 Multivariable functions and partial derivatives available
  8. III.8 Gradient and directional derivatives available
  9. III.9 Jacobian available
  10. III.10 Computational graphs and automatic differentiation available
  11. III.11 Hessian and curvature available
  12. III.12 Integrals as accumulation available
  13. III.13 Fundamental derivative/integral connection available
  14. III.14 Numerical differentiation available
  15. III.15 Numerical integration available

Part IV

Probability

Uncertainty through sample spaces, evidence, and repetition.

16 of 16 chapters written

  1. IV.1 Random experiments, outcomes, and sample spaces available
  2. IV.2 Events and probability mass available
  3. IV.3 Counting and finite probability where needed available
  4. IV.4 Conditional probability as restricted sample space available
  5. IV.5 Independence available
  6. IV.6 Bayes' theorem as probability-mass update available
  7. IV.7 Random variables available
  8. IV.8 PMF, PDF, and CDF available
  9. IV.9 Bernoulli and Binomial distributions available
  10. IV.10 Uniform and Gaussian distributions available
  11. IV.11 Expectation available
  12. IV.12 Variance and standard deviation available
  13. IV.13 Joint, marginal, and conditional distributions available
  14. IV.14 Covariance and correlation available
  15. IV.15 Law of Large Numbers available
  16. IV.16 Central Limit Theorem available

Part V

Statistics

From observed data to estimates, intervals, and likelihood.

10 of 10 chapters written

  1. V.1 Data summaries: mean, median, mode available
  2. V.2 Spread: variance, standard deviation, robust interpretation available
  3. V.3 Population, sample, and sampling variability available
  4. V.4 Estimators and estimation available
  5. V.5 Confidence intervals through repeated sampling available
  6. V.6 Covariance matrices and multivariate spread available
  7. V.7 Regression fundamentals available
  8. V.8 Likelihood available
  9. V.9 Maximum Likelihood Estimation available
  10. V.10 Maximum A Posteriori estimation available

Part VI

Optimization

Learning as repeated parameter updates governed by an objective.

10 of 10 chapters written

  1. VI.1 Objective functions and optimization landscapes available
  2. VI.2 Local vs global optima and stationary points available
  3. VI.3 Convexity available
  4. VI.4 Gradient descent flagship chapter available
  5. VI.5 Learning rate and convergence behavior available
  6. VI.6 Momentum available
  7. VI.7 Stochastic and mini-batch gradient descent available
  8. VI.8 Adam intuition available
  9. VI.9 Constraints and projected/penalized intuition available
  10. VI.10 Numerical stopping and optimization diagnostics available

Part VII

Information Theory

Logarithms, entropy, and the loss behind token prediction.

8 of 8 chapters written

  1. VII.1 Logarithms and log probabilities in computation available
  2. VII.2 Self-information available
  3. VII.3 Entropy available
  4. VII.4 Cross entropy and negative log-likelihood available
  5. VII.5 KL divergence available
  6. VII.6 Logits and softmax available
  7. VII.7 Numerical stability: log-sum-exp and stable softmax available
  8. VII.8 From token logits to language-model loss available

Part VIII

Numerical Computing

Why equivalent expressions behave differently on real machines.

10 of 10 chapters written

  1. VIII.1 Floating-point representation available
  2. VIII.2 Rounding and representation error available
  3. VIII.3 Error propagation and conditioning available
  4. VIII.4 Catastrophic cancellation available
  5. VIII.5 Overflow and underflow available
  6. VIII.6 Stable algorithms available
  7. VIII.7 Numerical linear algebra realities available
  8. VIII.8 Sparse matrices and sparse structure available
  9. VIII.9 Vectorized computation available
  10. VIII.10 Reproducibility, random seeds, and nondeterminism available