Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gplepage committed Dec 5, 2024
1 parent 5c718bc commit 77cf0d7
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 64 deletions.
Binary file modified doc/html/.doctrees/environment.pickle
Binary file not shown.
Binary file modified doc/html/.doctrees/gvar.doctree
Binary file not shown.
2 changes: 1 addition & 1 deletion doc/html/gvar.html
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ <h2>Functions<a class="headerlink" href="#functions" title="Link to this heading
<dt class="sig sig-object py" id="gvar.sample">
<span class="sig-prename descclassname"><span class="pre">gvar.</span></span><span class="sig-name descname"><span class="pre">sample</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">g</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">eps</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">svdcut</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">uniform</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">nbatch</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'rbatch'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#gvar.sample" title="Link to this definition">¶</a></dt>
<dd><p>Generate random sample(s) from distribution <code class="docutils literal notranslate"><span class="pre">g</span></code>.</p>
<p>The <a class="reference internal" href="#gvar.GVar" title="gvar.GVar"><code class="xref py py-class docutils literal notranslate"><span class="pre">gvar.GVar</span></code></a>s in array (or dictionary) <code class="docutils literal notranslate"><span class="pre">g</span></code> collectively define a
<p>The <a class="reference internal" href="#gvar.GVar" title="gvar.GVar"><code class="xref py py-class docutils literal notranslate"><span class="pre">gvar.GVar</span></code></a>\s in array (or dictionary) <code class="docutils literal notranslate"><span class="pre">g</span></code> collectively define a
multidimensional Gaussian distribution. <code class="docutils literal notranslate"><span class="pre">sample(g)</span></code> returns
an array (or dictionary) containing random samples drawn from that
distribution, with correlations intact:</p>
Expand Down
88 changes: 44 additions & 44 deletions src/gvar/_gvarcore.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ cdef class GVar:
return old

def __format__(self, spec):
""" Format strings for |GVar|\s.
""" Format strings for |GVar|\\s.
Support is provided for standard presentation formats
normally used for floats including: ``'e'``, ``'f'``,
Expand Down Expand Up @@ -830,20 +830,20 @@ cdef class GVar:
return -self

def deriv(GVar self, x):
""" Derivative of ``self`` with respest to primary |GVar|\s in ``x``.
""" Derivative of ``self`` with respest to primary |GVar|\\s in ``x``.
All |GVar|\s are constructed from primary |GVar|\s (see
All |GVar|\\s are constructed from primary |GVar|\\s (see
:func:`gvar.is_primary`). ``self.deriv(x)`` returns the
partial derivative of ``self`` with respect to
primary |GVar| ``x``, holding all of the other
primary |GVar|\s constant.
primary |GVar|\\s constant.
Args:
x: A primary |GVar| or an array of primary |GVar|\s.
x: A primary |GVar| or an array of primary |GVar|\\s.
Returns:
Derivatives of ``self`` with respect to the
|GVar|\s in ``x``. The result has the same
|GVar|\\s in ``x``. The result has the same
shape as ``x``.
"""
cdef INTP_TYPE i, ider
Expand Down Expand Up @@ -960,17 +960,17 @@ cdef class GVar:
return ft % (v, sep, dv)

def partialvar(self,*args):
""" Compute partial variance due to |GVar|\s in ``args``.
""" Compute partial variance due to |GVar|\\s in ``args``.
This method computes the part of ``self.var`` due to the |GVar|\s
in ``args``. If ``args[i]`` is correlated with other |GVar|\s, the
This method computes the part of ``self.var`` due to the |GVar|\\s
in ``args``. If ``args[i]`` is correlated with other |GVar|\\s, the
variance coming from these is included in the result as well. (This
last convention is necessary because variances associated with
correlated |GVar|\s cannot be disentangled into contributions
correlated |GVar|\\s cannot be disentangled into contributions
corresponding to each variable separately.)
Args:
args[i]: A |GVar| or array/dictionary of |GVar|\s
args[i]: A |GVar| or array/dictionary of |GVar|\\s
contributing to the partial variance.
Returns:
Expand Down Expand Up @@ -1003,7 +1003,7 @@ cdef class GVar:
if ai is None:
continue
else:
assert ai.cov is self.cov,"Incompatible |GVar|\s."
assert ai.cov is self.cov,"Incompatible |GVar|\\s."
iset.update(ai.d.indices())

# b) collect indices connected to args[i].der indices by self.cov
Expand Down Expand Up @@ -1040,18 +1040,18 @@ cdef class GVar:
return md.dot(self.cov.dot(md))

def partialsdev(self,*args):
""" Compute partial standard deviation due to |GVar|\s in ``args``.
""" Compute partial standard deviation due to |GVar|\\s in ``args``.
This method computes the part of ``self.sdev`` due to the |GVar|\s
in ``args``. If ``args[i]`` is correlated with other |GVar|\s, the
This method computes the part of ``self.sdev`` due to the |GVar|\\s
in ``args``. If ``args[i]`` is correlated with other |GVar|\\s, the
standard deviation coming from these is included in the result as
well. (This last convention is necessary because variances
associated with correlated |GVar|\s cannot be disentangled into
associated with correlated |GVar|\\s cannot be disentangled into
contributions corresponding to each variable separately.)
:param args[i]: Variables contributing to the partial standard
deviation.
:type args[i]: |GVar| or array/dictionary of |GVar|\s
:type args[i]: |GVar| or array/dictionary of |GVar|\\s
:returns: Partial standard deviation due to ``args``.
"""
ans = self.partialvar(*args)
Expand All @@ -1063,14 +1063,14 @@ cdef class GVar:
A *primary* |GVar| is one created using :func:`gvar.gvar` (or a
function of such a variable). A *derived* |GVar| is one that
is constructed from arithmetic expressions and functions that
combine multiple primary |GVar|\s. The standard deviations for
all |GVar|\s originate with the primary |GVar|\s.
combine multiple primary |GVar|\\s. The standard deviations for
all |GVar|\\s originate with the primary |GVar|\\s.
In particular, ::
z = z.mean + sum_p (p - p.mean) * dz/dp
is true for any |GVar| ``z``, where the sum is over all primary
|GVar|\s ``p``.
|GVar|\\s ``p``.
"""
return self.d.size == 1

Expand All @@ -1086,7 +1086,7 @@ cdef class GVar:

property der:
""" Array of derivatives with respect to underlying (original)
|GVar|\s.
|GVar|\\s.
"""
def __get__(self):
return self.d.toarray(len(self.cov))
Expand Down Expand Up @@ -1154,16 +1154,16 @@ _RE3 = re.compile(r"([-+]?)([0-9]*)[.]?([0-9]*)\s*\(([0-9]+)\)")
_RE3a = re.compile(r"([-+]?[0-9]*[.]?[0-9]*)\s*\(([.0-9]+)\)")

class GVarFactory:
""" Creates one or more new |GVar|\s.
""" Creates one or more new |GVar|\\s.
``gvar.gvar`` is an object of type :class:`gvar.GVarFactory`.
Each of the following creates new |GVar|\s:
Each of the following creates new |GVar|\\s:
.. function:: gvar.gvar(x, xsdev)
:noindex:
Returns a |GVar| with mean ``x`` and standard deviation ``xsdev``.
Returns an array of |GVar|\s if ``x`` and ``xsdev`` are arrays
Returns an array of |GVar|\\s if ``x`` and ``xsdev`` are arrays
with the same shape; the shape of the result is the same as the
shape of ``x``. Returns a |BufferDict| if ``x`` and ``xsdev``
are dictionaries with the same keys and layout; the result has
Expand All @@ -1172,20 +1172,20 @@ class GVarFactory:
.. function:: gvar.gvar(x, xcov)
:noindex:
Returns an array of |GVar|\s with means given by array ``x`` and a
Returns an array of |GVar|\\s with means given by array ``x`` and a
covariance matrix given by array ``xcov``, where ``xcov.shape =
2*x.shape``; the result has the same shape as ``x``. Returns a
|BufferDict| if ``x`` and ``xcov`` are dictionaries, where the
keys in ``xcov`` are ``(k1,k2)`` for any keys ``k1`` and ``k2``
in ``x``. Returns a single |GVar| if ``x`` is a number and
``xcov`` is a one-by-one matrix. The layout for ``xcov`` is
compatible with that produced by :func:`gvar.evalcov` for
a single |GVar|, an array of |GVar|\s, or a dictionary whose
values are |GVar|\s and/or arrays of |GVar|\s. Therefore
``gvar.gvar(gvar.mean(g), gvar.evalcov(g))`` creates |GVar|\s
with the same means and covariance matrix as the |GVar|\s
a single |GVar|, an array of |GVar|\\s, or a dictionary whose
values are |GVar|\\s and/or arrays of |GVar|\\s. Therefore
``gvar.gvar(gvar.mean(g), gvar.evalcov(g))`` creates |GVar|\\s
with the same means and covariance matrix as the |GVar|\\s
in ``g`` provided ``g`` is a single |GVar|, or an array or
dictionary of |GVar|\s.
dictionary of |GVar|\\s.
.. function:: gvar.gvar(x, xcov, verify=True)
:noindex:
Expand All @@ -1205,9 +1205,9 @@ class GVarFactory:
xcov = [[1,1,0], [1,2,0], [0,0,3]]
can be decomposed into two blocks. This decomposition saves memory,
and can make later manipulations of the resulting |GVar|\s
and can make later manipulations of the resulting |GVar|\\s
faster. This is at the expense of extra processing to
create the |GVar|\s. Setting keyword ``fast=True`` prevents
create the |GVar|\\s. Setting keyword ``fast=True`` prevents
``gvar.gvar`` from doing this, which would make sense, for example,
if it was known ahead of time that ``xcov`` has no sub-blocks. The
default is ``fast=False``. Either choice gives correct answers;
Expand Down Expand Up @@ -1236,27 +1236,27 @@ class GVarFactory:
Returns a dictionary (:class:`BufferDict`) ``b`` where
``b[k] = gvar.gvar(xdict[k])`` for every key in dictionary ``xdict``.
The values in ``xdict``, therefore, can be strings, tuples or
|GVar|\s (see above), or arrays of these.
|GVar|\\s (see above), or arrays of these.
.. function:: gvar.gvar(xarray)
:noindex:
Returns an array ``a`` having the same shape as ``xarray`` where
every element ``a[i...] = gvar.gvar(xarray[i...])``. The values in
``xarray``, therefore, can be strings, tuples or |GVar|\s (see
``xarray``, therefore, can be strings, tuples or |GVar|\\s (see
above).
.. function:: gvar.gvar(ymean, ycov, x, xycov)
:noindex:
Returns a 1-d array of |GVar|\s ``y[i]`` constructed from the 1-d array
Returns a 1-d array of |GVar|\\s ``y[i]`` constructed from the 1-d array
of mean values ``ymean`` and the 2-d covariance matrix ``ycov``. The
``y[i]`` are correlated with the primary |GVar|\s in 1-d array ``x``.
``y[i]`` are correlated with the primary |GVar|\\s in 1-d array ``x``.
The ``x-y`` covariance matrix is ``xycov`` whose shape
is ``x.shape + y.shape``. Note that this changes the |GVar|\s
is ``x.shape + y.shape``. Note that this changes the |GVar|\\s
in ``x`` (because they are correlated with the ``y[i]``); it
has no effect on the variance or on correlations between
different ``x[i]``\s.
different ``x[i]``\\s.
"""
def __init__(self,cov=None):
if cov is None:
Expand Down Expand Up @@ -1577,16 +1577,16 @@ class GVarFactory:
def gvar_function(x, double f, dfdx):
""" Create a |GVar| for function f(x) given f and df/dx at x.
This function creates a |GVar| corresponding to a function of |GVar|\s ``x``
This function creates a |GVar| corresponding to a function of |GVar|\\s ``x``
whose value is ``f`` and whose derivatives with respect to each
``x`` are given by ``dfdx``. Here ``x`` can be a single |GVar|,
an array of |GVar|\s (for a multidimensional function), or
a dictionary whose values are |GVar|\s or arrays of |GVar|\s, while
an array of |GVar|\\s (for a multidimensional function), or
a dictionary whose values are |GVar|\\s or arrays of |GVar|\\s, while
``dfdx`` must be a float, an array of floats, or a dictionary
whose values are floats or arrays of floats, respectively.
This function is useful for creating functions that can accept
|GVar|\s as arguments. For example, ::
|GVar|\\s as arguments. For example, ::
import math
import gvar as gv
Expand All @@ -1600,11 +1600,11 @@ def gvar_function(x, double f, dfdx):
return math.sin(x)
creates a version of ``sin(x)`` that works with either floats or
|GVar|\s as its argument. This particular function is unnecessary since
|GVar|\\s as its argument. This particular function is unnecessary since
it is already provided by :mod:`gvar`.
:param x: Point at which the function is evaluated.
:type x: |GVar|, array of |GVar|\s, or a dictionary of |GVar|\s
:type x: |GVar|, array of |GVar|\\s, or a dictionary of |GVar|\\s
:param f: Value of function at point ``gvar.mean(x)``.
:type f: float
Expand Down
2 changes: 1 addition & 1 deletion src/gvar/cspline.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class CSpline:
to use smaller values.
warn (bool): If ``True``, warnings are generated
when the spline function is called for ``x`` values that
fall outside of the original range of ``xknot``\s used to
fall outside of the original range of ``xknot``\\s used to
define the spline. Default value is ``False``,
which means out-of-range warnings are suppressed.
alg (str): Spline algorithm used, which is one of:
Expand Down
28 changes: 14 additions & 14 deletions src/gvar/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def det(a):
Args:
a: Two-dimensional, square matrix/array of numbers
and/or :class:`gvar.GVar`\s.
and/or :class:`gvar.GVar`\\s.
Returns:
Deterimant of the matrix.
Expand All @@ -41,7 +41,7 @@ def slogdet(a):
Args:
a: Two-dimensional, square matrix/array of numbers
and/or :class:`gvar.GVar`\s.
and/or :class:`gvar.GVar`\\s.
Returns:
Tuple ``(s, logdet)`` where the determinant of matrix ``a`` is
Expand All @@ -64,8 +64,8 @@ def eigvalsh(a, eigvec=False):
Args:
a: Two-dimensional, square Hermitian matrix/array of numbers
and/or :class:`gvar.GVar`\s. Array elements must be
real-valued if `gvar.GVar`\s are involved (i.e., symmetric
and/or :class:`gvar.GVar`\\s. Array elements must be
real-valued if `gvar.GVar`\\s are involved (i.e., symmetric
matrix).
eigvec (bool): If ``True``, method returns a tuple of arrays
``(val, vec)`` where ``val[i]`` are the
Expand Down Expand Up @@ -95,8 +95,8 @@ def eigh(a, eigvec=True, rcond=None):
Args:
a: Two-dimensional, square Hermitian matrix/array of numbers
and/or :class:`gvar.GVar`\s. Array elements must be
real-valued if `gvar.GVar`\s are involved (i.e., symmetric
and/or :class:`gvar.GVar`\\s. Array elements must be
real-valued if `gvar.GVar`\\s are involved (i.e., symmetric
matrix).
eigvec (bool): If ``True`` (default), method returns a tuple
of arrays ``(val, vec)`` where ``val[i]`` are the
Expand Down Expand Up @@ -150,11 +150,11 @@ def eigh(a, eigvec=True, rcond=None):
return val

def svd(a, compute_uv=True, rcond=None):
""" svd decomposition of matrix ``a`` containing |GVar|\s.
""" svd decomposition of matrix ``a`` containing |GVar|\\s.
Args:
a: Two-dimensional matrix/array of numbers
and/or :class:`gvar.GVar`\s.
and/or :class:`gvar.GVar`\\s.
compute_uv (bool): It ``True`` (default), returns
tuple ``(u,s,vT)`` where matrix ``a = u @ np.diag(s) @ vT``
where matrices ``u`` and ``vT`` satisfy ``u.T @ u = 1``
Expand Down Expand Up @@ -226,7 +226,7 @@ def svd(a, compute_uv=True, rcond=None):


def lstsq(a, b, rcond=None, weighted=False, extrainfo=False):
""" Least-squares solution ``x`` to ``a @ x = b`` for |GVar|\s.
""" Least-squares solution ``x`` to ``a @ x = b`` for |GVar|\\s.
Here ``x`` is defined to be the solution that minimizes ``||b - a @ x||``.
If ``b`` has a covariance matrix, another option is to weight the
Expand All @@ -236,8 +236,8 @@ def lstsq(a, b, rcond=None, weighted=False, extrainfo=False):
obtain the weighted-least-squares solution.
Args:
a : Matrix/array of shape ``(M,N)`` containing numbers and/or |GVar|\s.
b : Vector/array of shape ``(M,)`` containing numbers and/or |GVar|\s.
a : Matrix/array of shape ``(M,N)`` containing numbers and/or |GVar|\\s.
b : Vector/array of shape ``(M,)`` containing numbers and/or |GVar|\\s.
rcond (float): Cutoff for singular values of ``a``. Singular values
smaller than ``rcond`` times the maximum eigenvalue are ignored.
Default (``rcond=None``) is ``max(M,N)`` times machine precision.
Expand Down Expand Up @@ -299,7 +299,7 @@ def inv(a):
Args:
a: Two-dimensional, square matrix/array of numbers
and/or :class:`gvar.GVar`\s.
and/or :class:`gvar.GVar`\\s.
Returns:
The inverse of matrix ``a``.
Expand All @@ -319,9 +319,9 @@ def solve(a, b):
Args:
a: Two-dimensional, square matrix/array of numbers
and/or :class:`gvar.GVar`\s.
and/or :class:`gvar.GVar`\\s.
b: One-dimensional vector/array of numbers and/or
:class:`gvar.GVar`\s, or an array of such vectors.
:class:`gvar.GVar`\\s, or an array of such vectors.
Requires ``b.shape[0] == a.shape[1]``.
Returns:
Expand Down
6 changes: 3 additions & 3 deletions src/gvar/pade.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# from scipy.interpolate import pade as _scipy_pade

class Pade(object):
""" Pade approximant to ``sum_i f[i] x**i`` for ``GVar``\s.
""" Pade approximant to ``sum_i f[i] x**i`` for ``GVar``\\s.
The ``order=(m,n)`` Pade approximant to a series given by
``sum_i f[i] * x**i`` is the ratio of polynomials of order ``m``
Expand All @@ -33,7 +33,7 @@ class Pade(object):
coefficients used in the numerator and denominator are given by ``pade.num.c``
and ``pade.den.c``, respectively.
Elements in the series ``f[i]`` may be numbers or :class:`gvar.GVar`\s.
Elements in the series ``f[i]`` may be numbers or :class:`gvar.GVar`\\s.
When the latter appear, the code uses an SVD algorithm (see :func:`pade_svd`)
to deal with the imprecision in the input data. It automatically reduces
the order of the approximant if the extraction of Pade coefficients
Expand Down Expand Up @@ -160,7 +160,7 @@ def __call__(self, x):
return self.num(x) / self.den(x)

def pade_gvar(f, m, n, rtol='gavg'):
""" ``(m,n)`` Pade approximant to ``sum_i f[i] x**i`` for ``GVar``\s.
""" ``(m,n)`` Pade approximant to ``sum_i f[i] x**i`` for ``GVar``\\\s.
The ``(m,n)`` Pade approximant to a series given by
``sum_i f[i] * x**i`` is the ratio of polynomials of order ``m``
Expand Down
Loading

0 comments on commit 77cf0d7

Please sign in to comment.