[SciPy-User] affine transformation - what's going on ?

josef.pktd at gmail.com josef.pktd at gmail.com
Fri Jun 3 11:48:50 EDT 2011


On Fri, Jun 3, 2011 at 10:20 AM, Warren Weckesser
<warren.weckesser at enthought.com> wrote:
>
>
> On Fri, Jun 3, 2011 at 8:20 AM, <josef.pktd at gmail.com> wrote:
>>
>> I'm puzzling for hours already what's going on, and I don't understand
>> where my thinko or bug is.
>>
>> I *think* an affine transformation should return the same count in an
>> inequality.
>> x is (nobs, 3)
>> a is (3)
>> mu and A define an affine transformation
>>
>> Why do the following two not give the same result? The first is about
>> 0.19, the second 0.169
>>
>> print (x<a).all(-1).mean()
>>
>> print (affine(x, mu, A) < affine(a, mu, A)).all(-1).mean()
>>
>
>
> An affine transformation will not necessarily preserve
> the ordering of the components of two vectors.
>
> Here's a counterexample:
>
> In [92]: Q = array([[2, -1.5],[0,0.5]])
>
> In [93]: Q
> Out[93]:
> array([[ 2. , -1.5],
>        [ 0. ,  0.5]])
>
> In [94]: x1 = array([1.0, 1.0])
>
> In [95]: x2 = array([0.9, 0.1])
>
> In [96]: x1 > x2
> Out[96]: array([ True,  True], dtype=bool)
>
> In [97]: dot(Q, x1)
> Out[97]: array([ 0.5,  0.5])
>
> In [98]: dot(Q, x2)
> Out[98]: array([ 1.65,  0.05])
>
> In [99]: dot(Q,x1) > dot(Q,x2)
> Out[99]: array([False,  True], dtype=bool)

Thanks Warren,

nice (nasty for my thinking) example, positive definite and
everything. I completely forgot about monotonicity.
I had to check it's not a trick with negative eigenvalues.

This means we can transform a multivariate normal distributed random
variable to the standardized N(0, eye) form but cannot use it for
calculating cdfs.
http://en.wikipedia.org/wiki/Multivariate_normal_distribution#Affine_transformation

(Now I understand why Brentz and Getz only standardize by the variance
for the mvn cdf)
(Last time I had to ask stackoverflow when my uncorrelated
t-distributed random variables were not independent)

Josef




>
>
>
> Warren
>
>
>>
>> full script below and in attachment
>> -------------
>> import numpy as np
>>
>> def affine(x, mu, A):
>>    return np.dot(x-mu, A.T)
>>
>> cov3 = np.array([[ 1.  ,  0.5 ,  0.75],
>>                   [ 0.5 ,  1.5 ,  0.6 ],
>>                   [ 0.75,  0.6 ,  2.  ]])
>>
>> mu = np.array([-1, 0.0, 2.0])
>>
>> A = np.array([[ 1.22955725, -0.25615776, -0.38423664],
>>               [-0.        ,  0.87038828, -0.26111648],
>>               [-0.        , -0.        ,  0.70710678]])
>>
>> x = np.random.multivariate_normal(mu, cov3, size=1000000)
>> print x.shape
>>
>> a = np.array([ 0. ,  0.5,  1. ])
>>
>> print (x<a).all(-1).mean()
>> print (affine(x, mu, A) < affine(a, mu, A)).all(-1).mean()
>>
>> '''
>> with 100000
>> (100000, 3)
>> 0.19185
>> 0.16837
>>
>> with 1000000
>>
>> (1000000, 3)
>> 0.191597
>> 0.168814
>> '''
>> ------------------
>>
>> context: I'm transforming multivariate normal distributed random
>> variables, and my cdf's don't match up.
>>
>> Can anyone help figuring out where my thinking or my calculations are
>> wrong?
>>
>> Josef
>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>



More information about the SciPy-User mailing list