matfree.stochtrace
matfree.stochtrace
Stochastic estimation of traces, diagonals, and more.
matfree.stochtrace.estimator(integrand: Callable, /, sampler: Callable) -> Callable
Construct a stochastic trace-/diagonal-estimator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
integrand
|
Callable
|
The integrand function. For example, the return-value of integrand_trace. But any other integrand works, too. |
required |
sampler
|
Callable
|
The sample function. Usually, either sampler_normal or sampler_rademacher. |
required |
Returns:
Type | Description |
---|---|
estimate
|
A function that maps a random key to an estimate. This function can be compiled, vectorised, differentiated, or looped over as the user desires. |
Source code in matfree/stochtrace.py
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 |
|
matfree.stochtrace.integrand_diagonal()
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.
Source code in matfree/stochtrace.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
matfree.stochtrace.integrand_frobeniusnorm_squared()
Construct the integrand for estimating the squared Frobenius norm.
Source code in matfree/stochtrace.py
85 86 87 88 89 90 91 92 93 |
|
matfree.stochtrace.integrand_trace()
Construct the integrand for estimating the trace.
Source code in matfree/stochtrace.py
59 60 61 62 63 64 65 66 67 68 |
|
matfree.stochtrace.integrand_trace_and_diagonal()
Construct the integrand for estimating the trace and diagonal jointly.
Source code in matfree/stochtrace.py
71 72 73 74 75 76 77 78 79 80 81 82 |
|
matfree.stochtrace.integrand_wrap_moments(integrand, /, moments)
Wrap an integrand into another integrand that computes moments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
integrand
|
Any integrand function compatible with Hutchinson-style estimation. |
required | |
moments
|
Any Pytree (tuples, lists, dictionaries) whose leafs that are
valid inputs to |
required |
Returns:
Type | Description |
---|---|
integrand
|
An integrand function compatible with Hutchinson-style estimation whose
output has a PyTree-structure that mirrors the structure of the |
Source code in matfree/stochtrace.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
matfree.stochtrace.sampler_normal(*args_like, num)
Construct a function that samples from a standard-normal distribution.
Source code in matfree/stochtrace.py
130 131 132 |
|
matfree.stochtrace.sampler_rademacher(*args_like, num)
Construct a function that samples from a Rademacher distribution.
Source code in matfree/stochtrace.py
135 136 137 |
|