Module ml4opf.viz.plot

Functions

def interp_curves(convergence_curves: list['DataFrame'],
column: str,
max_time: int | None = None,
n_time_steps: int = 2000,
kind: str = 'previous',
fill_value: str | None = None) ‑> tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]

Interpolate convergence curves to have the same start/end/number of time steps.

Args

convergence_curves : list[DataFrame]
List of DataFrames with columns 'time' and column
column : str
Column to interpolate. All convergence_curves must have this column.
max_time : int, optional
Maximum time to interpolate to. If None, use the maximum time of all convergence curves. Default: None
n_time_steps : int, optional
Number of time steps to interpolate to. Default: 2000
kind : str, optional
Interpolation kind. Default: 'previous'
fill_value : str, optional
Fill value for time steps before the first point. If None, return None for any time steps before the first point and the last point for any time steps after the last point. Default: None

Returns

tuple[np.ndarray, np.ndarray, np.ndarray]
Interpolated times, means, and standard deviations
def plot_pca(tensor: torch.Tensor,
label: str,
color_by: torch.Tensor | None = None,
logy: bool = False,
logx: bool = False,
xlim: tuple[float, float] = None,
ylim: tuple[float, float] = None,
subplots_kwargs: dict = None,
scatter_kwargs: dict = None,
show: bool = True)

Plot PCA of a 2D tensor.

Args

tensor : Tensor
Tensor of shape [batch, n_features]
label : str
Label for the plot
color_by : Tensor, optional
Tensor of shape [batch, 1] to color the points by. Default: None
logy : bool, optional
Whether to use a log scale for the y-axis. Default: False
logx : bool, optional
Whether to use a log scale for the x-axis. Default: False
xlim : tuple[float, float], optional
X-axis limits. Default: None
ylim : tuple[float, float], optional
Y-axis limits. Default: None
subplots_kwargs : dict, optional
Keyword arguments for plt.subplots(). Default: {'figsize':(8,5), 'dpi':300}
scatter_kwargs : dict, optional
Keyword arguments for ax.scatter(). Default: {'marker': '.'}
show : bool, optional
Whether to show the plot. Default: True
def plot_wrt_total_load(pd: torch.Tensor,
metrics: list[torch.Tensor],
labels: list[str],
title: str,
ylabel: str,
logy: bool = False,
xlim: tuple[float, float] = None,
ylim: tuple[float, float] = None,
subplots_kwargs: dict = None,
plot_kwargs: dict = None,
legend: bool = True,
show: bool = True)

Plot metrics vs total active load

Args

pd : Tensor
Active load tensor of shape [batch, n_loads]. pd.sum(dim=1) becomes the x-axis.
metrics : list[Tensor]
List of metrics tensors of shape [batch, 1] <- one number per sample
labels : list[str], optional
List of labels for each metric
title : str, optional
Plot title
ylabel : str, optional
Y-axis label
logy : bool, optional
Whether to use a log scale for the y-axis. Default: False
xlim : tuple[float, float], optional
X-axis limits. Default: None
ylim : tuple[float, float], optional
Y-axis limits. Default: None
subplots_kwargs : dict, optional
Keyword arguments for plt.subplots(). Default: {'figsize':(8,5), 'dpi':300}
plot_kwargs : dict, optional
Keyword arguments for ax.plot() (same for every metric). Default: {'ls':'', 'marker': '.', 'ms':0.75}
show : bool, optional
Whether to show the plot. Default: True