Closed mkhattab940 closed 6 years ago
I need the exact details. The PDF for chi-squared is 'obviously' positive. And the relation to normal that I know is only asymptotic, not exact.
Well, here is our implementation of chi-squared:
def chiSq_iid(n nat, mean real, stdev prob):
q <~ plate _ of n: normal(mean,stdev)
return summate i from 0 to size(q):
((q[i]-mean)/stdev)^2
As far as I can tell, even if normal wasn't returning reals, the term in the summate would be because of the subtraction before the division. Isn't the option to cast to prob then?
Yes. The squaring does ensure the results are positive, so this is safe.
Just to clarify, even though its output is strictly positive, it won't let me explicitly type it as prob without a real2prob. Shall I give them real return types, then?
No, use real2prob
.
Hi @JacquesCarette
Referring to the convo here about making sure chiSq returns a prob, you said:
"Yes, please make sure all of these return prob. There should be no need to cast, as it should be obvious that they are all positive."
I'm unsure how to get any of the chi distributions to return prob values without a cast since these distributions are built up from the normal distribution (which returns real values) and their implementations use mathematical operators which results in a real when applied to reals/probs.
Is there some other way to ensure these distributions returns a prob type?