src.plot_latents

plot_latents.py

Visualize latent representations from an autoencoder using dimensionality reduction.

This script: - Loads latent feature vectors and labels from a compressed .npz file. - Computes the Silhouette Score using cosine distance (if labels are available). - Applies dimensionality reduction (UMAP or PCA) to project the latent space to 2D. - Displays a scatter plot of the embedded data, optionally saving the plot.

Usage:

python plot_latents.py –input path/to/X_latent_data.npz –method umap –save

Functions

extract_fold_number(path_str)

Extract fold number (e.g., 'fold3') from folder or file path.

extract_model_suffix(path_str)

Extract model suffix (e.g., 'B') from folder name like 'latent_len295_B_fold2'.

extract_segment_length(path_str)

Extract segment length (e.g. 295) from path like 'latent_len295_fold4'.

load_latents(npz_path)

Load latent vectors and labels from a .npz file.

main()

Main function to load latent data, compute Silhouette Score, and visualize embeddings.

plot_embedding(X[, y, method, title, save, ...])

Reduce dimensionality of latent space and generate a scatter plot.