Whether the covariance matrix will be singular or not depends on the
dimension of the matrix you start with.  The covariance matrix of an n
x n matrix like yours will always be singular, but because of rounding
errors, you'll sometimes end up with an invertible result.  The reason
is that any n points in n-space lie on an (n-1)-dimensional hyperplane
(in your case, any two points in the plane lie on a line), and since
there's no variability in the direction perpendicular to that
hyperplane, the covariance matrix will be singular.

Best,
Robert Young

On Sun, Jun 12, 2011 at 4:36 PM, Stéphane Lévy <[email protected]> wrote:
> Hello,
> The deteminant of the cut and pasted matrix is "very small" but it's not
> equal to zero.
> I wonder how you can say that the matrix is not invertible in the first
> place?
> The covariance matrix based on a random matrix has nearly 0.0% chance to
> happen to be non-invertible.
> I think the matrix is invertible.
> And I do have a message error if I ask for inversion of a not-ivertible
> matrix, as follows :
> -------------------
> Perl> my $m = pdl([1,1],[1,1])
>
> [
>  [1 1]
>  [1 1]
> ]
>
> Perl> inv($m)
> [!] Runtime error: PDL: PDL::inv: got a singular matrix or LU decomposition
>
> Caught at file (eval 47), line 4, pkg PerlConsole::Console
> -------------------
> The determinant of a (2,2) matrix : ([a,b],[c,d]) is : ad - bc
> I find the problem to be not solved for the moment.
> Thank you for your help again, I hope we will find a solution to this
> matter.
> Stéphane
>
> Le 10/06/2011 15:14, Chris Marshall a écrit :
>
> You matrix is not invertible which is why the first
> answer comes out funny.  The matrix inverse routine
> does not do checking for condition numbers, etc
> before it calculates the inverse.  If you print the
> determinant you'll see it is very small (i.e. floating
> point zero within round-off).
>
> The reason your cut and paste "check" worked
> is because you only included the top several places
> from the sprint of the numbers which is enough to
> make the determinant farther from 0 and the matrix
> then invertible.  It is not actually inverting the
> same matrix....
>
> --Chris
>
> On Fri, Jun 10, 2011 at 5:54 AM, Stéphane Lévy <[email protected]>
> wrote:
>
> Hello,
> I have found unexpected, astonishing results using the PDL matrix inv()
> function by 2 different ways.
> In the first way I manipulate PDL objects all the way, in the second way I
> recreate objects by pasting values of the original PDL object into a new PDL
> object.
> First way gives unexpected, wrong result, second way leads to accurate
> result. I do not understand this and it worries me a bit as I am supposed to
> use intensively PDL matrix functions.
> Anybody can give me an explanation of this, and tell me what I should do
> differently when I manipulate objects?
> Here is what I did :
>
> # step 1A : creating a (2,2) matrix
> Perl> my $m = random(2,2)
> $PDL1 =
> [
> [0.65707276 0.12124598]
> [0.95303134 0.43850649]
> ]
> ;
>
> # step 1B : computing cov table of the matrix
> Perl> my $c = $m->cov_table()
> $PDL1 =
> [
> [0.071777584 0.068924048]
> [0.068924048 0.066183954]
> ]
> ;
>
> # step 1C : testing if the the matrix multiplied by its inverse is equal to
> identity matrix
> Perl> $c x inv($c)
> $PDL1 =
> [
> [ 1 0]
> [-0.125 1.125]
> ]
> ;
> # we observe that step 1C leads to unexpected result
>
> # step 2A : pasting the content of PDL obtained in step 1B to a new PDL
> object : the 2 PDL objects are supposedly perfectly identical
> Perl> $m = pdl([0.071777584,0.068924048],[0.068924048,0.066183954])
> $PDL1 =
> [
> [0.071777584 0.068924048]
> [0.068924048 0.066183954]
> ]
> ;
>
> # step 2B : same as step 1C, testing if the the matrix multiplied by its
> inverse is equal to identity matrix
> Perl> $m x $m->inv()
> $PDL1 =
> [
> [1 0]
> [0 1]
> ]
> ;
> # we observe that step 2B leads to expected result
>
> Thank you.
> Best regards.
> Stéphane
>
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>
>
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>
>

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to