def __init__(self, X): assert X.shape[0] == 2 p = X[0] q = X[1] if p[..., -1] < q[..., -1]: self.X = X else: self.X = np.array([q, p]) y = X[..., -1:] A = np.hstack([X[..., :-1], np.ones((X.shape[0], 1), dtype=X.dtype)]) self.theta = (np.linalg.lstsq(A, y)[0]).flatten()
def calc_has_crossing(line, line_seg): ''' Has line a crossing with the line segment ''' if np_allclose(line.theta[..., :-1], line_seg.theta[..., :-1]): return False else: A = np.vstack([line.theta, line_seg.theta]) b = -A[..., -1:] A[..., -1] = -np.ones(len(A)) intersection_point = (np.linalg.solve(A, b)).flatten() x = intersection_point[..., :-1] return line_seg.is_between(x)
def create_all_edges(n): adj_matrix = np.ones((n, n), dtype=bool) for i in range(0, n): adj_matrix[i, i] = False edges = Edges(n, adj_matrix) return edges
def __call__(self, X): paddedX = np.hstack([X, np.ones((X.shape[0], 1), dtype=X.dtype)]) y = np.dot(paddedX, self.theta) return y.flatten()