Commit fcad586b authored by Taddeüs Kroes's avatar Taddeüs Kroes

ModSim ass4 taddeus: Updated Least Squares usage.

parent 4a2bab4c
#!/usr/bin/env python #!/usr/bin/env python
from sys import argv, stdin from sys import argv, stdin
from pylab import array, matrix, ones, dot, plot, legend, show, savefig from pylab import plot, xlabel, ylabel, legend, show, savefig
from scipy import polyfit, polyval
# Collect data # Collect data
data = [] x = []
y = []
for line in stdin.readlines(): for line in stdin.readlines():
data.append(map(float, line.split(',', 1))) s, t = map(float, line.split(',', 1))
x.append(s)
y.append(t)
# Least squares data fit # Least squares data fit
A = matrix(ones((len(data), 2))) c = tuple(polyfit(x, y, 1).tolist())
data = array(data) fit = polyval(c, [0, x[-1]])
A.T[1] = data.T[0]
b = data.T[1].T
start, slope = tuple(list(dot((A.T * A).I * A.T, b).tolist()[0]))
# Plot and optionally save data # Plot and optionally save data
data = data.T plot(x, y, 'x', label='metingen')
plot(data[0], data[1], 'x', label='original data') plot([0, x[-1]], fit, '-', label='Least Squares fit (y = %ex + %e)' % c)
plot([0, data[0][-1]], [start, data[0][-1] * slope + start], '-',
label='linear fit y = %ex + %e' % (slope, start))
legend() legend()
xlabel('Pakketgrootte')
ylabel('Tijd (s)')
if len(argv) == 2: if len(argv) == 2:
savefig(argv[1]) savefig(argv[1])
show() show()
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
#include <math.h> #include <math.h>
#include <mpi.h> #include <mpi.h>
#define DEBUG //#define DEBUG
#define LOOP 1 // Number of different message sizes #define LOOP 100 // Number of different message sizes
#define STRIDE 10000 // Difference between the message sizes #define STRIDE 10000 // Difference between the message sizes
#define REPEAT 7 // Number of times to repeat aREPEAT measurement #define REPEAT 7 // Number of times to repeat aREPEAT measurement
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment