Skip to content

Commit

Permalink
Remove numpy dependency
Browse files Browse the repository at this point in the history
Instead of numpy LSE use straight formula for the single variable case.
  • Loading branch information
baruch committed Mar 20, 2015
1 parent c2651d0 commit 56545f2
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions stm8/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import csv
import os
import math
import numpy

def calc_average(data):
return reduce(lambda x,y: x+y, data) / len(data)
Expand Down Expand Up @@ -186,12 +185,24 @@ def sample3(self, count):
return None

def lse(xdata, ydata):
x = numpy.array(xdata)
X = numpy.vstack([x, numpy.ones(len(x))]).T
y = numpy.array(ydata)

a = numpy.linalg.lstsq(X, y)[0]
return (a[0], a[1])
assert(len(xdata) == len(ydata))
sum_xy = 0
sum_x = 0
sum_y = 0
sum_x2 = 0
n = len(xdata)
for i in xrange(n):
x_i = xdata[i]
y_i = ydata[i]
sum_xy += x_i*y_i
sum_x += x_i
sum_y += y_i
sum_x2 += x_i*x_i

alpha = (n * sum_xy - sum_x*sum_y) / (n * sum_x2 - sum_x*sum_x)
beta = (sum_y - alpha * sum_x) / n

return (alpha, beta)

def auto_calibration():
psu = B3603(sys.argv[2])
Expand Down

0 comments on commit 56545f2

Please sign in to comment.