[SciPy-User] scipy.stats.truncnorm behaviour
Wed Apr 3 07:42:07 CDT 2013
On Wed, Apr 3, 2013 at 8:05 AM, <firstname.lastname@example.org> wrote:
> On Wed, Apr 3, 2013 at 6:54 AM, Joe <email@example.com> wrote:
>> <josef.pktd <at> gmail.com> writes:
>>> On Tue, Apr 2, 2013 at 12:39 PM, Pauli Virtanen <pav <at> iki.fi> wrote:
>>> > 02.04.2013 19:36, Joe Mellor kirjoitti:
>>> >> I have been using both scipy.stats.norm and scipy.stats.truncnorm and
>>> >> have found some (to me) unexpected differences in their behaviour.
>>> >> The differences are in how each handles the size parameter given to the
>>> >> rvs method.
>>> > [clip]
>>> > This seems related?
>>> > https://github.com/scipy/scipy/pull/463
>>> I think that fixed this case (when the problem is in _ppf)
>>> It looks like a case of http://projects.scipy.org/scipy/ticket/793
>>> problems with vectorized parameters when bounds depend on the parameters
>>> > --
>>> > Pauli Virtanen
>>> > _______________________________________________
>>> > SciPy-User mailing list
>>> > SciPy-User <at> scipy.org
>>> > http://mail.scipy.org/mailman/listinfo/scipy-user
>> Apologises for my ignorance, but I'm confused how 463 fixes a problem with _ppf?
>> As far as I could tell the diff of the fix didn't touch _ppf, only functions not
>> on the code path for the problem I raised?
>> 793 appears to be about having array value arguments to methods like ppf and
>> moment. I think truncnorm may also suffer from this bug, but is it not different
>> from the size parameter problem?
>> My understanding is that rvs takes some distribution parameters a,b,c which can
>> be arrays compatible with say shape (x,) or (x,y). This should produce a return
>> array of shape (x,) or (x,y) of variate. However, the size parameter can be
>> specified potentially with a larger shape (z,x) or (z,x,y), which should return
>> z different samples of the (x,) or (x,y) parameterised variates.
>> Again apologises if I have completely misunderstood.
> I think you are right, I didn't look at your traceback carefully enough
> there is http://projects.scipy.org/scipy/ticket/1544 on shape and rvs,
> but the case is a bit different from yours.
> Since your norm example succeeds, and you specify a matching shape
> for loc, I think the problem is the broadcasting for the bounds.
> as in your comment on
>> Alternatively truncnorm._ppf could work out how to expand self._nb by looking at the size of _nb and q.
> _nb should be expanded to the correct shape (if it's not a scalar),
> before calling _ppf
or maybe stats.distributions.rv_continuous._rvs
should call ppf instead of _ppf, but that's expensive
someone with current scipy master needs to check if or where the problems
is with current master.
I don't have a build for master.
> self._size works on the flattened ``size`` and is attached for use by _rvs,
> the other methods work elementwise and shouldn't need to know about the _size,
> they are supposed to get broadcasted and flattened arguments.
> (The relevant code for setting bounds .a, .b is in _argcheck, that's
> why I thought
> the PR that Pauli referred to, might also have fixed this case.)
>> SciPy-User mailing list
More information about the SciPy-User