Skip to content

Randomly changing results #4978

@BalticPinguin

Description

@BalticPinguin

By calculating the eigen problem using numpy.linalg.eig() I get deviating results changing more or less randomly for big matrices (see 'output' below in the code in attached file).
The probability for errors increases with the size of matrices and when more calculations are done around it (for that reason I calculate multiple things in between).
In the 'real' application, I have a bigger matrices and instead of an expected unity-matrix I get something really different.

This error occured on my Laptop using python 2.7.3, 2.7.8 and 3.2.3 for linux (ubuntu);
I was NOT able to reproduce it on a cluster using the same version as well as on other computers...

code: (sorry for the long file)

#!/usr/bin/python
import numpy as np

A=np.matrix([[3.2363937392492934594e-05, 5.3743203181225035763e-07, -5.3223444085470951933e-06, -2.0932406999365669401e-06,
-4.8026889992356032691e-06, 2.9354996913650668977e-06, 2.3523788694230963702e-06, -3.0881657618430002498e-08,
 1.5339921531474763390e-06, -8.3912046455898551422e-06, 5.2033871746176156365e-07, 2.8397884864543894022e-06,
 1.1540866569804096925e-06, 7.6502877195009575924e-06, -7.2546718782771161732e-06, 3.0751087009984703759e-07,
 6.6199568823411368145e-06, -8.8853431683582578506e-06],
[  5.3743203181225025175e-07, 1.2555389164845958414e-04, -9.1520868975769601090e-05, -1.2577607485774579037e-06,
 -9.1423828050608230096e-07, 1.0838123851206823272e-06, 3.2122164097855226294e-07, 1.4966310144486706531e-06,
 -1.9469804903977263439e-06, 1.6817277476448176928e-06, -3.5312560677364369076e-05, 2.4943720695895097767e-05,
  1.2810852306119931102e-07, 5.2832296574101113179e-06, -7.7463112370587695334e-06, -2.4497143155063846378e-06,
 -7.3285692747166421225e-06, 1.1402843374263565645e-05],
[ -5.3223444085470951933e-06, -9.1520868975769601090e-05, 1.1569157982681613217e-04, 3.5983924292980524646e-07,
  8.1663917273742100732e-07, -5.6236718587450825274e-08, -7.1643076582534449590e-07, -8.8096014232139781835e-07,
 -6.0357744008440676717e-07, 7.2940831545005406246e-07, 2.4099327483036244200e-05, -3.2245878965596542131e-05,
  1.8929096863578700437e-06, 1.2987006198095699642e-05, -8.7138155976158751612e-06, 3.8727807940591425955e-07,
 -6.5608929080913637750e-06, 5.0883768383658558749e-06],
[ -2.0932406999365673636e-06, -1.2577607485774581154e-06, 3.5983924292980498177e-07, 1.4403168747730365844e-05,
 -3.3637325889159790233e-06, -3.6232773221842713856e-06, -1.4358756211595842084e-05, 2.2852525258849945138e-05,
 -1.4338118241669330927e-06, -8.2814094879237133879e-06, -2.5172161262231661427e-06, 4.2893232062647641424e-06,
 -1.4574654808322303607e-06, -4.7722429842521700606e-07, -1.3223028593561090855e-06, -3.2144474988509354573e-06,
 -8.2457777062527617450e-07, 9.7999301067991132434e-08],
 [ -4.8026889992356032691e-06, -9.1423828050608230096e-07, 8.1663917273742121908e-07, -3.3637325889159790233e-06,
  1.5118590013672111811e-05, -2.7117407016551274256e-06, 1.2830877385567249351e-05, -3.8988049951376544809e-05,
  5.6847434782544964800e-06, 3.7840234999380512024e-07, -3.9835066642550023282e-06, 1.2983551577352654629e-06,
 -1.2342127583594660500e-06, -9.5042860827452957300e-07, -4.0919282893623241349e-07, 3.5072865233435838752e-06,
  2.4296937643214367637e-06, -1.2151230175285083018e-06],
[  2.9354996913650673213e-06, 1.0838123851206827507e-06, -5.6236718587449819422e-08, -3.6232773221842713856e-06,
 -2.7117407016551274256e-06, 2.5759541573805727762e-06, 9.4279048071909251937e-07, 3.3457990867145600408e-06,
 -1.5132598154442973713e-06, 2.8439571680093519393e-06, 1.3109838220762297868e-06, -1.7348425232743938705e-06,
 -2.0508732496471420395e-06, -1.0315842056999880908e-07, -4.9929687993861365844e-07, 8.6172651077259989421e-07,
  5.0703693877717605167e-07, -8.3356938947532246401e-07],
[  2.3523788694230955232e-06, 3.2122164097855205118e-07, -7.1643076582534470766e-07, -1.4358756211595842084e-05,
  1.2830877385567249351e-05, 9.4279048071909262525e-07, 6.6198869331340602661e-05, -6.5071674594714522125e-05,
 -3.1993968205147471374e-06, -4.5761153552121572050e-06, 6.8038229608618740673e-06, -3.7069107762320074073e-08,
  4.2605995651567878422e-07, -5.4565436277699948216e-07, -1.6964272504802535275e-07, -3.6401225862765453229e-06,
 -2.4559265771047108679e-06, 9.6016337641870898645e-07],
[ -3.0881657618430935558e-08, 1.4966310144486704413e-06, -8.8096014232139834775e-07, 2.2852525258849945138e-05,
 -3.8988049951376544809e-05, 3.3457990867145604644e-06, -6.5071674594714522125e-05, 1.3151057245217146027e-04,
 -1.4300692659883785588e-05, -3.8434380502066693467e-06, 5.3753772291631534837e-07, 7.5370604827365464148e-07,
  7.5120743302210220676e-08, -4.2333662535568228056e-07, 4.2887647366700935927e-07, -5.6584058499220633837e-07,
  9.4522019575817941164e-08, 6.0691181559721841267e-07],
[  1.5339921531474765508e-06, -1.9469804903977276144e-06, -6.0357744008440835536e-07, -1.4338118241669328810e-06,
  5.6847434782544964800e-06, -1.5132598154442973713e-06, -3.1993968205147471374e-06, -1.4300692659883785588e-05,
  7.6077685013634374969e-06, 1.5192539154507005295e-06, -4.8637800074582419917e-07, -1.3882025984989911367e-06,
 -4.6096359757604052334e-07, -1.2933530803779982199e-06, 5.1620715459838551317e-07, 1.8315394484876420663e-06,
 -3.9659582669124663831e-07, 2.4914673253400029882e-06],
[ -8.3912046455898568363e-06, 1.6817277476448176928e-06, 7.2940831545005416834e-07, -8.2814094879237150820e-06,
  3.7840234999380506730e-07, 2.8439571680093519393e-06, -4.5761153552121580521e-06, -3.8434380502066684996e-06,
  1.5192539154507005295e-06, 2.3580551581010146214e-05, -4.0826256176844557259e-06, -1.9470160315608835941e-06,
 -1.5985577490895219141e-05, -7.0382497672300478134e-06, -1.3471074972815663849e-05, -2.3838740544305559338e-05,
  2.1981854163110550753e-05, 8.1274031311220209459e-06],
[  5.2033871746176188129e-07, -3.5312560677364362299e-05, 2.4099327483036244200e-05, -2.5172161262231661427e-06,
 -3.9835066642550023282e-06, 1.3109838220762297868e-06, 6.8038229608618740673e-06, 5.3753772291631503073e-07,
 -4.8637800074582441092e-07, -4.0826256176844557259e-06, 2.9813381962734028882e-05, -1.2453240604130596341e-06,
 -8.1834599746255672331e-06, -1.3818361370956393336e-05, -1.4045897657535346773e-05, 2.3632892679526815258e-05,
 -4.0535889654513385897e-05, -9.7936191937069982667e-06],
[  2.8397884864543889787e-06, 2.4943720695895094379e-05, -3.2245878965596542131e-05, 4.2893232062647649894e-06,
  1.2983551577352654629e-06, -1.7348425232743940823e-06, -3.7069107762320107160e-08, 7.5370604827365432385e-07,
 -1.3882025984989915602e-06, -1.9470160315608835941e-06, -1.2453240604130596341e-06, 2.6629893843426370541e-05,
 -1.9608248137175574011e-05, -1.6332258008013109135e-05, -3.8827145510905184073e-05, 8.7230995749557529165e-06,
 -9.5481592906228155321e-06, -1.3442317724094680022e-05],
[  1.1540866569804099043e-06, 1.2810852306119976101e-07, 1.8929096863578708907e-06, -1.4574654808322307842e-06,
 -1.2342127583594664735e-06, -2.0508732496471428866e-06, 4.2605995651567894304e-07, 7.5120743302211028004e-08,
 -4.6096359757604015276e-07, -1.5985577490895222529e-05, -8.1834599746255672331e-06, -1.9608248137175574011e-05,
  5.3142336179174688140e-05, 2.6953011252655272164e-05, 6.2632232666971537818e-05, 5.4669582365750346134e-06,
  5.3406385240191917976e-06, 1.0673377734273272385e-05],
[  7.6502877195009575924e-06, 5.2832296574101113179e-06, 1.2987006198095697948e-05, -4.7722429842521690019e-07,
 -9.5042860827452914948e-07, -1.0315842056999891496e-07, -5.4565436277699979980e-07, -4.2333662535568339229e-07,
 -1.2933530803779988552e-06, -7.0382497672300478134e-06, -1.3818361370956393336e-05, -1.6332258008013109135e-05,
  2.6953011252655275552e-05, 5.1298589467256022084e-05, 5.6995916052827023772e-05, -8.1245443002887434385e-06,
 -5.1968919689740851784e-06, -1.1977071842944974722e-05],
[ -7.2546718782771170203e-06, -7.7463112370587695334e-06, -8.7138155976158768553e-06, -1.3223028593561090855e-06,
 -4.0919282893623251937e-07, -4.9929687993861408195e-07, -1.6964272504802540569e-07, 4.2887647366700935927e-07,
  5.1620715459838572493e-07, -1.3471074972815663849e-05, -1.4045897657535346773e-05, -3.8827145510905184073e-05,
  6.2632232666971537818e-05, 5.6995916052827030548e-05, 1.4743448232719687089e-04, -4.1614840156383791104e-06,
  2.0064919359475556352e-07, -3.5359764541647034757e-06],
[  3.0751087009984719641e-07, -2.4497143155063846378e-06, 3.8727807940591447131e-07, -3.2144474988509354573e-06,
  3.5072865233435842987e-06, 8.6172651077260021184e-07, -3.6401225862765453229e-06, -5.6584058499220665601e-07,
  1.8315394484876424898e-06, -2.3838740544305559338e-05, 2.3632892679526811870e-05, 8.7230995749557529165e-06,
  5.4669582365750346134e-06, -8.1245443002887451325e-06, -4.1614840156383782634e-06, 9.1216123865756263528e-05,
 -8.2510545259704650605e-05, -3.1130996484799605163e-05],
[  6.6199568823411368145e-06, -7.3285692747166421225e-06, -6.5608929080913637750e-06, -8.2457777062527649214e-07,
  2.4296937643214376108e-06, 5.0703693877717615755e-07, -2.4559265771047112915e-06, 9.4522019575817544117e-08,
 -3.9659582669124595009e-07, 2.1981854163110550753e-05, -4.0535889654513385897e-05, -9.5481592906228155321e-06,
  5.3406385240191909505e-06, -5.1968919689740851784e-06, 2.0064919359475564293e-07, -8.2510545259704650605e-05,
  1.4392122071336894756e-04, 3.7954383542922142910e-05],
[ -8.8853431683582578506e-06, 1.1402843374263565645e-05, 5.0883768383658575690e-06, 9.7999301067991463306e-08,
 -1.2151230175285080900e-06, -8.3356938947532256988e-07, 9.6016337641870877469e-07, 6.0691181559721777740e-07,
  2.4914673253400029882e-06, 8.1274031311220209459e-06, -9.7936191937069982667e-06, -1.3442317724094680022e-05,
  1.0673377734273270691e-05, -1.1977071842944974722e-05, -3.5359764541647026286e-06, -3.1130996484799611939e-05,
  3.7954383542922142910e-05, 4.5216898714936450045e-05]])

L=np.zeros((2,len(A),len(A)-6))

ftemp,Ltemp=np.linalg.eig(A)
L[1]=np.real(Ltemp)[:].T[6:].T 
ftemp,Ltemp=np.linalg.eig(A)
L[0]=np.real(Ltemp)[:].T[6:].T 
print(np.linalg.norm(L[0]-L[1]))

ftemp,Ltemp=np.linalg.eig(A)
L[1]=np.real(Ltemp)[:].T[6:].T 
ftemp,Ltemp=np.linalg.eig(A)
L[0]=np.real(Ltemp)[:].T[6:].T 
print(np.linalg.norm(L[0]-L[1]))

ftemp,Ltemp=np.linalg.eig(A)
L[1]=np.real(Ltemp)[:].T[6:].T 
ftemp,Ltemp=np.linalg.eig(A)
L[0]=np.real(Ltemp)[:].T[6:].T 
print(np.linalg.norm(L[0]-L[1]))
#output:
#0.0
#2.8914368725
#0.0
#0.0
#0.0
#2.8914368725
#0.0
#0.0
#0.0
#7.32973786166e-16
#2.8914368725
#2.8914368725

gdb-run:
gdb /usr/bin/python
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
http://bugs.launchpad.net/gdb-linaro/...
Reading symbols from /usr/bin/python...(no debugging symbols found)...done.
(gdb) run "bug3.py"
Starting program: /usr/bin/python "bug3.py"
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
0.0
2.8914368725
2.8914368725
[Inferior 1 (process 7925) exited normally]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions