matfree.hutchinson
matfree.hutchinson
Hutchinson-style estimation.
matfree.hutchinson.hutchinson(integrand_fun, /, sample_fun)
Construct Hutchinson's estimator.
Parameters:
-
integrand_fun
–The integrand function. For example, the return-value of integrand_trace. But any other integrand works, too.
-
sample_fun
–The sample function. Usually, either sampler_normal or sampler_rademacher.
Returns:
-
integrand_fun
–A function that maps a random key to an estimate. This function can be jitted, vmapped, or looped over as the user desires.
matfree.hutchinson.integrand_diagonal(matvec)
Construct the integrand for estimating the diagonal.
When plugged into the Monte-Carlo estimator,
the result will be an Array or PyTree of Arrays with the
same tree-structure as
matvec(*args_like)
where *args_like
is an argument of the sampler.
matfree.hutchinson.integrand_frobeniusnorm_squared(matvec)
Construct the integrand for estimating the squared Frobenius norm.
matfree.hutchinson.integrand_trace(matvec)
Construct the integrand for estimating the trace.
matfree.hutchinson.integrand_trace_and_diagonal(matvec)
Construct the integrand for estimating the trace and diagonal jointly.
matfree.hutchinson.integrand_wrap_moments(integrand_fun, /, moments)
Wrap an integrand into another integrand that computes moments.
Parameters:
-
integrand_fun
–Any integrand function compatible with Hutchinson-style estimation.
-
moments
–Any Pytree (tuples, lists, dictionaries) whose leafs that are valid inputs to
lambda m: x**m
for an arrayx
, usually, with data-typefloat
(but that depends on the wrapped integrand). For example,moments=4
,moments=(1,2)
, ormoments={"a": 1, "b": 2}
.
Returns:
-
integrand_fun
–An integrand function compatible with Hutchinson-style estimation whose output has a PyTree-structure that mirrors the structure of the
moments
argument.
matfree.hutchinson.sampler_normal(*args_like, num)
Construct a function that samples from a standard-normal distribution.
matfree.hutchinson.sampler_rademacher(*args_like, num)
Construct a function that samples from a Rademacher distribution.