View Single Post
  #3   Spotlight this post!  
Unread 26-05-2013, 01:30
DMetalKong's Avatar
DMetalKong DMetalKong is offline
Registered User
AKA: David K.
no team
Team Role: College Student
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Bridgewater
Posts: 144
DMetalKong is a jewel in the roughDMetalKong is a jewel in the roughDMetalKong is a jewel in the rough
Send a message via AIM to DMetalKong
Re: OPR-computation-related linear algebra problem

Using Python with Numpy

System:
Code:
Ubuntu 12.04 32-bit
Kernel Linux 3.2.0-43-generic-pae
Memory 3.8 GiB
Processor Intel Core 2 Duo T9400 @ 2.53 GHz x 2
Code:
Code:
import sys
import numpy
import time
import scipy
import psutil

n_runs = 1000

print ""
print ""
print "Python version %s" % (sys.version)
print "Numpy version %s" % (numpy.__version__)
print "Scipy version %s" % (scipy.__version__)
print "Psutil version %s" % (psutil.__version__)
print ""


N = numpy.loadtxt(open('N.dat'))
d = numpy.loadtxt(open('d.dat'))

data = []
for i in range(1,n_runs+1):
    start = time.time()
    x = numpy.linalg.solve(N,d)
    end = time.time()
    row = [end - start]
    row.extend(psutil.cpu_percent(interval=1,percpu=True))
    s = "\t".join([str(item) for item in row])
    data.append(s)
    
f = open('times.dat','w')
f.write("\n".join(data))
f.close()

x = numpy.linalg.solve(N,d)
print ", ".join([str(f) for f in x])
print ""
Average run time: 10.1 seconds
Standard Deviation: 5.1 seconds

The file output.txt contains versions and the solution for x.
The file runs.txt contains the run data. Note that I was doing work while letting this run in the backround, which skews the times. I collected CPU usage data to try and account for this; one interesting note is that there are two different clusters of execution times - I believe this is from my laptop throttling the CPU when I unplugged and was running off battery for a while (if you plot runs over time, you will see three distinct sections where the execution times are consistently higher).
Attached Thumbnails
Click image for larger version

Name:	times.png
Views:	68
Size:	32.7 KB
ID:	14869  
Attached Files
File Type: txt runs.txt (23.2 KB, 4 views)
File Type: txt output.txt (37.1 KB, 7 views)

Last edited by DMetalKong : 26-05-2013 at 01:32.
Reply With Quote