def computeH(pts1, pts2): l1, l2 = len(pts1), len(pts2) assert l1 == l2 A = [] B = [] for j in range(l1 * 2): i = int(j / 2) if (j % 2 == 0): A.append([ pts1[i][0], pts1[i][1], 1, 0, 0, 0, -pts2[i][0] * pts1[i][0], -pts2[i][0] * pts1[i][1] ]) else: A.append([ 0, 0, 0, pts1[i][0], pts1[i][1], 1, -pts2[i][1] * pts1[i][0], -pts2[i][1] * pts1[i][1] ]) for i in range(l2): B.append(pts2[i][0]) B.append(pts2[i][1]) # H matrix 3*3 a, b, c, d, e, f, g, h = lstsq(A, B)[0] return [[a, b, c], [d, e, f], [g, h, 1]]
def draw_edge(img): univ = depth_to_edge_univ(img) xs, ys = img_to_dots(univ) A = np.array([xs, np.ones(xs.size)]) w = linalg.lstsq(A.T, ys)[0] # slope, intercept, r_value, p_value, std_err = scipy.stats.linregress(xs, ys) for y in range(0, univ.shape[1]): x = int(y * w[0]) + w[1] if x < univ.shape[1] and y < univ.shape[0]: univ[x, y] = 254 return univ
def _linregression(self, x, y): m, c = linalg.lstsq(numpy.vstack([x, numpy.ones(len(x))]).T, y)[0] return m, c
sline = line.split(',') aaa = [] year = np.array([[1,1980],[1,1984],[1,1988],[1,1992],[1,1996],[1,2000],[1,2004],[1,2008]]) x = np.array(float(sline[1])) for i in range(7): # a.append(int(sline[i+1])) a = np.array(float(sline[2+2*i])) x = np.vstack((x,a)) print x ''' if cnt == 30: plt.plot(x) plt.show() ''' #Do the regression here: reg = lsq.lstsq(year,x) rr = reg[0] a = rr[0] b = rr[1] a12 = float(a + 2012*b) print a12 for i in range(8): aaa.append(float(x[i])) aaa.append(a12) writer.writerow(aaa) cnt += 1 if cnt >50: break f1.close()
def find_coefficients(data, exponents): X = tuple((tuple((pow(x,p) for p in exponents)) for (x,y) in data)) y = tuple(((y) for (x,y) in data)) x, resids, rank, s = lstsq(X,y) return x