Re: Determinant of Large Matrix

2007-06-08 Thread Hendrik van Rooyen
 James Stroud j@mbia.edu wrote:

 James Stroud wrote:
 [pointless stuff]
 
 OK. Nevermind. I'm rebinding encodings and so taking a sample from the 
 sample and thus getting the sample back. Terribly sorry.

There is truly nothing to be sorry about.
It takes guts to come right out and say that you made a mistake.
Well done!

start rant
One of my pet peeves are people who pretend that they never make mistakes.
Strangely enough, when you ask them to walk on water, they never quite 
manage it.

This sort of thing should be cause for rejoicing, - when you think about it, 
its a proof that the body of knowledge that has to do with sampling is
solid and reliable, independently of the experimenter - these days that is
quite a comforting thought.

The sanitised stuff you read in the scientific journals does not represent
the true course of the progress of science - in reality, progress is the
incidental by-product of a progressive series of blunders.  But nobody
involved will acknowledge this, for fear of their precious reputations...

end rant

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determinant of Large Matrix

2007-06-07 Thread Bjoern Schliessmann
James Stroud wrote:

 If I run it again on 10 (or 1000) the set is basically homogenous
 but now of different values (terribly confusing):
 
 set([12048175104.1, 12048175104.15, 12048175104.46,
 12048175103.94, 12048175104.23, 12048175103.81,
 12048175103.98, 12048175103.9])

As you seem to have overread it: Note that Python only prints those
numbers with full bogus precision since you let it display them
using repr() (it's used in lists by default for display). If you
use str() explicitly, Python applies rounding:
 
 A
[12048175104.1, 12048175104.15, 12048175104.46,
12048175103.94, 12048175104.23, 12048175103.81,
12048175103.94, 12048175104.23, 12048175103.81,
12048175103.98, 12048175103.9]
 [repr(i) for i in A]
['12048175104.1', '12048175104.15', '12048175104.46',
'12048175103.94', '12048175104.23', '12048175103.81',
'12048175103.94', '12048175104.23', '12048175103.81',
'12048175103.98', '12048175103.9']
 [str(i) for i in A]
['12048175104.0', '12048175104.0', '12048175104.0', '12048175104.0',
'12048175104.0', '12048175104.0', '12048175104.0', '12048175104.0',
'12048175104.0', '12048175104.0', '12048175104.0']
 

Regards,


Björn

-- 
BOFH excuse #83:

Support staff hung over, send aspirin and come back LATER.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determinant of Large Matrix

2007-06-07 Thread Mark Westwood
Hi James

Mathematica says that the determinant of the integer version of this
matrix is 2774532096, which is another vote for the answer you have.

Mathematica says that the determinant of the 24-digit real version of
your matrix is 2.774532096*10^9, which looks very similar to me.

I'd go with Numpy.

Regards

Mark Westwood


PS 13x13 isn't a large matrix !


On Jun 6, 12:10 pm, James Stroud [EMAIL PROTECTED] wrote:
 Hello All,

 I'm using numpy to calculate determinants of matrices that look like
 this (13x13):

 [[ 0.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
   [ 1.  0.  1.  4.  1.  9.  4.  4.  1.  1.  4.  9.  4.  9.]
   [ 1.  1.  0.  1.  4.  4.  9.  9.  4.  4.  1.  4.  1.  4.]
   [ 1.  4.  1.  0.  9.  1.  4.  4.  9.  1.  4.  1.  4.  1.]
   [ 1.  1.  4.  9.  0.  4.  4.  4.  1.  4.  1.  9.  4.  9.]
   [ 1.  9.  4.  1.  4.  0.  4.  4.  9.  4.  1.  1.  4.  1.]
   [ 1.  4.  9.  4.  4.  4.  0.  1.  1.  1.  9.  1.  9.  4.]
   [ 1.  4.  9.  4.  4.  4.  1.  0.  4.  1.  9.  4.  4.  1.]
   [ 1.  1.  4.  9.  1.  9.  1.  4.  0.  4.  4.  4.  4.  9.]
   [ 1.  1.  4.  1.  4.  4.  1.  1.  4.  0.  9.  4.  9.  4.]
   [ 1.  4.  1.  4.  1.  1.  9.  9.  4.  9.  0.  4.  1.  4.]
   [ 1.  9.  4.  1.  9.  1.  1.  4.  4.  4.  4.  0.  4.  1.]
   [ 1.  4.  1.  4.  4.  4.  9.  4.  4.  9.  1.  4.  0.  1.]
   [ 1.  9.  4.  1.  9.  1.  4.  1.  9.  4.  4.  1.  1.  0.]]

 For this matrix, I'm getting this with numpy:

   2774532095.971

 But I have a feeling I'm exceeding the capacity of floats here. Does
 anyone have an idea for how to treat this? Is it absurd to think I could
 get a determinant of this matrix? Is there a python package that could
 help me?

 Many thanks for any answers.

 James


-- 
http://mail.python.org/mailman/listinfo/python-list


Determinant of Large Matrix

2007-06-06 Thread James Stroud
Hello All,

I'm using numpy to calculate determinants of matrices that look like 
this (13x13):

[[ 0.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
  [ 1.  0.  1.  4.  1.  9.  4.  4.  1.  1.  4.  9.  4.  9.]
  [ 1.  1.  0.  1.  4.  4.  9.  9.  4.  4.  1.  4.  1.  4.]
  [ 1.  4.  1.  0.  9.  1.  4.  4.  9.  1.  4.  1.  4.  1.]
  [ 1.  1.  4.  9.  0.  4.  4.  4.  1.  4.  1.  9.  4.  9.]
  [ 1.  9.  4.  1.  4.  0.  4.  4.  9.  4.  1.  1.  4.  1.]
  [ 1.  4.  9.  4.  4.  4.  0.  1.  1.  1.  9.  1.  9.  4.]
  [ 1.  4.  9.  4.  4.  4.  1.  0.  4.  1.  9.  4.  4.  1.]
  [ 1.  1.  4.  9.  1.  9.  1.  4.  0.  4.  4.  4.  4.  9.]
  [ 1.  1.  4.  1.  4.  4.  1.  1.  4.  0.  9.  4.  9.  4.]
  [ 1.  4.  1.  4.  1.  1.  9.  9.  4.  9.  0.  4.  1.  4.]
  [ 1.  9.  4.  1.  9.  1.  1.  4.  4.  4.  4.  0.  4.  1.]
  [ 1.  4.  1.  4.  4.  4.  9.  4.  4.  9.  1.  4.  0.  1.]
  [ 1.  9.  4.  1.  9.  1.  4.  1.  9.  4.  4.  1.  1.  0.]]

For this matrix, I'm getting this with numpy:

  2774532095.971

But I have a feeling I'm exceeding the capacity of floats here. Does 
anyone have an idea for how to treat this? Is it absurd to think I could 
get a determinant of this matrix? Is there a python package that could 
help me?

Many thanks for any answers.

James
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determinant of Large Matrix

2007-06-06 Thread Tommy Nordgren

On 6 jun 2007, at 13.10, James Stroud wrote:

 Hello All,

 I'm using numpy to calculate determinants of matrices that look like
 this (13x13):

 [[ 0.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
   [ 1.  0.  1.  4.  1.  9.  4.  4.  1.  1.  4.  9.  4.  9.]
   [ 1.  1.  0.  1.  4.  4.  9.  9.  4.  4.  1.  4.  1.  4.]
   [ 1.  4.  1.  0.  9.  1.  4.  4.  9.  1.  4.  1.  4.  1.]
   [ 1.  1.  4.  9.  0.  4.  4.  4.  1.  4.  1.  9.  4.  9.]
   [ 1.  9.  4.  1.  4.  0.  4.  4.  9.  4.  1.  1.  4.  1.]
   [ 1.  4.  9.  4.  4.  4.  0.  1.  1.  1.  9.  1.  9.  4.]
   [ 1.  4.  9.  4.  4.  4.  1.  0.  4.  1.  9.  4.  4.  1.]
   [ 1.  1.  4.  9.  1.  9.  1.  4.  0.  4.  4.  4.  4.  9.]
   [ 1.  1.  4.  1.  4.  4.  1.  1.  4.  0.  9.  4.  9.  4.]
   [ 1.  4.  1.  4.  1.  1.  9.  9.  4.  9.  0.  4.  1.  4.]
   [ 1.  9.  4.  1.  9.  1.  1.  4.  4.  4.  4.  0.  4.  1.]
   [ 1.  4.  1.  4.  4.  4.  9.  4.  4.  9.  1.  4.  0.  1.]
   [ 1.  9.  4.  1.  9.  1.  4.  1.  9.  4.  4.  1.  1.  0.]]

 For this matrix, I'm getting this with numpy:

   2774532095.971

 But I have a feeling I'm exceeding the capacity of floats here. Does
 anyone have an idea for how to treat this? Is it absurd to think I  
 could
 get a determinant of this matrix? Is there a python package that could
 help me?

 Many thanks for any answers.

 James
 -- 
 http://mail.python.org/mailman/listinfo/python-list
Are you sure NumPy return float results. As far as I know, it  
returns doubles
(about 16 digits)
--
Home is not where you are born, but where your heart finds peace -
Tommy Nordgren, The dying old crone
[EMAIL PROTECTED]


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determinant of Large Matrix

2007-06-06 Thread montyphyton

James Stroud je napisao/la:
 Hello All,

 I'm using numpy to calculate determinants of matrices that look like
 this (13x13):

 [[ 0.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
   [ 1.  0.  1.  4.  1.  9.  4.  4.  1.  1.  4.  9.  4.  9.]
   [ 1.  1.  0.  1.  4.  4.  9.  9.  4.  4.  1.  4.  1.  4.]
   [ 1.  4.  1.  0.  9.  1.  4.  4.  9.  1.  4.  1.  4.  1.]
   [ 1.  1.  4.  9.  0.  4.  4.  4.  1.  4.  1.  9.  4.  9.]
   [ 1.  9.  4.  1.  4.  0.  4.  4.  9.  4.  1.  1.  4.  1.]
   [ 1.  4.  9.  4.  4.  4.  0.  1.  1.  1.  9.  1.  9.  4.]
   [ 1.  4.  9.  4.  4.  4.  1.  0.  4.  1.  9.  4.  4.  1.]
   [ 1.  1.  4.  9.  1.  9.  1.  4.  0.  4.  4.  4.  4.  9.]
   [ 1.  1.  4.  1.  4.  4.  1.  1.  4.  0.  9.  4.  9.  4.]
   [ 1.  4.  1.  4.  1.  1.  9.  9.  4.  9.  0.  4.  1.  4.]
   [ 1.  9.  4.  1.  9.  1.  1.  4.  4.  4.  4.  0.  4.  1.]
   [ 1.  4.  1.  4.  4.  4.  9.  4.  4.  9.  1.  4.  0.  1.]
   [ 1.  9.  4.  1.  9.  1.  4.  1.  9.  4.  4.  1.  1.  0.]]

 For this matrix, I'm getting this with numpy:

   2774532095.971

 But I have a feeling I'm exceeding the capacity of floats here. Does
 anyone have an idea for how to treat this? Is it absurd to think I could
 get a determinant of this matrix? Is there a python package that could
 help me?

 Many thanks for any answers.

 James

have you tried using matlab to verify the result? matlab is very fast
and can work with large matrices, so this should be no problem for
it...

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determinant of Large Matrix

2007-06-06 Thread Dustan
On Jun 6, 6:47 am, Tommy Nordgren [EMAIL PROTECTED] wrote:
 On 6 jun 2007, at 13.10, James Stroud wrote:



  Hello All,

  I'm using numpy to calculate determinants of matrices that look like
  this (13x13):

  [[ 0.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
[ 1.  0.  1.  4.  1.  9.  4.  4.  1.  1.  4.  9.  4.  9.]
[ 1.  1.  0.  1.  4.  4.  9.  9.  4.  4.  1.  4.  1.  4.]
[ 1.  4.  1.  0.  9.  1.  4.  4.  9.  1.  4.  1.  4.  1.]
[ 1.  1.  4.  9.  0.  4.  4.  4.  1.  4.  1.  9.  4.  9.]
[ 1.  9.  4.  1.  4.  0.  4.  4.  9.  4.  1.  1.  4.  1.]
[ 1.  4.  9.  4.  4.  4.  0.  1.  1.  1.  9.  1.  9.  4.]
[ 1.  4.  9.  4.  4.  4.  1.  0.  4.  1.  9.  4.  4.  1.]
[ 1.  1.  4.  9.  1.  9.  1.  4.  0.  4.  4.  4.  4.  9.]
[ 1.  1.  4.  1.  4.  4.  1.  1.  4.  0.  9.  4.  9.  4.]
[ 1.  4.  1.  4.  1.  1.  9.  9.  4.  9.  0.  4.  1.  4.]
[ 1.  9.  4.  1.  9.  1.  1.  4.  4.  4.  4.  0.  4.  1.]
[ 1.  4.  1.  4.  4.  4.  9.  4.  4.  9.  1.  4.  0.  1.]
[ 1.  9.  4.  1.  9.  1.  4.  1.  9.  4.  4.  1.  1.  0.]]

  For this matrix, I'm getting this with numpy:

2774532095.971

  But I have a feeling I'm exceeding the capacity of floats here. Does
  anyone have an idea for how to treat this? Is it absurd to think I
  could
  get a determinant of this matrix? Is there a python package that could
  help me?

  Many thanks for any answers.

  James
  --
 http://mail.python.org/mailman/listinfo/python-list

 Are you sure NumPy return float results. As far as I know, it
 returns doubles

I don't know about NumPy, but in general, a python float is a double:
http://docs.python.org/lib/typesnumeric.html
Floating point numbers are implemented using double in C. All bets on
their precision are off unless you happen to know the machine you are
working with.

 (about 16 digits)
 --
 Home is not where you are born, but where your heart finds peace -
 Tommy Nordgren, The dying old crone
 [EMAIL PROTECTED]


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determinant of Large Matrix

2007-06-06 Thread J. Robertson
James Stroud wrote:
 Hello All,
 
 I'm using numpy to calculate determinants of matrices that look like 
 this (13x13):
 
 [[ 0.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
[snip]
 But I have a feeling I'm exceeding the capacity of floats here. Does 
 anyone have an idea for how to treat this? Is it absurd to think I could 
 get a determinant of this matrix? Is there a python package that could 
 help me?
 
 Many thanks for any answers.
 
 James

in order to verify that this result is correct, you could get the 
eigenvector and eigenvalues of this matrix (for example with 
numpy.linalg.eig) and check that they make sense; the determinant simply 
is the product of all the eigenvalues.

gd luck
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determinant of Large Matrix

2007-06-06 Thread Robert Kern
James Stroud wrote:
 Hello All,
 
 I'm using numpy to calculate determinants of matrices that look like 
 this (13x13):
 
 [[ 0.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
   [ 1.  0.  1.  4.  1.  9.  4.  4.  1.  1.  4.  9.  4.  9.]
   [ 1.  1.  0.  1.  4.  4.  9.  9.  4.  4.  1.  4.  1.  4.]
   [ 1.  4.  1.  0.  9.  1.  4.  4.  9.  1.  4.  1.  4.  1.]
   [ 1.  1.  4.  9.  0.  4.  4.  4.  1.  4.  1.  9.  4.  9.]
   [ 1.  9.  4.  1.  4.  0.  4.  4.  9.  4.  1.  1.  4.  1.]
   [ 1.  4.  9.  4.  4.  4.  0.  1.  1.  1.  9.  1.  9.  4.]
   [ 1.  4.  9.  4.  4.  4.  1.  0.  4.  1.  9.  4.  4.  1.]
   [ 1.  1.  4.  9.  1.  9.  1.  4.  0.  4.  4.  4.  4.  9.]
   [ 1.  1.  4.  1.  4.  4.  1.  1.  4.  0.  9.  4.  9.  4.]
   [ 1.  4.  1.  4.  1.  1.  9.  9.  4.  9.  0.  4.  1.  4.]
   [ 1.  9.  4.  1.  9.  1.  1.  4.  4.  4.  4.  0.  4.  1.]
   [ 1.  4.  1.  4.  4.  4.  9.  4.  4.  9.  1.  4.  0.  1.]
   [ 1.  9.  4.  1.  9.  1.  4.  1.  9.  4.  4.  1.  1.  0.]]
 
 For this matrix, I'm getting this with numpy:
 
   2774532095.971
 
 But I have a feeling I'm exceeding the capacity of floats here.

It's not that you're exceeding the capacity of float64 numbers, it's just that
there are floating point calculations taking place. The way the determinant is
calculated is by doing an LU decomposition and then multiplying down the
diagonal. Although all of your entries started as integers, floating point error
does accumulate. The answer that you got is within finfo(float64).eps of
relative error of the actual answer.

 Does 
 anyone have an idea for how to treat this? Is it absurd to think I could 
 get a determinant of this matrix? Is there a python package that could 
 help me?

If all of your matrices are going to be integers, doing the
determinant-by-minors calculations yourself is probably easy enough to code and
will retain complete precision.

  http://mathworld.wolfram.com/DeterminantExpansionbyMinors.html

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determinant of Large Matrix

2007-06-06 Thread Peter Otten
James Stroud wrote:

 I'm using numpy to calculate determinants of matrices that look like
 this (13x13):
 
 [[ 0.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
   [ 1.  0.  1.  4.  1.  9.  4.  4.  1.  1.  4.  9.  4.  9.]
   [ 1.  1.  0.  1.  4.  4.  9.  9.  4.  4.  1.  4.  1.  4.]
   [ 1.  4.  1.  0.  9.  1.  4.  4.  9.  1.  4.  1.  4.  1.]
   [ 1.  1.  4.  9.  0.  4.  4.  4.  1.  4.  1.  9.  4.  9.]
   [ 1.  9.  4.  1.  4.  0.  4.  4.  9.  4.  1.  1.  4.  1.]
   [ 1.  4.  9.  4.  4.  4.  0.  1.  1.  1.  9.  1.  9.  4.]
   [ 1.  4.  9.  4.  4.  4.  1.  0.  4.  1.  9.  4.  4.  1.]
   [ 1.  1.  4.  9.  1.  9.  1.  4.  0.  4.  4.  4.  4.  9.]
   [ 1.  1.  4.  1.  4.  4.  1.  1.  4.  0.  9.  4.  9.  4.]
   [ 1.  4.  1.  4.  1.  1.  9.  9.  4.  9.  0.  4.  1.  4.]
   [ 1.  9.  4.  1.  9.  1.  1.  4.  4.  4.  4.  0.  4.  1.]
   [ 1.  4.  1.  4.  4.  4.  9.  4.  4.  9.  1.  4.  0.  1.]
   [ 1.  9.  4.  1.  9.  1.  4.  1.  9.  4.  4.  1.  1.  0.]]
 
 For this matrix, I'm getting this with numpy:
 
   2774532095.971
 
 But I have a feeling I'm exceeding the capacity of floats here. Does
 anyone have an idea for how to treat this? Is it absurd to think I could
 get a determinant of this matrix? Is there a python package that could
 help me?

Here's some anecdotal evidence that your result may be correct:

import operator

m = eval([[ 0.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
  [ 1.  0.  1.  4.  1.  9.  4.  4.  1.  1.  4.  9.  4.  9.]
  [ 1.  1.  0.  1.  4.  4.  9.  9.  4.  4.  1.  4.  1.  4.]
  [ 1.  4.  1.  0.  9.  1.  4.  4.  9.  1.  4.  1.  4.  1.]
  [ 1.  1.  4.  9.  0.  4.  4.  4.  1.  4.  1.  9.  4.  9.]
  [ 1.  9.  4.  1.  4.  0.  4.  4.  9.  4.  1.  1.  4.  1.]
  [ 1.  4.  9.  4.  4.  4.  0.  1.  1.  1.  9.  1.  9.  4.]
  [ 1.  4.  9.  4.  4.  4.  1.  0.  4.  1.  9.  4.  4.  1.]
  [ 1.  1.  4.  9.  1.  9.  1.  4.  0.  4.  4.  4.  4.  9.]
  [ 1.  1.  4.  1.  4.  4.  1.  1.  4.  0.  9.  4.  9.  4.]
  [ 1.  4.  1.  4.  1.  1.  9.  9.  4.  9.  0.  4.  1.  4.]
  [ 1.  9.  4.  1.  9.  1.  1.  4.  4.  4.  4.  0.  4.  1.]
  [ 1.  4.  1.  4.  4.  4.  9.  4.  4.  9.  1.  4.  0.  1.]
  [ 1.  9.  4.  1.  9.  1.  4.  1.  9.  4.  4.  1.  1.  0.]].replace(.,
.,).replace(], ],))[0]

M = [[int(x) for x in row] for row in m]

def subdet(m, rowindex):
return [row[1:] for index, row in enumerate(m) if index != rowindex]

def det(m):
if len(m) == 1:
return m[0][0]
sign = 1
sigma = 0
for index, row in enumerate(m):
x = row[0]
if x:
sigma += sign * x * det(subdet(m, index))
sign = -sign
return sigma

def common_multiple(items):
items = set(items)
items.discard(0)
if items:
return reduce(operator.mul, items)
else:
return 0

def det3(m, switch_algo=8):
p = 1
q = 1
while 1:
if len(m) == switch_algo:
a, b = divmod(p*det(m), q)
assert b == 0
return a
cm = common_multiple(row[0] for row in m)
if cm == 0: return 0

sign = 1
e = enumerate(m)
for first_index, first_row in e:
if first_row[0]:
f = cm // first_row[0]
assert (cm % first_row[0]) == 0
p *= sign * cm
q *= f
first_row[:] = [f*x for x in first_row[1:]]
break
first_row[:] = first_row[1:]
sign = -sign
for index, row in e:
if row[0]:
f = cm // row[0]
assert (cm % row[0]) == 0
q *= f
row[:] = [f*x - fx for x, fx in zip(row[1:], first_row)]
else:
row[:] = row[1:]
del m[first_index]

if __name__ == __main__:
import pprint
pprint.pprint(M)
result = det3(M)
assert result == 2774532096
print det(M) =, result

As I use only integers, any errors should be algorithmic rather than caused
by rounding.

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determinant of Large Matrix

2007-06-06 Thread Bjoern Schliessmann
James Stroud wrote:

 For this matrix, I'm getting this with numpy:
 
 2774532095.971
 
 But I have a feeling I'm exceeding the capacity of floats here.
 Does anyone have an idea for how to treat this?

Not if you don't state your requirements more precisely. E. g. what
precision do you need?

 Is it absurd to think I could get a determinant of this matrix? 

Absolutely not.

 Is there a python package that could help me?

Help doing what?

BTW, scilab says this:

--det(A)
 ans  =
 
2.774532096E+09  
 
--ans-2774532095.971
 ans  =
 
2.8610229492188E-06  
 
--

The error is 15 magnitudes below your result -- what do you want
more? :)

Regards,


Björn

P.S.:
 print 2774532095.971
2774532096.0
 

-- 
BOFH excuse #118:

the router thinks its a printer.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determinant of Large Matrix

2007-06-06 Thread Steven D'Aprano
On Wed, 06 Jun 2007 04:10:43 -0700, James Stroud wrote:

 Hello All,
 
 I'm using numpy to calculate determinants of matrices that look like 
 this (13x13):

[snip matrix]

 For this matrix, I'm getting this with numpy:
 
   2774532095.971
 
 But I have a feeling I'm exceeding the capacity of floats here. Does 
 anyone have an idea for how to treat this? Is it absurd to think I could 
 get a determinant of this matrix? Is there a python package that could 
 help me?

Is there a particular reason you think there is a problem? The determinant
given is pretty close to the integer 2774532096. Assuming that is the
correct value, the difference between:

2.774532096000e9 and
2.774532095971e9

gives a relative error of 1.0311731312618234e-13 percent. How much
precision were you after? :-)

I suspect that if there is a problem with the matrix, it is less likely
to be because of the size of floats and more likely that the matrix is
ill-conditioned. 

I don't know if numpy will calculate the condition number of the matrix,
or estimate it. If it does, do so -- a large condition number == trouble.

http://en.wikipedia.org/wiki/Condition_number

Another way to see if the matrix is ill-conditioned is to make a small
perturbation to it (say, change two or three of the entries by 0.0001 or
so), then calculate the determinate. If the result is radically different,
then the matrix is probably ill-conditioned and there is likely no help
for you except numerical black magic and/or using a different matrix.


-- 
Steven.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determinant of Large Matrix

2007-06-06 Thread James Stroud
Hello,

Thank you to those who responded for your answers. They were very 
helpful and I'm confident now that numpy is calculating accurate 
determinants for these matrices.

But I think I need to restate my problem a little as suggested by some 
becuase I'm still bewildered.

First, here is the relevant part of my code:

# start of code

def main(word, repeats, trials):
   encodings = encode(word, CODE)
   random.shuffle(encodings)
   values = []
   pb = PB(tk.Tk())
   for i in xrange(trials):
 if i % 100 == 0:
   pb.update(float(i)/trials)
 random.seed()
 encodings = random.sample(encodings, repeats)
 distmat = build_distmat(encodings)
 print
 print distmat
 values.append(det(distmat))
   values.sort()
   # print values
   print set(values)

# end of code

Here are some notes about the code:

1. PB is a progress bar because this takes a while for a lot of trials.
2. encodings is a complete list equivalent encodings of word.
3. distmat is a representation of the distances between the sample as 
integers for purposes of calculating the content of the hyperspace 
defined by this pairwise distance matrix (Cayley-Menger determinant).
4. det is numpy.linalg.det

I get fairly unintuitive results, because if I run it once for 10 (or 
1000 or 100,000) the set of values are all essentially the same:

set([-733163520.5591, -733163520.4566, -733163519.8546, 
-733163520.2789, -733163519.9189, -733163519.783, 
-733163519.758, -733163520.2348, -733163519.6936, 
-733163520.4542])

If I run it again on 10 (or 1000) the set is basically homogenous but 
now of different values (terribly confusing):

set([12048175104.1, 12048175104.15, 12048175104.46, 
12048175103.94, 12048175104.23, 12048175103.81, 
12048175103.98, 12048175103.9])

How could this be? This holds for 10 trials or 10 trials. Below is 
the output from the above runs.

Is this a problem with the rng? All of these matrices look different. 
I'm certain this can't happen by chance.

Thank you again.

James


euler 70% ./simplex.py

[[  0.   1.   1.   1.   1.   1.   1.   1.   1.   1.   1.   1.   1.   1.]
  [  1.   0.   4.   9.   9.   4.   4.   9.   9.   1.   9.  16.   9.   9.]
  [  1.   4.   0.   9.   9.   4.   4.  16.  16.   4.   9.   9.   1.   4.]
  [  1.   9.   9.   0.   9.   9.  16.   4.   4.  16.   9.   1.   4.   4.]
  [  1.   9.   9.   9.   0.  16.   4.   4.   9.   9.   9.   9.   4.   9.]
  [  1.   4.   4.   9.  16.   0.   9.   4.   4.   4.   4.   9.   9.   4.]
  [  1.   4.   4.  16.   4.   9.   0.  16.   9.   1.   9.   9.   9.   9.]
  [  1.   9.  16.   4.   4.   4.  16.   0.   1.   9.   4.   4.   9.   4.]
  [  1.   9.  16.   4.   9.   4.   9.   1.   0.   4.   9.   1.   9.   9.]
  [  1.   1.   4.  16.   9.   4.   1.   9.   4.   0.   9.   9.   9.   9.]
  [  1.   9.   9.   9.   9.   4.   9.   4.   9.   9.   0.   9.  16.   1.]
  [  1.  16.   9.   1.   9.   9.   9.   4.   1.   9.   9.   0.   4.   4.]
  [  1.   9.   1.   4.   4.   9.   9.   9.   9.   9.  16.   4.   0.   9.]
  [  1.   9.   4.   4.   9.   4.   9.   4.   9.   9.   1.   4.   9.   0.]]

[[  0.   1.   1.   1.   1.   1.   1.   1.   1.   1.   1.   1.   1.   1.]
  [  1.   0.   4.  16.   4.   9.  16.   4.   4.   9.   9.   1.   9.   9.]
  [  1.   4.   0.   9.   9.   1.   9.   9.   9.  16.   9.   4.   4.   9.]
  [  1.  16.   9.   0.   4.   4.   1.   9.   9.   9.   4.   9.   9.   1.]
  [  1.   4.   9.   4.   0.  16.   9.   9.   1.   9.   4.   1.   9.   9.]
  [  1.   9.   1.   4.  16.   0.   4.   4.  16.   9.   4.   9.   9.   4.]
  [  1.  16.   9.   1.   9.   4.   0.   9.  16.   9.   9.   9.   4.   4.]
  [  1.   4.   9.   9.   9.   4.   9.   0.   4.   1.   4.   4.   9.   9.]
  [  1.   4.   9.   9.   1.  16.  16.   4.   0.   4.   4.   4.   4.   9.]
  [  1.   9.  16.   9.   9.   9.   9.   1.   4.   0.   4.   9.   9.   9.]
  [  1.   9.   9.   4.   4.   4.   9.   4.   4.   4.   0.   9.  16.   4.]
  [  1.   1.   4.   9.   1.   9.   9.   4.   4.   9.   9.   0.   9.  16.]
  [  1.   9.   4.   9.   9.   9.   4.   9.   4.   9.  16.   9.   0.   9.]
  [  1.   9.   9.   1.   9.   4.   4.   9.   9.   9.   4.  16.   9.   0.]]

[[  0.   1.   1.   1.   1.   1.   1.   1.   1.   1.   1.   1.   1.   1.]
  [  1.   0.   9.   9.   4.   9.   4.   9.   9.   9.   9.   9.  16.   4.]
  [  1.   9.   0.   1.   9.   4.   9.   4.  16.   9.   9.   9.   4.   1.]
  [  1.   9.   1.   0.   9.   4.   9.   9.   9.   9.  16.   9.   4.   4.]
  [  1.   4.   9.   9.   0.   1.   9.   9.   4.   9.   4.  16.   9.   9.]
  [  1.   9.   4.   4.   1.   0.  16.  16.   9.   4.   9.   9.   4.   4.]
  [  1.   4.   9.   9.   9.  16.   0.   1.   4.   4.   4.   4.   4.  16.]
  [  1.   9.   4.   9.   9.  16.   1.   0.   4.   9.   1.   9.   4.   9.]
  [  1.   9.  16.   9.   4.   9.   4.   4.   0.   4.   1.   9.   9.  16.]
  [  1.   9.   9.   9.   9.   4.   4.   9.   4.   0.   4.   1.   4.   9.]
  [  1.   9.   9.  16.   4.   9.   4.   1.   1.   4.   0.   9.   9.  

Re: Determinant of Large Matrix

2007-06-06 Thread James Stroud
Steven D'Aprano wrote:
[Valuable Response]

Thank you Steven for your helpful comments. Please see my reply to 
Bjoern Schliessmann where I have restated my problem.

James
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determinant of Large Matrix

2007-06-06 Thread James Stroud
James Stroud wrote:
[pointless stuff]

OK. Nevermind. I'm rebinding encodings and so taking a sample from the 
sample and thus getting the sample back. Terribly sorry.

James
-- 
http://mail.python.org/mailman/listinfo/python-list