1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use crateFloat;
/// Trait for stochastic estimators that combine Taylor jet coefficients into
/// a per-direction sample.
///
/// Given the Taylor coefficients `(c0, c1, c2)` from propagating a random
/// direction through a tape, an `Estimator` produces a scalar sample whose
/// expectation (over random directions with `E[vv^T] = I`) equals the
/// desired quantity.
/// Hutchinson trace estimator: estimates tr(H) = Laplacian.
///
/// Each sample is `2 * c2 = v^T H v`. Since `E[v^T H v] = tr(H)` when
/// `E[vv^T] = I`, the mean of these samples converges to the Laplacian.
;
/// Estimates `||∇f||²` (squared gradient norm).
///
/// Each sample is `c1² = (∇f·v)²`. Since `E[(∇f·v)²] = ∇f^T E[vv^T] ∇f = ||∇f||²`
/// when `E[vv^T] = I`, the mean converges to the squared gradient norm.
///
/// Useful for score matching loss functions where `||∇ log p||²` appears.
;