Skip to content

Commit

Permalink
Document the parameters and return-types of integrand_wrap_moments
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkraemer committed Jan 3, 2024
1 parent 273df6f commit f31422d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
30 changes: 26 additions & 4 deletions matfree/hutchinson.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ def hutchinson(integrand_fun, /, sample_fun):
Returns
-------
A function that maps a random key to an estimate.
This function can be jitted, vmapped, or looped over as the user desires.
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.
"""

Expand Down Expand Up @@ -94,8 +95,29 @@ def integrand(vec, *parameters):
return integrand


def integrand_wrap_moments(integrand_fun, /, moments=(1, 2)):
"""Wrap an integrand into another integrand that computes moments."""
def 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 array ``x``,
usually, with data-type ``float``
(but that depends on the wrapped integrand).
For example, ``moments=4``, ``moments=(1,2)``,
or ``moments={"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.
"""

def integrand_wrapped(vec, *parameters):
Qs = integrand_fun(vec, *parameters)
Expand Down
2 changes: 1 addition & 1 deletion tutorials/3_uncertainty_quantification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Uncertainty quantification for trace estimation.
"""Implement uncertainty quantification for trace estimation.
Computing higher moments of trace-estimates can easily
be turned into uncertainty quantification.
Expand Down

0 comments on commit f31422d

Please sign in to comment.