Re: How to derive Covariance of Dirichlet distirubtion from its variance

marc nicole <[email protected]> Tue, 19 Dec 2023 18:40:23 +0100
Newsgroups gmane.comp.python.scientific.devel
Message-ID <CAGJtH9TGF07dkZ=KLGOR0ZGN7_Q1TUTptDmaQxDrQvAVpUqLOA@mail.gmail.com>
Thanks, how about me exposing it as follows:

import numpy as npdef covariance_dirichlet(X,alpha):
  cov_list = []
  sigma = np.sum(alpha)
  for i in range(0,len(X)):
    for j in range(i+1,len(X)):
      if i == j:
        iter_val_num = np.multiply(X[i],sigma)-np.power(X[i],2)#**2
      else:
        iter_val_num = -np.multiply(X[i],X[j])#a*b
      iter_res = iter_val_num/(sigma**2)*(sigma+1)
      cov_list.append(iter_res)
  return np.reshape(np.array(cov_list),(-1,len(X)))print(covariance_dirichlet([[0.2,
0.2, 0.6,0.8],[0.2, 0.2, 0.6,0.8]],[0.4, 5, 15,11]))


Could you provide opinion on this implementation? or how to improve it
/ refactor it ?


Le lun. 18 déc. 2023 à 21:38, Robert Kern <[email protected]> a écrit :

> We don't expose it, but here is a reference for the formula:
>
>
> https://www.statlect.com/probability-distributions/Dirichlet-distribution#hid10
>
> On Mon, Dec 18, 2023 at 3:30 PM marc nicole <[email protected]> wrote:
>
>> Hello,
>>
>> Using the Dirichlet class I can obtain the variance of an array using
>>
>> from scipy.stats import dirichletalpha = np.array([0.4, 5, 15*])
>> *dirichlet.var(alpha)
>>
>> BUT how to derive the covariance?
>> thanks.
>> _______________________________________________
>> 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]
>>
>
>
> --
> 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]
>

_______________________________________________
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]