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

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


On Fri, Jun 3, 2011 at 11:15 AM, eat <e.antero.tammi at gmail.com> wrote:
> Hi,
>
> On Fri, Jun 3, 2011 at 4:20 PM, <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()
>>
>>
>> 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?
>
> From my rusty memory of linear algebra, only orthogonal transformations will
> do that what you are (apparently) looking for. So, given
> def affine(x, mu, A):
>     U, S, V= np.linalg.svd(A.T)
>
>     return np.dot(x- mu, np.dot(U, U.T))
>
> it will produce:
> In []: run try_affine
> (1000000, 3)
> 0.191657
> 0.191657

Thanks,
my linear algebra has sometimes blind spots. After seeing Warrens
answer, I started to google for the conditions that affine
transformation are monotonic, but I didn't find anything.

Josef


> My 2 cents,
> eat
>>
>> 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