MCPcopy Create free account
hub / github.com/Notgnoshi/generative / _fit_transform

Function _fit_transform

generative/projection.py:54–76  ·  view source on GitHub ↗

Project the given geometries.

(
    tagged_points: TaggedPointSequence, kind, dimensions, scale
)

Source from the content-addressed store, hash-verified

52
53
54def _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
79def _rot_x(theta):

Callers 1

projectFunction · 0.85

Calls 2

unzipFunction · 0.85
_zeropad_3dFunction · 0.85

Tested by

no test coverage detected