Skip to content

Instantly share code, notes, and snippets.

@davidchall
Created March 16, 2016 21:18
Show Gist options
  • Save davidchall/f58781741e74006c63e9 to your computer and use it in GitHub Desktop.
Save davidchall/f58781741e74006c63e9 to your computer and use it in GitHub Desktop.
Weighted mean of a vector using covariances

Given a set of covariance matrices pcov of shape (n,m,m) and a set of parameter estimates popt of shape (n,m), the mean parameter estimates are:

weight = np.linalg.inv(pcov)
pcov_mean = np.linalg.inv(np.sum(weight, axis=0))
popt_wgt = np.einsum('ijk,ik->ij', weight, popt)
popt_mean = np.dot(pcov_mean, np.sum(popt_wgt, axis=0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment