2

I am trying to translate some Julia code to Python. This is code for the multinomial distribution, and I am stuck in the last part of the it. I don't know how to write it in Python, because I want to know if there is a package that will do what I want. I don't know if I can do this using SciPy.stats, because the documentation seems kind of limited.

Here you will find a part of the Julia code where I'm stuck: x1s is an array, x also is an array, OrthoNNDist is a name of a struct:

Base.length(d::OrthoNNDist) = length(d.x0)

Distributions.rand(d::OrthoNNDist) = rand(d.x1s)

Distributions.pdf(d::OrthoNNDist, x::Vector) = x in d.x1s ? d.prob : 0.0
Distributions.pdf(d::OrthoNNDist) = fill(d.prob, size(d.x1s))
Distributions.logpdf(d::OrthoNNDist, x::Vector) = log(pdf(d, x))
phipsgabler
  • 20,535
  • 4
  • 40
  • 60
M.HANHASSE
  • 129
  • 1
  • 6
  • 2
    This question is not too broad. It's a perfectly reasonable question as to how you'd implement a code that works with all probability distributions defined in Python scientific codes. In Julia, just a few lines like that are sufficient due to multiple dispatch and Distributions.jl fallback handling. So this user is just interested to know if you could write a code that is generic so that any SciPy or etc. package defined probability distribution will work no matter what. I think people want to close just because there isn't an easy (or any) answer. – Chris Rackauckas Jun 18 '19 at 01:17
  • thanks at least i knew that i'm not alone, i've been struggling with this code for a while and now i think i'll be back to `Julia`and call some functions by `PyCall`because i don't know how to do this piece of code using `Python` – M.HANHASSE Jun 18 '19 at 23:04
  • 1
    Hei @M.HANHASSE, I took the liberty to add some more punctuation to your text, and make it more easily readable. Please check that I didn't mess up anything. Also, what is you exact question: how to define a "distribution object" in Python that works with generic statistical functions in SciPy? – phipsgabler Jun 19 '19 at 11:23
  • My advice to OP is to try reading the documentation again. I'm pretty sure any kind of statistical stuff is much more extensively developed in Python, due to the greater age of Scipy etc and the greater number of people developing and using it; multinomial is one of the basic distributions and so it seems implausible to me that it is not included in Scipy. – Robert Dodier Jun 19 '19 at 17:52
  • @RobertDodier the Scipy documentation i've read it and i wouldn't ask a question without seing the documentation – M.HANHASSE Jun 20 '19 at 23:41

0 Answers0