reformatting code to wrap at 80 characters per line

This commit is contained in:
Kevin Keraudren
2015-12-01 14:32:25 +00:00
parent a606a53875
commit c1c0d18ba1
3 changed files with 20 additions and 12 deletions
+4 -2
View File
@@ -32,7 +32,9 @@ outliers = inliers == False
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(xyz[inliers][:, 0], xyz[inliers][:, 1], xyz[inliers][:, 2], c='b', marker='o', label='Inlier data')
ax.scatter(xyz[outliers][:, 0], xyz[outliers][:, 1], xyz[outliers][:, 2], c='r', marker='o', label='Outlier data')
ax.scatter(xyz[inliers][:, 0], xyz[inliers][:, 1], xyz[inliers][:, 2], c='b',
marker='o', label='Inlier data')
ax.scatter(xyz[outliers][:, 0], xyz[outliers][:, 1], xyz[outliers][:, 2], c='r',
marker='o', label='Outlier data')
ax.legend(loc='lower left')
plt.show()
+6 -4
View File
@@ -188,7 +188,8 @@ class LineModel3D(BaseModel):
elif data.shape[0] > 2: # over-determined
data = data - X0
# first principal component
# Note: without full_matrices=False Python dies with joblib parallel_for.
# Note: without full_matrices=False Python dies with joblib
# parallel_for.
_, _, u = np.linalg.svd(data, full_matrices=False)
u = u[0]
else: # under-determined
@@ -200,8 +201,8 @@ class LineModel3D(BaseModel):
def residuals(self, data):
"""Determine residuals of data to model.
For each point the shortest distance to the line is returned. It is obtained by projecting the data onto the
line.
For each point the shortest distance to the line is returned.
It is obtained by projecting the data onto the line.
Parameters
----------
@@ -214,7 +215,8 @@ class LineModel3D(BaseModel):
Residual for each data point.
"""
X0, u = self.params
return np.linalg.norm((data - X0) - np.dot(data - X0, u)[..., np.newaxis] * u, axis=1)
return np.linalg.norm((data - X0) -
np.dot(data - X0, u)[..., np.newaxis] * u, axis=1)
class CircleModel(BaseModel):
+10 -6
View File
@@ -56,10 +56,12 @@ def test_line_model_under_determined():
def test_line_model3D_estimate():
# generate original data without noise
model0 = LineModel3D()
model0.params = (np.array([0,0,0], dtype='float'), np.array([1,1,1], dtype='float')/np.sqrt(3))
# we scale the unit vector with a factor 10 when generating points on the line
# in order to compensate for the scale of the random noise
data0 = model0.params[0] + 10 * np.arange(-100,100)[...,np.newaxis] * model0.params[1]
model0.params = (np.array([0,0,0], dtype='float'),
np.array([1,1,1], dtype='float')/np.sqrt(3))
# we scale the unit vector with a factor 10 when generating points on the
# line in order to compensate for the scale of the random noise
data0 = (model0.params[0] +
10 * np.arange(-100,100)[...,np.newaxis] * model0.params[1])
# add gaussian noise to data
np.random.seed(1234)
@@ -70,9 +72,11 @@ def test_line_model3D_estimate():
model_est.estimate(data)
# test whether estimated parameters are correct
# we use the following geometric property: two aligned vectors have a cross-product equal to zero
# we use the following geometric property: two aligned vectors have
# a cross-product equal to zero
# test if direction vectors are aligned
assert_almost_equal(np.linalg.norm(np.cross(model0.params[1], model_est.params[1])), 0, 1)
assert_almost_equal(np.linalg.norm(np.cross(model0.params[1],
model_est.params[1])), 0, 1)
# test if origins are aligned with the direction
a = model_est.params[0] - model0.params[0]
if np.linalg.norm(a) > 0: