Project the given geometries.
(
tagged_points: TaggedPointSequence, kind, dimensions, scale
)
| 52 | |
| 53 | |
| 54 | def _fit_transform( |
| 55 | tagged_points: TaggedPointSequence, kind, dimensions, scale |
| 56 | ) -> TaggedPointSequence: |
| 57 | """Project the given geometries.""" |
| 58 | points, tags = unzip(tagged_points) |
| 59 | |
| 60 | # Convert the generator of points to an array of points. |
| 61 | # This will consume the generator, and keep the points loaded in memory. |
| 62 | points = scale * np.array(list(_zeropad_3d(points))) |
| 63 | |
| 64 | # TruncatedSVD picked a sideways view |
| 65 | # PCA picked a top-down view |
| 66 | if kind == "pca": |
| 67 | decomp = PCA(n_components=dimensions) |
| 68 | elif kind == "svd": |
| 69 | if dimensions >= 3: |
| 70 | raise ValueError("SVD cannot be used for 3D -> 3D projections") |
| 71 | decomp = TruncatedSVD(n_components=dimensions, n_iter=5) |
| 72 | else: |
| 73 | raise ValueError(f"Unsupported projection '{kind}'") |
| 74 | transformed = decomp.fit_transform(points) |
| 75 | |
| 76 | return zip(transformed, tags) |
| 77 | |
| 78 | |
| 79 | def _rot_x(theta): |
no test coverage detected