On 6/12/2011 8:16 PM, chm wrote:
On 6/12/2011 4:36 PM, Stéphane Lévy 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?
I just reported the value of the determinant. With floating
point values, very small is the same as zero for computational
purposes. You are right that that does not prove the matrix
is not invertible.
I don't know what the cov_table result is analytically or
whether it should be invertible but for my random matrix, I
saw a failure due to very small determinant that resembled
your report. I.e., for a "random" set of two starting
matrixes there was the same outcome.
That suggests that the computation is ill-posed, unstable,
or something else is going on. Please let us know if you
figure out what is going on. Sorry I cannot be of more help.
I installed PDL::Stats on this system and tried running
the experiment 5-6 times. About 1/2 to 2/3 of the time
the result of $c x $c->inv or $c x $c->matinv were
"bad" but the other times the condition number of the
matrix was good enough that the solution worked. It
definitely appears to be related to numerical instability
but it is not clear what could be improved.
Regards,
Chris
--Chris
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