Package: pca3dvis
PCA 3D VisualizationsThis module produces informative visualizations of atleast 3-dimensional data,
optionally using principal component analysis and automatic clustering.FeaturesAnimated: high-quality videos with multi-processed video production usingpympanim.(Pdf)snapshotsthat can be used in research papers or where the full video
cannot be used.Supports automaticclusteringfor informative zoomsSupportstrajectoriesof data, for example for visualizing data through
time for a recurrent network or through layers of a feedforward network.Supports using different markers, in any combination of style and colorInstallationThis package requiresffmpegto be installed.pip install pca3dvisExample Videosexamples/gaus_balls.pyhttps://youtu.be/n9rpWhuN6LAexamples/all_rand.pyhttps://www.youtube.com/watch?v=YnIRqSQ8lAUUsageVideo introduction athttps://youtu.be/JqfVY9pdxY8Projecting to 3D from higher dimensionsThere are many approaches for projecting to 3-dimensions. Once you have used
any of these projections, you can use this library to visualize the resulting
3d scatter plot.This library provides one linear projection that depends on the eigenvectors
of the covariance matrix, called principal component analysis. For more
information seeWold, Esbensen, and Geladi, 1987To quickly generate apca3dvis.trajectory.ProjectedTrajectoryusing this
technique for an arbitraryndarray[samples, features]wherefeatures > 3,
the following snippet will work:importnumpyasnpimportpca3dvis.pcsaspcsdata:np.ndarray# must have shape [samples > 3, features > 3]lbls:np.ndarray# must have shape [samples = data.shape[0], ...]traj=pcs.get_pc_trajectory([data],lbls)This creates a trajectory with a single snapshot; for multiple snapshots, just
have[data]instead be a list of ndarrays which each have the same number of
samples but possibly different numbers of features.Converting 3D data to trajectoriesA trajectory is a sequence of one or more snapshots which have the same labels.
They include the projection matrix that created them from the original data.
For quickly plotting already projected data, the labels can be swapped with all
zeros of the appropriate shape and the projection matrix with the identity map.importnumpyasnpimportpca3dvis.snapshotimportpca3dvis.trajectoryraw_data:np.ndarray# must have shape [samples > 3, og_features]proj_matrices:np.ndarray# must have shape [og_features, 3]lbls:np.ndarray# must have shape [samples = data.shape[0], ...]snap=pca3dvis.snapshot.project_with_matrix(raw_data,lbls,proj_matrices)traj=pca3dvis.trajectory.ProjectedTrajectory([snap])# trajectory of one snapPlotting trajectoriesPlotting trajectories, the main feature of this module, requires only that you
give a name to each snapshot and give markers to each label.Markers are described as follows: Suppose there are N samples and M distinct
styles. Then for each style m, you will create a bool numpy array with shape
(N,) mask wheremask[i]isTrueifsample[i]should be rendered with
stylem. The style is described with adictwhich are the keyword arguments
toscatter.
It should at least specifiy the size and color (sandcrespectively), and
it may use acolormapto do so, but if it does it must specify thenormexactly, i.e., with vmin and vmax not None.For a more complete example of styling, seeexamples/gaus_balls.py.importnumpyasnpimportpca3dvis.trajectoryimportpca3dvis.workertraj:pca3dvis.trajectory.ProjectedTrajectorytitles=[f'Snapshot{i+1}'foriinrange(traj.num_snapshots)]markers=[(np.ones(traj.num_samples,'bool'),{'s':20,'c':'tab:red'})]pca3dvis.worker.generate(traj,markers,titles,'out/my_out_folder',draft=True,clusters=True)