Re: How to derive Covariance of Dirichlet distirubtion from its variance
Robert Kern <[email protected]> Tue, 19 Dec 2023 13:31:17 -0500
| Newsgroups | gmane.comp.python.scientific.devel |
|---|---|
| Message-ID | <CAF6FJitt8phUJJbtURTf5DHL_XShcGubqqkkQgS29gytit09wA@mail.gmail.com> |
On Tue, Dec 19, 2023 at 1:18 PM marc nicole <[email protected]> wrote: > How you manage to write cov_dirichlet ? > Based on which definition of the dirichlet function ? > A straightforward implementation of the math of the formula that I referenced, but following the conventions of `scipy.stats.dirichlet`. > (np.diag and np.multiply.outer got me confused) could you explain more? > Given a vector `x`, `np.diag(x)` will make a diagonal matrix with that vector on the diagonal and 0s elsewhere. `np.multiply.outer(alpha, alpha)` computes the outer product of the vector `alpha`; that is, the matrix `P` such that `P[i, j] = alpha[i] * alpha[j]`. The covariance formula has a form where all the entries can be formed by an outer product of the `alpha` vector, except that the diagonal has an extra term added onto it. > also the function is supposed to take two random variables Xi and Xj to > measure their covariance not just alpha (what is alpha anyways?) > That isn't what you asked for originally. If you think you need those because of the formula I referenced, I think you are misreading it. You do not need an explicit `X` anywhere in the code to compute the covariance of a Dirichlet distribution specified by the `alpha` vector. The `cov(X_i, X_j)` on the left hand side is just traditional math notation to specify the `[i, j]` element of the covariance matrix. Also could alpha be multi dimensional ? > By which you mean that you would like to write a version that computes the covariance matrices for a number of different `alpha` vectors in batch? One could write a version, but I won't. -- Robert Kern _______________________________________________ SciPy-Dev mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/scipy-dev.python.org/ Member address: [email protected]