Visualization Methods

softsensor.visualization.plot_all_weight_matrices(model, abs_values=False, rel_threshold=0.1, use_case=None, save_path=None)[source]

Visualize all weight matrices of the model as heatmaps and their distributions as histograms, highlighting the percentage of weights that fall within a certain threshold range.

Parameters:
  • model (nn.module) – Model consisting of nn.Modules

  • abs_values (bool, optional) – If the absolute values of the weight matrix entries should be plotted. The default is False.

  • rel_threshold (float, optional) – Threshold value for the percentage of weights that fall within the range [-threshold, threshold]. The default is 0.1, i.e. 10 % of the maximum absolute value of each weight matrix.

  • use_case (string, optional) – Use case for the channel names. The default is None.

  • save_path (string, optional) – Path to save the plots. The default is None, i.e. the plots are not saved.

softsensor.visualization.plot_calibration_curve(dataframe, ground_truth, model_names, quantiles=array([0., 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.]), show_legend=False)[source]
Runs the model prediction on track and plots the calibration at different quantile levels

Assumes that Quantile Regression models have QR in their name and that all other models predict mean and variance

Parameters:
  • models (list[uncertainty models]) – Models to use for prediction

  • track (torch.Dataloader) – Single track

  • track_number (int) – Number of track in the test set

  • out_sens (list[string]) – Names of output sensors

  • output (int, optional) – Output sensor to plot. The default is 0.

  • quantiles (list[x], x in (0,1)) – Quantile levels to analyze for calibration curve. The default is np.arange(0.0, 1.05, 0.05)

  • fig_path (string, optional) – Path to save fig. The default is None

Return type:

None.

softsensor.visualization.plot_feature_importance(model, sensitivity, time_step, ch_names=None, use_case=None, save_path=None)[source]

Visualize the feature importance of the sensitivity tensor for a given model, at a specific time step.

softsensor.visualization.plot_first_weight_matrix(model, abs_values=False, ch_names=None, use_case=None, save_path=None)[source]

Visualize the model’s first weight matrix and subsequent slices of it as heatmaps, to compare with the sensitivity plots.

Parameters:
  • model (nn.module) – Model consisting of nn.Modules

  • abs_values (bool, optional) – If the absolute values of the weight matrix entries should be plotted. The default is False.

  • save_path (string, optional) – Path to save the plots. The default is None, i.e. the plots are not saved.

softsensor.visualization.plot_grad_sens_comparison(vals_dict, models, sum_mean_std_list, ch_names=None, use_case=None, scientific_notation=False, save_path=None)[source]

Visualize the comparison of the sensitivity tensors of different models for the same prediction type.

Parameters:
  • vals_dict (dict) – Dict, containing the mode to compare, e.g. alpha, excitation amplitude/frequency; as well as the values to compare, e.g. [0.1, 0.2, 0.3]

  • models (list[Model consisting of nn.Modules]) – Models consisting of nn.Modules

  • sum_mean_std_list (list of torch.Tensor) – List of sensitivity tensors that contain the gradients of the output with respect to the inputs

  • ch_names (list of strings, optional) – List of channel names. The default is None, i.e. the channel names are not provided and will be generated in the style of ‘Inp_ch_i’ and ‘Rec_ch_i’.

  • scientific_notation (bool, optional) – If the plot legends should be displayed in LaTeX scientific notation. The default is False.

  • save_path (string, optional) – Path to save the plots. The default is None, i.e. the plots are not saved.

softsensor.visualization.plot_sens_analysis(model, sensitivity, ch_names=None, title=None, use_case=None, annotations=False, orig_length=None, save_path=None)[source]

Visualize different metrics/insights of the post-processed arrays, coming from differently averaged sensitivities.

Parameters:
  • model (Model consisting of nn.Modules)

  • sensitivity (torch.Tensor) – Sensitivity tensor that contains the gradients of the output with respect to the inputs

  • ch_names (list of strings, optional) – List of channel names. The default is None, i.e. the channel names are not provided and will be generated in the style of ‘Inp_ch_i’ and ‘Rec_ch_i’.

  • title (string, optional) – Title for the plot series. The default is None, i.e. no title is displayed.

  • annotations (bool, optional) – If the plot should contain the percentages of the channel-wise mean sensitivities. The default is False.

  • orig_length (int, optional) – Original length of the time series. Only needed when sensitivity analysis is performed on subset of the data. The default is None, i.e. the original length is not provided.

  • save_path (string, optional) – Path to save the plots. The default is None, i.e. the plots are not saved.

softsensor.visualization.plot_uncertainty(dataframe, mean, var, ground_truth=None, t_start=None, t_end=None, n_std=2, show_legend=False)[source]

Plots the prediction with distributional uncertainty

Parameters:
  • mean (torch.Tensor) – Point prediction

  • std (torch.Tensor) – Uncertainty estimate

  • t_start (int, optional) – Start of plotting window

  • t_end (int, optional) – End of plotting window

  • ground_truth (torch.Tensor, optional) – Ground truth of point prediction

  • fs (int, optional) – Sampling rate. The default is 10

  • n_std (int, optional) – Amount of standard deviations to plot. The default is 2

  • show_legend (bool, optional) – Show legend in the plot. The default is False

  • title (string, optional) – Title for the plot. The default is None

  • title_info (dict[string,string], optional) – Must contain keys [‘dataset’, ‘model’, ‘track’, ‘sensor’]. The default is None.

  • fig_path (string, optional) – Path to save fig. The default is None

  • is_duffing (bool, optional) – Whether it is position prediction (like Duffing dataset) or acceleration prediction. The default is True.

  • show (bool, optional) – If the plot should be displayed. The default is True.

Return type:

None.

softsensor.visualization.plot_uncertainty_both(dataframe, mean, epistemic_var, aleatoric_var, ground_truth=None, t_start=None, t_end=None, n_std=2, show_legend=False)[source]

Plots the prediction with aleatoric and epistemic uncertainty

Parameters:
  • mean (torch.Tensor) – Point prediction

  • epistemic_std (torch.Tensor) – Epistemic uncertainty estimate (e.g. ensemble, mcdo)

  • aleatoric_std (torch.Tensor) – Aleatoric uncertainty estimate (e.g. mve)

  • t_start (int, optional) – Start of plotting window

  • t_end (int, optional) – End of plotting window

  • ground_truth (torch.Tensor, optional) – Ground truth of point prediction

  • fs (int, optional) – Sampling rate. The default is 10

  • n_std (int, optional) – Amount of standard deviations to plot. The default is 2

  • show_legend (bool, optional) – Show legend in the plot. The default is False

  • title (string, optional) – Title for the plot. The default is None

  • title_info (dict[string,string], optional) – Must contain keys [‘dataset’, ‘model’, ‘track’, ‘sensor’]. The default is None.

  • fig_path (string, optional) – Path to save fig

Return type:

None.

softsensor.visualization.plot_uncertainty_sens(model, sens_uq, eps, ch_names, use_case=None, amplification=1, save_path=None)[source]

Visualize the uncertainty of the sensitivity tensor for a given model.

Parameters:
  • model (Model consisting of nn.Modules)

  • sens_uq (torch.Tensor) – Sensitivity tensor that contains the gradients of the output with respect to the inputs

  • eps (float) – Epsilon value for the uncertainty quantification

  • ch_names (list of strings) – List of channel names

  • use_case (string, optional) – Use case for the channel names. The default is use_case.

  • amplification (int, optional) – Amplification factor for the uncertainty quantification of sensitivities of MVE models. The default is 1.

  • save_path (string, optional) – Path to save the plots. The default is None, i.e. the plots are not saved.