[Numpy-discussion] Weighted covariance.

Charles R Harris charlesr.harris at gmail.com
Wed Apr 29 16:51:15 EDT 2015


The weighted covariance function in PR #4960
<https://github.com/numpy/numpy/pull/4960> is evolving to the following,
where frequency weights are `f` and reliability weights are `a`.

Assume that the observations are in the columns of the observation matrix.
the steps to compute the weighted covariance are as follows::

    >>> w = f * a
    >>> v1 = np.sum(w)
    >>> v2 = np.sum(a * w)
    >>> m -= np.sum(m * w, axis=1, keepdims=True) / v1
    >>> cov = np.dot(m * w, m.T) * v1 / (v1**2 - ddof * v2)

    Note that when ``a == 1``, the normalization factor ``v1 / (v1**2 -
ddof * v2)`` goes over to ``1 / (np.sum(f) - ddof)``
    as it should.

This is probably a good time for comments from all the kibitzers out there.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150429/6d80e204/attachment.html>


More information about the NumPy-Discussion mailing list