Back to .md Directory

Eval Learnings

Documents six evaluation rounds that validate parameter recovery, autodiff correctness, influence function assembly, and frequentist coverage for a deep inference package.

May 2, 2026
0 downloads
0 views
ai eval
View source

What this file does

Documents six evaluation rounds that validate parameter recovery, autodiff correctness, influence function assembly, and frequentist coverage for a deep inference package.

When to use it

  • Verifying correctness of a statistical inference pipeline with Monte Carlo simulations
  • Debugging gradient or Hessian computations in PyTorch autodiff
  • Validating coverage properties of confidence intervals from influence functions
  • Reproducing or extending the FLM 2021 theorem validation

Assumes this stack

PythonPyTorchtorch.funclgbm

Eval Learnings

What we learn from each eval. Updated as we investigate.


Eval 01: Parameter Recovery

Goal: Recover θ*(x) = [α*(x), β*(x)] for all families.

Results by family (n=2000, epochs=100):

FamilyRMSE(α)RMSE(β)Corr(α)Corr(β)Status
Linear0.100.100.961.00PASS
Gaussian0.090.080.971.00PASS
Logit0.090.030.981.00PASS
Poisson0.080.020.981.00PASS
NegBin0.120.040.960.99PASS
Gamma0.060.111.000.90PASS
Weibull0.210.011.001.00PASS
Gumbel0.050.030.991.00PASS
Tobit0.030.041.001.00PASS

Overall: 9/9 PASS with relaxed thresholds (RMSE < 0.3, Corr > 0.7).

Legacy issues (Logit-specific): Early stopping and flat loss surface were previously problematic with stricter thresholds. These are now mitigated with patience=50 default.

What helps: More data (n=5k+), patience=50+, family-specific DGP coefficients (smaller for Poisson/NegBin to avoid overflow).


Eval 02: Autodiff vs Calculus

Goal: Verify torch.func autodiff matches closed-form gradient/Hessian for all families.

Results by family (9 families):

FamilyGradientHessianStatus
Linear1e-160PASS
Logit1e-161e-16PASS
Poisson1e-91e-9PASS
Gamma1e-151e-15PASS
Gaussian1e-61e-6PASS (now theta_dim=3 with MLE for sigma)
Gumbel00PASS
TobitN/AN/AUses autodiff only (verified against Tobias/Purdue notes)
NegBin1e-91e-9PASS
Weibull1e-151e-15PASS

Fixed (2026-01-13):

  • NegBin: Now uses true NegBin NLL with lgamma terms (was using Poisson-like loss)
  • Gaussian: Now estimates sigma via MLE (theta_dim=3, gamma=log(sigma)), distinct from Linear
  • NegBin Hessian: w = r * mu * (r + y) / (r + mu)² (observed information)

Extended test: Also verified with estimated θ̂(x) from a trained model. Same results.

Poisson/NegBin note: The 1e-9 gradient errors are from the log(mu + 1e-10) numerical stability term. Acceptable.

Tobit verification (against Tobias, Purdue Econ 674 notes): Our loss function matches the standard formulation exactly. Uncensored: log(σ) + (y-μ)²/(2σ²). Censored: -log(Φ(-z)) which equals -log(1-Φ(z)) from the textbook. Our target='observed' marginal effect β·Φ(z) matches the PDF's ∂E(y|x)/∂x_j = β_j·Φ(xβ/σ). We use γ=log(σ) parameterization (ensures σ>0) rather than Olsen's (δ=1/σ, θ=β/σ) which provides global concavity - both valid, ours is more standard for neural nets.


Eval 03: Lambda Estimation

Goal: Verify EstimateLambda recovers Λ(x) = E[ℓ_θθ | X=x].

Result: PASS. Mean Frobenius error 0.12, all eigenvalues positive (min=0.035), 0/1000 non-PSD.

Note: The aggregate method returns mean(Hessians), losing x-dependence. This is stable but doesn't capture Λ(x) heterogeneity. For this DGP, the heterogeneity is small so it works.


Eval 04: Target Jacobian H_θ

Goal: Verify autodiff ∂H/∂θ matches closed-form oracle formulas.

Paper Reference: Theorem 2 (FLM 2021)

"√n(μ̂ - μ*) →_d N(0, E[ψ²]) where ψ = H_θ(X,θ) · Λ(X)⁻¹ · ℓ_θ(Z,θ)"

The influence function formula requires accurate H_θ. If H_θ is wrong, the entire IF correction is wrong → invalid standard errors.

Mathematical Objects Tested:

TargetFormulaH_θ
AverageParameterH(θ) = β[0, 1]
AME (Logit)H(θ) = σ(α+βt̃)(1-σ)β[σ(1-σ)(1-2σ)β, σ(1-σ)(1+(1-2σ)βt̃)]
AME (Poisson)H(θ) = β·exp(α+βt̃)[βμ, μ(1+βt̃)]
PredictionH(θ) = g⁻¹(α+βt̃)Depends on link

Test Matrix (9 parts):

PartDescriptionTests
1Target coverage (Logit)AvgParam, AME, Prediction
2Family coverage (AME)Linear, Logit, Poisson, Probit
3Edge casesθ = [±5, 1], tiny/large effects
4Batched vmap100 random θ per config
5Package Target classesAverageParameter, AME, CustomTarget
6All 9 familiesLinear, Logit, Poisson, Gamma, Weibull, NegBin, Gumbel, Beta, Probit
7Higher-dim θGaussian (3D), Tobit (3D), ZIP (4D)
8Varying θ(x)50 obs with θ varying as NN output
9Elasticityε = β·t̄ for Poisson

Pass Criteria:

  • Standard θ: max|err| < 1e-10 (machine precision)
  • Edge θ: max|err| < 1e-6 OR relative error < 1e-4
  • Batched: max|err| < 1e-8

Results: 9/9 parts PASS, overall max|err| ≈ 1e-14 (machine precision).


Eval 05: Influence Function Assembly ψ

Goal: Verify complete IF assembly matches Oracle formula.

Formula (Theorem 2):

ψ_i = H(θ_i) - H_θ(θ_i) · Λ(x_i)⁻¹ · ℓ_θ(y_i, t_i, θ_i)

Paper References:

  • Theorem 2: "√n(μ̂ - μ*) →_d N(0, E[ψ²])"
  • Theorem 3: "Var(ψ)/n gives valid SE"
  • Remark 4: "Λ(x) varies with x through θ(x)" - per-observation Lambda

DGP: Heterogeneous Logistic (Regime C - most stressful)

  • X ~ Uniform(-2, 2)
  • α*(x) = 0.5·sin(x), β*(x) = 1.0 + 0.5·x
  • T = β*(x) + N(0, 0.5²) [CONFOUNDED]
  • Y ~ Bernoulli(σ(α*(x) + β*(x)·T))
  • Target: AME at t̃=0, μ* ≈ 0.241

Test Rounds:

RoundDescriptionPass Criteria
AMechanical AssemblyCorr > 0.999, Max
BNeyman Orthogonalitybias ~ O(δ²) not O(δ), bias < 10·δ²
CVariance FormulaVar(ψ) > 0, SE > 0, SE < 1
DMulti-Seed CoverageCoverage in [88%, 98%] over 50 seeds
EAggregate vs Per-obs ΛDemonstrates U-shape limitation

Round Details:

  • Round A: Uses identical inputs (true θ*, same Λ) for oracle and package. Tests assembly code correctness.
  • Round B: Perturbs θ by δ, verifies bias scales as O(δ²). This is the Neyman orthogonality property - IF is first-order insensitive to θ estimation error.
  • Round C: Basic sanity checks on variance formula from Theorem 3.
  • Round D: Monte Carlo with 50 seeds, coverage should be 88-98% (allowing MC noise).
  • Round E: Compares aggregate Λ vs per-observation Λ(xᵢ). Confirms Remark 4: aggregate shows U-shaped SE ratio, per-obs is stable.

Results: 4/4 core rounds PASS. Round E confirms theoretical prediction.


Eval 06: Frequentist Coverage

Goal: Monte Carlo validation that CIs achieve valid coverage.

Paper Reference: Theorem 3 (FLM 2021)

"√n(μ̂ - μ*) →_d N(0, V) where V = E[ψ₀(W)²]"

Procedure:

For m = 1, ..., M:
    1. Generate data from canonical DGP (logit, confounded)
    2. Run inference() to get μ̂, SE, CI
    3. Check if true μ* is in CI

Settings (NON-NEGOTIABLE):

ParameterValueRationale
M50Detects systematic failure
n8000Binary families need ~2x data (1 bit/obs)
epochs200Proper convergence
patience50Matches eval_01
lambda_methodlgbmValidated 96% coverage
t_tilde0.0Must match DGP's mu_true()
n_jobs4Avoids OOM (11 workers caused OOM)

Pass Criteria:

MetricRangeTests
Coverage[85%, 99%]Valid CIs
SE ratio[0.5, 2.0]SE calibration
|Bias|< 0.1Unbiased estimation
|z_mean|< 0.5z-scores centered
z_std[0.5, 2.0]z-scores ~N(0,1)

Results (M=50, n=8000, lgbm):

Coverage: 96% (48/50)
SE Ratio: 0.914
Bias: -0.0064
z_mean: ~0
z_std: ~1

Status: PASS with 96% coverage.


Summary

EvalComponentStatus
01θ*(x) Recovery9/9 PASS
02Autodiff ∇ℓ, ∇²ℓ9/9 PASS
03Λ(x) EstimationPASS
04H_θ Jacobian9/9 PASS
05ψ Assembly4/4 PASS
06Coverage (96%)PASS

All components of Theorem 2 validated end-to-end.

What's inside

6 eval sections with tables, pass criteria, results, and a summary table.

Change this for your project

  • Replace rawatpranjal/deep-inference with your own repository name
  • Replace n=8000, epochs=200, patience=50 with your own simulation parameters
  • Replace lambda_method: lgbm with your preferred lambda estimation method

Where it goes

Keep alongside your test suite. Used to define and score model evaluations.

Worth borrowing

  • Structuring evals as pass/fail tables with explicit thresholds and rationale
  • Including a 'what helps' section with concrete data size and hyperparameter recommendations
  • Cross-referencing paper theorems (FLM 2021) to tie each eval to a specific claim

Related Documents