Hi everyone,
I'm currently trying to use skleanr.Transform.SimilarityTransform to remove
scaling translation and rotation from one set of points to align it to the
other.
However, if I centre the sets around the origin first, there seems to be
frequently a problem (which doesn't occur if the points are all positives),
the output being NaN.
I tried to write a small reproducible code:
In [77]:
#I fixed the seed here for reproducibility but this happens often
np.random.seed(4)
#Two random set of points
a = np.random.randn(10, 2)
b = np.random.randn(10, 2)
# Center the points arount the origin
a -= np.mean(a, axis=0)[np.newaxis, :]
b -= np.mean(b, axis=0)[np.newaxis, :]
tform = SimilarityTransform()
tform.estimate(a, b)
tform(a)
Out[77]:
array([[ nan, nan],
[ nan, nan],
[ nan, nan],
[ nan, nan],
[ nan, nan],
[ nan, nan],
[ nan, nan],
[ nan, nan],
[ nan, nan],
[ nan, nan]])
Note that if I don't centre the point there is no problem:
In [89]:
#I fixed the seed here for reproducibility but this happens often
np.random.seed(4)
#Two random set of points
a = np.random.randn(10, 2)
b = np.random.randn(10, 2)
# Center the points arount the origin
#a -= np.mean(a, axis=0)[np.newaxis, :]
#b -= np.mean(b, axis=0)[np.newaxis, :]
tform = SimilarityTransform()
tform.estimate(a, b)
tform(a)
Out[89]:
array([[ 3.76870886, -0.35152078],
[ 1.83453334, -1.25080725],
[ 5.42428044, -4.30088121],
[ 2.51364241, -1.00154154],
[ 6.14244682, -2.71511189],
[ 5.37956586, -0.65190768],
[ 4.5752074 , -0.19039746],
[ 1.96968262, -1.99729896],
[ 1.47865106, 0.59493455],
[ 5.39473376, -0.31125435]])
Sometime it also tells me that the *SVD doesn't converge*.
Any idea what is going on?
Thanks,
Jean