pymcdm_reidentify.visuals package
pymcdm_reidentify.visuals.fitness_plot
- pymcdm_reidentify.visuals.fitness_plot.fitness_plot(method, plot_kwargs={}, ax=None)
Plots the evolution of the global best fitness over the epochs of an optimization process.
- Parameters:
method (object) – An object representing the optimization method, which should contain the attribute history.list_global_best_fit – a list of fitness values representing the best global fitness at each epoch.
plot_kwargs (dict, optional) – A dictionary of keyword arguments passed to the ax.plot function to customize the appearance of the line plot (e.g., color, linestyle). Default settings include: - linestyle: ‘-’ - color: ‘tab:blue’ - zorder: 1
ax (matplotlib.axes.Axes, optional) – A Matplotlib Axes object on which to plot the graph. If not provided, the current active Axes (plt.gca()) will be used.
- Returns:
ax – The Axes object with the plot.
- Return type:
matplotlib.axes.Axes
Example
>>> import matplotlib.pyplot as plt >>> # Assuming 'optimizer' is an object with the appropriate 'history' attribute >>> fig, ax = plt.subplots() >>> fitness_plot(optimizer, ax=ax) >>> plt.show()
pymcdm_reidentify.visuals.model_contourf
- pymcdm_reidentify.visuals.model_contourf.model_contourf(model, bounds, num=10, cmap='Greens', colorbar=False, esp=False, model_kwargs={}, contourf_kwargs={}, scatter_kwargs={}, text_kwargs={}, ax=None)
Plots a contour plot for the model’s preferences over a defined 𝑥-𝑦 grid.
- Parameters:
model (callable) – A function or model that takes a 2D grid of points as input and returns a 1D array of preferences for each point.
bounds (np.ndarray) – A 2x2 array defining the bounds of the x-y grid. The first row contains the min and max values for the x-axis, and the second row contains the min and max values for the y-axis.
num (int, optional) – Number of points to generate along each axis, determining the resolution of the grid. Default is 10.
cmap (str, optional) – The colormap used for the contour plot. Default is ‘Greens’.
colorbar (bool, optional) – Whether to add a colorbar to the plot. Default is False.
esp (tuple or bool, optional) – Coordinates of a special point to be highlighted on the plot. If False, no point is plotted. Default is False.
model_kwargs (dict, optional) – Additional keyword arguments to pass to the model. It must contain the keys ‘weights’ and ‘types’.
contourf_kwargs (dict, optional) – Additional keyword arguments to customize the ax.contourf function, which creates the filled contour plot.
scatter_kwargs (dict, optional) – Additional keyword arguments to customize the appearance of the special point, if esp is provided. Default settings include: - color: ‘tab:orange’ - marker: ‘*’ - s: 50 - zorder: 3
text_kwargs (dict, optional) – Additional keyword arguments to customize the annotation of the special point, if esp is provided. Default settings include: - color: ‘tab:orange’ - fontsize: 8 - zorder: 3 - text: ‘$ESP$’ - xy: coordinates of the annotation adjusted slightly from esp
ax (matplotlib.axes.Axes, optional) – A Matplotlib Axes object on which to plot the graph. If not provided, the current active Axes (plt.gca()) will be used.
- Returns:
ax (matplotlib.axes.Axes) – The Axes object with the contour plot.
cax (matplotlib.axes.Axes, optional) – The Axes object containing the colorbar if colorbar=True. Otherwise, only ax is returned.
- Raises:
KeyError – If the required keys ‘weights’ or ‘types’ are missing from model_kwargs.
Example
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.methods import SPOTIS >>> bounds = np.array([[0, 1], [0, 1]]) >>> model = SPOTIS(bounds) >>> model_kwargs = {'weights': np.array([0.5, 0.5]), 'types': np.array([1, -1])} >>> fig, ax = plt.subplots() >>> model_contourf(model, bounds, num=50, model_kwargs=model_kwargs, ax=ax) >>> plt.show()
pymcdm_reidentify.visuals.tfn_plot
- pymcdm_reidentify.visuals.tfn_plot.tfn_plot(tfn, a, m, b, crit=None, plot_kwargs={}, text_kwargs={}, ax=None)
Plots a triangular fuzzy number (TFN) defined by the parameters a, m, and b.
- Parameters:
tfn (callable) – A function that takes an input array x and returns the membership values (μ(x)) for a triangular fuzzy number.
a (float) – The lower bound (left endpoint) of the triangular fuzzy number.
m (float) – The peak (core) value where the membership function reaches 1.
b (float) – The upper bound (right endpoint) of the triangular fuzzy number.
crit (str or None, optional) – An optional label for the critical (core) value m to be displayed on the plot. If None, the label will be C^{core}. If a string is provided, the label will be C_{crit}^{core}. Default is None.
plot_kwargs (dict, optional) – Additional keyword arguments to customize the appearance of the plot line. Default settings include: - linestyle: ‘-’ - color: ‘black’
text_kwargs (dict, optional) – Additional keyword arguments to customize the appearance of the text annotations on the plot. Default settings include: - color: ‘black’
ax (matplotlib.axes.Axes, optional) – A Matplotlib Axes object on which to plot the graph. If not provided, the current active Axes (plt.gca()) will be used.
- Returns:
ax – The Axes object with the TFN plot.
- Return type:
matplotlib.axes.Axes
Example
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.methods.comet import _TFN >>> tfn = _TFN(1, 5, 9) >>> a, m, b = 1, 5, 9 >>> fig, ax = plt.subplots() >>> tfn_plot(tfn, a, m, b, crit='1', ax=ax) >>> plt.show()
pymcdm_reidentify.visuals.trfn_plot
- pymcdm_reidentify.visuals.trfn_plot.trfn_plot(trfn, a, b, c, d, crit=None, plot_kwargs={}, text_kwargs={}, ax=None)
Plots a trapezoidal fuzzy number (TrFN) defined by the parameters a, b, c, and d.
- Parameters:
trfn (callable) – A function that takes an input array x and returns the membership values (μ(x)) for a trapezoidal fuzzy number.
a (float) – The lower bound (left endpoint) where the membership function starts to rise.
b (float) – The lower core value where the membership function reaches 1.
c (float) – The upper core value where the membership function starts to drop from 1.
d (float) – The upper bound (right endpoint) where the membership function drops to 0.
crit (str or None, optional) – An optional label for the critical (core) value ((b+c)/2) to be displayed on the plot. If None, the label will be C^{core}. If a string is provided, the label will be C_{crit}^{core}. Default is None.
plot_kwargs (dict, optional) – Additional keyword arguments to customize the appearance of the plot line. Default settings include: - linestyle: ‘-’ - color: ‘black’
text_kwargs (dict, optional) – Additional keyword arguments to customize the appearance of the text annotations on the plot. Default settings include: - color: ‘black’
ax (matplotlib.axes.Axes, optional) – A Matplotlib Axes object on which to plot the graph. If not provided, the current active Axes (plt.gca()) will be used.
- Returns:
ax – The Axes object with the TrFN plot.
- Return type:
matplotlib.axes.Axes
Example
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm_reidentify.methods.strfn import _TRFN >>> trfn = _TRFN(1, 3, 7, 9) >>> a, b, c, d = 1, 3, 7, 9 >>> fig, ax = plt.subplots() >>> trfn_plot(trfn, a, b, c, d, crit='2', ax=ax) >>> plt.show()
pymcdm_reidentify.visuals.weights_diff_plot
- pymcdm_reidentify.visuals.weights_diff_plot.weights_diff_plot(reference, obtained, plot_kwargs={}, scatter_kwargs={}, text_kwargs={}, fill_kwargs={}, ax=None)
Plots the differences between reference weights and obtained weights, providing a visual comparison.
- Parameters:
reference (np.ndarray) – An array of reference weights used as the baseline for comparison.
obtained (np.ndarray) – An array of obtained weights that will be compared against the reference weights.
plot_kwargs (dict, optional) – Additional keyword arguments to customize the appearance of the dashed lines connecting reference and obtained weights. Default settings include: - linestyle: ‘–’ - color: ‘darkblue’ - zorder: 1
scatter_kwargs (dict, optional) – Additional keyword arguments to customize the appearance of the scatter points. Defaultoping settings include: - color: ‘black’ - s: 15 - zorder: 3
text_kwargs (dict, optional) – Additional keyword arguments to customize the appearance of the weight labels. Default settings include: - textcoords: “offset points” - xytext: (0, 10) - ha: ‘center’ - fontsize: 8
fill_kwargs (dict, optional) – Additional keyword arguments to customize the appearance of the filled area between the reference and obtained weights. Default settings include: - color: ‘tab:green’ - alpha: 0.5 - zorder: 0
ax (matplotlib.axes.Axes, optional) – A Matplotlib Axes object on which to plot the graph. If not provided, the current active Axes (plt.gca()) will be used.
- Returns:
ax – The Axes object with the weights difference plot.
- Return type:
matplotlib.axes.Axes
Example
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> reference = np.array([0.2, 0.3, 0.5]) >>> obtained = np.array([0.25, 0.35, 0.4]) >>> fig, ax = plt.subplots() >>> weights_diff_plot(reference, obtained, ax=ax) >>> plt.show()