tsgm.utils.visualization¶
Module Contents¶
- visualize_dataset(dataset: tsgm.dataset.DatasetOrTensor, obj_id: int = 0, palette: dict = DEFAULT_PALETTE_TSNE, path: str = '/tmp/generated_data.pdf') None[source]¶
The function visualizes time series dataset with target values.
- Parameters:
dataset (tsgm.dataset.DatasetOrTensor.) – A time series dataset.
- visualize_tsne_unlabeled(X: tsgm.types.Tensor, X_gen: tsgm.types.Tensor, palette: dict = DEFAULT_PALETTE_TSNE, alpha: float = 0.25, path: str = '/tmp/tsne_embeddings.pdf', fontsize: int = 20, markerscale: int = 3, markersize: int = 1, feature_averaging: bool = False, perplexity: float = 30.0) None[source]¶
Visualizes t-SNE embeddings of unlabeled data.
- Parameters:
X (tsgm.types.Tensor) – The original data tensor of shape (num_samples, num_features).
X_gen (tsgm.types.Tensor) – The generated data tensor of shape (num_samples, num_features).
palette (dict, optional) – A dictionary mapping class labels to colors. Defaults to DEFAULT_PALETTE_TSNE.
alpha (float, optional) – The transparency level of the plotted points. Defaults to 0.25.
path (str, optional) – The path to save the visualization as a PDF file. Defaults to “/tmp/tsne_embeddings.pdf”.
fontsize (int, optional) – The font size of the class labels in the legend. Defaults to 20.
markerscale (int, optional) – The scaling factor for the size of the markers in the legend. Defaults to 3.
markersize (int, optional) – The size of the markers in the scatter plot. Defaults to 1.
feature_averaging (bool, optional) – Whether to compute the average features for each class. Defaults to False.
- visualize_tsne(X: tsgm.types.Tensor, y: tsgm.types.Tensor, X_gen: tsgm.types.Tensor, y_gen: tsgm.types.Tensor, path: str = '/tmp/tsne_embeddings.pdf', feature_averaging: bool = False, perplexity=30.0) None[source]¶
Visualizes t-SNE embeddings of real and synthetic data.
This function generates a scatter plot of t-SNE embeddings for real and synthetic data. Each data point is represented by a marker on the plot, and the colors of the markers correspond to the corresponding class labels of the data points.
- Parameters:
X (tsgm.types.Tensor) – The original real data tensor of shape (num_samples, num_features).
y (tsgm.types.Tensor) – The labels of the original real data tensor of shape (num_samples,).
X_gen (tsgm.types.Tensor) – The generated synthetic data tensor of shape (num_samples, num_features).
y_gen (tsgm.types.Tensor) – The labels of the generated synthetic data tensor of shape (num_samples,).
path (str, optional) – The path to save the visualization as a PDF file. Defaults to “/tmp/tsne_embeddings.pdf”.
feature_averaging (bool, optional) – Whether to compute the average features for each class. Defaults to False.
- visualize_ts(ts: tsgm.types.Tensor, num: int = 5) None[source]¶
Visualizes time series tensor.
This function generates a plot to visualize time series data. It displays a specified number of time series from the input tensor.
- Parameters:
ts (tsgm.types.Tensor) – The time series data tensor of shape (num_samples, num_timesteps, num_features).
num (int, optional) – The number of time series to display. Defaults to 5.
- Raises:
AssertionError: If the input tensor does not have three dimensions.
- Example:
>>> visualize_ts(time_series_tensor, num=10)
- visualize_ts_lineplot(ts: tsgm.types.Tensor, ys: tsgm.types.OptTensor = None, num: int = 5, unite_features: bool = True) None[source]¶
Visualizes time series data using line plots.
This function generates line plots to visualize the time series data. It randomly selects a specified number of samples from the input tensor
tsand plots each sample as a line plot. Ifysis provided, it can be either a 1D or 2D tensor representing the target variable(s), and the function will optionally overlay it on the line plot.- Parameters:
ts (tsgm.types.Tensor) – Input time series data tensor.
ys (tsgm.types.OptTensor, optional) – Optional target variable(s) tensor, defaults to None.
num (int, optional) – Number of samples to visualize, defaults to 5.
unite_features (bool, optional) – Whether to plot all features together or separately, defaults to True.
- visualize_original_and_reconst_ts(original: tsgm.types.Tensor, reconst: tsgm.types.Tensor, num: int = 5, vmin: int = 0, vmax: int = 1) None[source]¶
Visualizes original and reconstructed time series data.
This function generates side-by-side visualizations of the original and reconstructed time series data. It randomly selects a specified number of samples from the input tensors
originalandreconstand displays them as images using imshow.- Parameters:
original (tsgm.types.Tensor) – Original time series data tensor.
reconst (tsgm.types.Tensor) – Reconstructed time series data tensor.
num (int, optional) – Number of samples to visualize, defaults to 5.
vmin (int, optional) – Minimum value for colormap normalization, defaults to 0.
vmax (int, optional) – Maximum value for colormap normalization, defaults to 1.
- visualize_training_loss(loss_vector: tsgm.types.Tensor, labels: tuple = (), path: str = '/tmp/training_loss.pdf') None[source]¶
Plot training losses as a function of the epochs
- Parameters:
loss_vector – np.array, having shape num of metrics times number of epochs
labels – list of strings
path – str, where to save the plot