bfade package
Submodules
bfade.abstract module
- class bfade.abstract.AbstractBayes(*pars: List[str], **args: Dict[str, Any])[source]
Bases:
ABCBayesian framework to perform Maximum a Posterior Estimation and predictions.
Contains:
core method to perform map
abstract predictor
methods to instantiate priors, log-likelihood, and log-posterior
Variational (Laplace) approximation of the posterior
computation of the predictive posterior.
- MAP(D, x0=[1, 1], solver: Dict[str, Any] = None) None[source]
Find the Maximum A Posteriori (MAP) estimate for the parameters.
\[\min_{\theta} -\log P[\theta | D]\]If MAP succeeds, the optimal parameters are stored in theta_hat. Whilst the Hessian Matrix is stored in ihess.
Parameters
- DDataset
Training dataset.
- x0list, optional
Initial guess for the parameters, by default [1, 1].
- solverstr, optional
The optimization solver to use, by default “Nelder-Mead”.
Raises
- Exception
Raised if MAP optimization does not succeed.
Returns
None
- laplace_posterior() None[source]
Load Laplace approximation.
\[P[\theta | D] \sim \mathcal{N}(\hat{\theta}, \mathbf{H}^{-1})\]and its marginal distributions, where \(\hat{\theta}\) is the optimal value from MAP, and \(\mathbf{H}^{-1}\) is the inverse Hessian matrix of \(-\log P[\theta | D]\)
Returns
None.
- load_log_likelihood(log_loss_fn: callable, **args: Dict[str, Any]) None[source]
Load a likelihood loss function.
Parameters
- log_loss_fncallable
Log-likelihood function.
- argsDict[str, Any]
Arguments of the log-likelihood function.
Returns
None
- load_prior(par: str, dist: callable, **args: Dict) None[source]
Load a prior distribution for a specified parameter.
Parameters
- parstr
The name of the parameter.
- distcallable
The distribution function or class.
- argsDict[str]
Additional arguments to be passed to the distribution function.
Returns
None
- log_likelihood(D, *P: Dict[str, Any]) float[source]
Calculate the log-likelihood.
\[\log P[D | \theta]\]Parameters
- DDataset
Input dataset.
- PDict[str, float]
Value of trainable parameters for the target curve.
Returns
- float
The log-posterior probability.
- log_posterior(D, *P: Dict[str, Any]) float[source]
Calculate the log-posterior.
\[\log P[\theta] = \log P[D | \theta] + \log P[\theta]\]Parameters
- DDataset
Input dataset.
- PDict[str, Any]
Trainable parameters.
Returns
- float
The log-posterior probability.
- log_prior(*P: Dict[str, Any]) float[source]
Calculate the log-prior probability hypothesising initially independent distributions.
\[\log P[\theta] = \sum \log P[\theta_i]\]Parameters
- PDict[str, Any]
Distribution and related arguments to be prescribed over the parameter.
Returns
- float
The log-prior probability.
- predict(D) ndarray[source]
Wraps predictor to predict via the trained model.
Parameters
- DDataset
Data for prediction.
Returns
- np.ndarray
Predictions.
Raises
- TypeError
If the optimal value is not available. Must run MAP.
- predictive_posterior(posterior_samples: int, D, post_op: callable = None, random_state: int = 0) ndarray[source]
Evaluate the predictive posterior using the specified number of samples.
Parameters
- posterior_samplesint
The number of posterior samples to generate.
- DDataset
The dataset supplied for predicting the corresponding output.
- post_opCallable[…, Any], optional
Posterior operation function. Default is None.
- random_state: int
Random state for numpy to sample the posterior. The default is 0.
Returns
- np.ndarray
Predictive posterior samples processed via post_op, if provided.
- class bfade.abstract.AbstractCurve(metrics: callable = <function identity>, **pars: ~typing.Dict[str, ~typing.Any])[source]
Bases:
ABCAbstract curve to instantiate curves to perform MAP over.
Contains:
representation
inspection
computation of its distance to a given dataset.
- config(save: bool = False, folder: str = './', fmt: str = 'png', dpi: int = 300) None[source]
Configure settings for saving plots.
Parameters
- savebool, optional
Flag indicating whether to save plots. The default is False.
- folderstr, optional
Folder path where plots will be saved. The default is “./”.
- fmtstr, optional
Format for saving plots. The default is “png”.
- dpiint, optional
Dots per inch for saving plots. The default is 300.
Returns
None
- inspect(x: ndarray, scale: str = 'linear', **data: Dict[str, Any]) None[source]
Plot the equation of the curve and optionally the provided dataset.
Parameters
- xnp.ndarray
Array of x-values for plotting the equation curve.
- scalestr, optional
The scale of the plot. The default is “linear”.
- dataDict[str, Any]
Additional data for scatter points. Expected keys: “X”, “y”.
Returns
None
- inspect_signed_distance(x: ndarray, x_opt: ndarray, y_opt: ndarray, dis: ndarray, X: ndarray = None, y: ndarray = None, scale: str = 'linear') None[source]
Visualize the signed distance of data points to a minimum-distance (optimal) point along the curve.
Parameters
- xnp.ndarray
Input values for the optimal point.
- x_optnp.ndarray
x-coordinate of the optimal point.
- y_optnp.ndarray
y-coordinate of the optimal point.
- disnp.ndarray
Signed distance values for each data point.
- Xnp.ndarray, optional
Input features of the synthetic dataset.
- ynp.ndarray, optional
Target values of the synthetic dataset.
- scalestr, optional
Scale for both x and y axes. Options are “linear” (default) or “log”.
Returns
- None
Displays a plot visualizing the signed distance of data points to the optimal point.
- signed_distance_to_dataset(D) Tuple[ndarray][source]
Minimises squared_distance to compute the minimum squared distance of each point of the dataset to the target curve.
\[\min_{\theta} d^2\]where \(\theta\) gather the parameters of the target curve.
- DDataset
Dataset instance containing attributes X and y as features and output, respectively.
- squared_distance(t: float, X: ndarray) float[source]
Calculate the squared distance between two points over the feature plane.
This is just an auxiliary function, which ought not to be used directly, rather it must be used in conjunction with signed_distance_to_dataset.
\[d^2 = (\mathcal{M}(x1) - \mathcal{M}(t))^2 + (\mathcal{M}(x2) - \mathcal{M}(f(t)))^2\]where \(\mathcal{M}\) is the metrics whereby the optimal distance will be computed.
Parameters
- tfloat
Dummy parameter. Abscissa along the equation.
- Xnp.ndarray
An array representing a point belonging to the feature space [X[0], X[1]].
Returns
- float
The squared distance between the metric values of points [t, equation(t)] and X.
- class bfade.abstract.AbstractMAPViewer(p1: str, b1: list, n1: int, p2: str, b2: list, n2: int, spacing: float = 'lin', **kwargs: Dict[str, float])[source]
Bases:
ABCAbstract viewer for inspecting MAP elements and Laplace’s Variational approximation of the posterior.
- config(save: bool = False, folder: str = './', fmt: str = 'png', dpi: int = 300) None[source]
Configure settings for saving plots.
Parameters
- savebool, optional
Flag indicating whether to save plots. The default is False.
- folderstr, optional
Folder path where plots will be saved. The default is “./”.
- fmtstr, optional
Format for saving plots. The default is “png”.
- dpiint, optional
Dots per inch for saving plots. The default is 300.
Returns
None
- config_contour(levels: int = 21, clevels: int = 11, cmap: str = 'viridis', xlim=None, ylim=None, translator: ~typing.Dict = <bfade.util.IdentityDictionary object>) None[source]
Configure contour plot settings.
Parameters
- levelsint, optional
The number of contour levels for the main plot. The default is 21.
- clevelsint, optional
The number of contour levels for the colorbar. The default is 11.
- cmapstr, optional
The colormap to use for the plot. The default is “viridis”.
- translator: Dict or callable
Mapper for labels.
Returns
None
bfade.dataset module
- class bfade.dataset.Dataset(**kwargs: Dict[str, Any])[source]
Bases:
objectGeneral dataset class for managing datasets.
- config(save: bool = False, folder: str = './', fmt: str = 'png', dpi: int = 300) None[source]
Configure settings for saving plots.
Parameters
- savebool, optional
Flag indicating whether to save plots. The default is False.
- folderstr, optional
Folder path where plots will be saved. The default is “./”.
- fmtstr, optional
Format for saving plots. The default is “png”.
- dpiint, optional
Dots per inch for saving plots. The default is 300.
Returns
None
- inspect(xlim=[1, 1000], ylim=[1, 1000], scale='linear', **kwargs: Dict[str, Any])[source]
Visualize the data and optionally a curve.
Parameters
- xlimlist, optional
Limits for the x-axis. Default is [1, 1000].
- ylimlist, optional
Limits for the y-axis. Default is [1, 1000].
- scalestr, optional
Scale for both x and y axes. Options are “linear” (default) or “log”.
**kwargs : Dict[str, Any]
- curve: AbstractCurve
Curve to inspect.
- x: np.ndarray
Abscissa for the curve
- partition(method: str = 'random', test_size: float = 0.2, random_state: int = 0)[source]
Partition the dataset into training and testing sets.
Parameters
- methodstr, optional
Method for partitioning. Options are “random” (default) or “user”.
- test_sizefloat, optional
The proportion of the dataset to include in the test split. Default is 0.2.
- random_stateint, optional
Random seed for reproducibility. Default is 0.
Returns
- Tuple[Dataset, Dataset]
Training and testing datasets.
Raises
- AttributeError
If no data is available in the dataset.
- Exception
If split method is incorrectly provided.
- populate(data, X_labels: List[str] = ['x1', 'x2'], y_label: str = 'y') Dict[str, ndarray][source]
Populate data into features and target labels.
Parameters
- datapd.DataFrame
Input data containing features and target labels.
- X_labelslist of str
Feature column labels. The default is [“x1”, “x2”].
- y_labelstr
Target column label. The default is “y”.
Returns
- dict
Dictionary containing features and target labels.
- class bfade.dataset.SyntheticDataset(**kwargs: Dict[str, Any])[source]
Bases:
Dataset- add_noise(x1_std: float, x2_std: float, random_state: int = 0) None[source]
Add Gaussian noise to the data points in the synthetic dataset.
Parameters
- x1_stdfloat
Standard deviation of the Gaussian noise to be added to the first feature (x1).
- x2_stdfloat
Standard deviation of the Gaussian noise to be added to the second feature (x2).
- random_state: int
Random state. The default is 0.
Returns
None
- clear_points(curve, tol: float = 0.01)[source]
Remove data points from the synthetic dataset based on the deviation from the underlying curve.
- curve: AbstractCurve
The curve used to separated the dataset and make classes accordingly.
Parameters
- tolfloat, optional
Tolerance level for determining the deviation. Points with a deviation less than tol will be removed. The default is 1e-2.
Returns
None
- make_classes(curve)[source]
Assign class labels to the synthetic dataset based on the underlying curve.
- curve: AbstractCurve
The curve used to separated the dataset and make classes accordingly.
Returns
None
- make_grid(x1_bounds: List[float], x2_bounds: List[float], n1: int, n2: int, spacing: str = 'lin') None[source]
Generate a grid of input points for the synthetic dataset.
Parameters
- x1_boundsList[float]
Bounds for the first feature (x1).
- x2_boundsList[float]
Bounds for the second feature (x2).
- n1int
Number of points along the first dimension (x1).
- n2int
Number of points along the second dimension (x2).
- scalestr, optional
The scale of the grid spacing, either “lin” for linear or “log” for logarithmic. Default is “lin”.
Returns
None
- make_tube(curve, x_bounds: List[float], n: int = 50, up: float = 0.1, down: float = -0.1, step: int = 4, spacing: str = 'lin') None[source]
Generate a ``tube’’ of points surrounding the given EH curve.
This method should be used in place of make_grid.
The dataset is inspected via view_grid
Parameters
- xlimList[float]
Edges of the interval along the x-axis.
- x_resint, optional
Number of points . The default is 50.
- upfloat, optional
Maximum upward translation of the EH curve. The default is 0.1. Note that in log-space (uniform) translations is achieved via multiplication.
- downfloat, optional
Minimum downward translation of the EH curve. The default is -0.1. Note that in log-space (uniform) translations is achieved via multiplication.
- stepint, optional
Number of translated curves. The default is 12. The method disregards the curve obtained via translation when the multiplication factor is 1. It gives the original curve, where points are classified as 0.5, so they do not bring about any information.
- spacing: str, optional
Spacing of the points.
Returns
None
bfade.elhaddad module
- class bfade.elhaddad.ElHaddadBayes(*pars, **args)[source]
Bases:
AbstractBayes- predictor(D, *P: Dict[str, float])[source]
Perform logistic prediction based on the given parameters and dataset.
\[P[\mathbf{x}_i | \theta] = {{1}\over{1+\exp [-\mathcal{H}(\mathbf{x}_i, \theta)]}}\]where \(\theta\) is the vector of trainable parameters
\[\theta = [\Delta K_{th,lc}\ \Delta\sigma_w]\]and \(\mathbf{x}_i \in D\) is a sample from the given dataset.
\(\mathcal{H}(\mathbf{x}_i, \theta)\) is the signed distance of the sample to the El Haddad curve of parameters \(\theta\). The position of the training points wrt the target curve are computed over the log-log plane.
Parameters
D : Dataset
- PDict[str, float]
Dictionary of the trainable parameters
Returns
- numpy.ndarray
An array containing the logistic predictions.
- class bfade.elhaddad.ElHaddadCurve(**pars)[source]
Bases:
AbstractCurve- equation(X: ndarray) ndarray[source]
Concrete representation of Evaluate El-Haddad curve over a given \(\sqrt{\text{area}}\) range.
\[\Delta\sigma = \Delta\sigma_w\sqrt{{\sqrt{\text{area}_0}} \over{\sqrt{\text{area}_0} + \sqrt{\text{area}}}}\]where
\[\sqrt{\text{area}_0} = {1 \over \pi} \bigg({{\Delta K_{th}} \over {Y \Delta \sigma_{w}}}\bigg)^2\]Parameters
- Xnp.ndarray
range of sqrt_area
Returns
- np.ndarray
Evaluated El Haddad curve along the given sqrt_area values.
- class bfade.elhaddad.ElHaddadDataset(**kwargs: Dict[str, Any])[source]
Bases:
Dataset- populate(data, X_labels: List[str] = ['sqrt_area', 'delta_sigma'], y_label: str = 'failed')[source]
Overload the method by providing keys pertinent to the El Haddad Curve.
- pre_process(**kwargs)[source]
Pre-process the dataset.
set ‘Y’
convert sqrt_area using the SIF equivalence
compute SIF
set attributes.
Parameters
- kwargsDict[str, Any]
Y_ref to specify the reference value for Y.
Raises
- MissingInputException
Raised if ‘Y’ is neither unique in the dataset nor provided as a keyword argument.
bfade.statistics module
- class bfade.statistics.Distribution(dist, **kwargs: Dict[str, Any])[source]
Bases:
objectInterface to scipy random variables.
This class instantiates distribution probabilities relying on scipy.stats.
- logpdf(x: ndarray) float[source]
Log-probability density function (PDF).
Parameters
- xfloat
The point where PDF is evaluated.
Returns
- float
The Log-PDF value at x.
- class bfade.statistics.MonteCarlo(curve, random_state: int = 0)[source]
Bases:
object- prediction_interval(x_edges: List[float], n: int, spacing: str, confidence: float = 95) Tuple[source]
Compute prediction intervals for a curve.
\[P\Big[\overline{\mathcal{E}^{(\sf M)}} - \mathcal{P}^{(\sf M)} \le \mathcal{E}^{({\sf M}+1)} \le \overline{\mathcal{E}^{(\sf M)}} + \mathcal{P}^{(\sf M)}\Big] = \beta\]where \(\beta\) is the confidence level. The semi ampliture of the prediction interval is:
\[\mathcal{P}^{(\sf M)} = T_{\beta} S^{(\sf M)} \sqrt{1 + 1/{\mathsf{M}}}\]Parameters
- x_edgeslist of float, optional
Edges of the x-axis over which the curve is plotted.
- nint, optional
Resolution of the curve (number of points over x-axis).
- spacingstr, optional
spacing for x and y axes.
- confidence: float
Confidence level of the prediction intervals. The default is 95.
Returns
- resultTuple
A tuple containing the following elements:
‘mean’: The expected curve data.
‘pred’: The semi-amplitude of the prediction interval.
‘x1’: abscissa along with the prediction interval is computed.
- sample(n_samples: int, distribution: str, bayes) ndarray[source]
Sample from the Bayesian model.
Parameters
- n_samplesint
Number of samples to generate.
- distributionstr
Distribution type to sample from. Options are “joint” or “marginals”.
- bayesAbstractBayes
Bayesian model object.
Returns
- np.ndarray
Generated samples.
Raises
- Exception
If an invalid distribution type is provided.
- class bfade.statistics.uniform(**kwargs)[source]
Bases:
objectUniform probability distribution.
This class is provided for convenience. Using this class is totally optional and one can alternatively utilise scipy’s either. Still scipy’s uniform returns 0 if the input point is outside the set range. This can cause issues to the likelihood for under-conservative choices of the lower and the upper bound of the range. Therefore, this custom uniform distribution is designed to return a given value everywhere. Obviously, this contrast the CDF but facilitates the computation of the likelihood.
The methods simulate part of the typical interface of scipy’s random vars.
bfade.util module
- exception bfade.util.MissingInputException(message: str)[source]
Bases:
ExceptionEnsure required parameters are passed in specific contexts.
- exception bfade.util.YieldException(message: str)[source]
Bases:
ExceptionEnsure the precedence of particular operations/stages over others.
- bfade.util.config_matplotlib(font_size: int = 12, font_family: str = 'sans-serif', use_latex: bool = False, interactive: str = False) None[source]
Set Matplotlib RC parameters for font size, font family, and LaTeX usage.
Parameters
- font_sizeint, optional
The font size of text. The default is 12.
- font_familystr, optional
The font family of text. The default is ‘sans-serif’.
- use_latexbool, optional
Whether to enable LaTeX text rendering in Matplotlib. The default is False.
- interactivebool, optional
Whether to enable plt.show() output. The default is False, i.e. display and keep window open.
Returns
None
- bfade.util.get_config_file(args: Namespace) Dict[source]
Get the configuration data from a YAML file.
Parameters
- argsargparse.Namespace
A namespace containing parsed command-line arguments.
Returns
- dict
A dictionary containing the configuration data loaded from the YAML file.
- bfade.util.grid_factory(x1_bounds: List[float], x2_bounds: List[float], n1: int, n2: int, spacing: str = 'lin') Tuple[ndarray][source]
Create a grid of points over a 2D space.
Parameters
- spacingstr
The type of spacing for the grid, either “lin” (linear) or “log” (logarithmic).
- x1List[float]
A list containing the lower and upper bounds for the X-axis.
- x2List[float]
A list containing the lower and upper bounds for the Y-axis.
- n1int
The number of points along the X-axis.
- n2int
The number of points along the Y-axis.
Returns
- Tuple
A tuple of two arrays: 1. X1: Flattened array of X-axis points for the entire grid. 2. X2: Flattened array of Y-axis points for the entire grid.
- bfade.util.identity(X: ndarray) ndarray[source]
Return the input array unchanged.
Parameters
- Xnumpy.ndarray
Input array.
Returns
- numpy.ndarray
Unchanged input array.
- bfade.util.inv_sif_range(delta_k: ndarray, delta_sigma: ndarray, y: ndarray) ndarray[source]
Compute the inverse of the SIF range, thus giving \(\sqrt{\text{area}}\).
\[\sqrt{\text{area}} = {1 \over \pi} \bigg({{\Delta K} \over {Y \Delta \sigma}}\bigg)^2\]Parameters
- delta_karray-like
stress intensity factor range.
- delta_sigmaarray-like
applied stress range.
- yarray-like
geometric factor of the defects.
Returns
- array-like
sqrt_area
- bfade.util.load(**kwargs: Dict[str, Any]) List[source]
Load data from binary files in a specified directory.
Parameters
- kwargsdict
- folderstr
The folder where the binary files are located.
- extensionstr, optional
If provided, filter by ‘extension’.
- filenamestr, optional
If provided, load files matching ‘filename’.
Returns
- List
A list with the loaded data objects loaded from the specified folder.
Raises
- MissingInputException
If the ‘folder’ keyword argument is missing.
- FileNotFoundError
If no matching files are found in the specified directory.
- bfade.util.logger_factory(name: str = 'root', level: str = 'DEBUG') Logger[source]
Instantiate a logger object.
Parameters
- namestr
name of the logger. The default is “root”.
- level: str
level of logging. The default is “DEBUG”.
Return
logger : Logger from logging module.
- bfade.util.logger_manager(level: str, fmt: str = None) None[source]
Manage loggers. Get the loggers to modify level and format.
Parameters
- levelstr
level of logging. The default is “DEBUG”.
- fmtstr
format of logging
Return
None.
- bfade.util.parse_arguments(config_path: str = './config.yaml') Namespace[source]
Parse command-line arguments to configure the execution using a YAML file.
Parameters
- config_pathstr
Path to yaml config file. The default is “./config.yaml”
Command Line Arguments
–config (str, optional): Path to the YAML config file. The default is “config.yaml”.
Returns
- argparse.Namespace
An object containing the parsed command-line arguments.
- bfade.util.printer(func: callable)[source]
A decorator for class methods that saves a figure if ‘save’ is True.
This decorator wraps a method that generates a figure and a title, and it saves the figure to the specified location if ‘save’ is True.
Parameters
- funccallable
The function to be decorated, which generates a figure and a title.
Returns
- callable
The decorated function.
- bfade.util.save(*args: Tuple, **kwargs: Dict[str, Any]) None[source]
Save a collection of data objects to binary files.
Parameters
- argsTuple
Any number of data objects to be saved as binary files.
- kwargsDict[str, Any]
- folderstr, optional
The directory where the binary files will be saved.
Raises
- MissingInputException
If the ‘folder’ keyword argument is missing.
- bfade.util.sif_equiv(sqrt_area_orig: ndarray, y_orig: ndarray, y_ref: float)[source]
Convert sqrt_area_orig into sqrt_area according to y_ref, given y_orig using the SIF-equivalence.
\[\sqrt{\text{area}}_{ref}=\sqrt{\text{area}_{orig}}\,\bigg({{Y_{orig}} \over {Y_{ref}}}\bigg)^2\]Parameters
- sqrt_area_origarray-like
original (measured) sqrt_area_data.
- y_origarray-like
original (indirectly retrieved from measurements) y.
- y_reffloat
user-defined value of y set as reference.
Returns
- array-like
equivalent sqrt_area computed by equalling delta_k.
- bfade.util.sif_range(delta_sigma: ndarray, y: ndarray, sqrt_area: ndarray) ndarray[source]
Definition of Stress Intensity Factor (SIF) range, \(\Delta K\).
\[\Delta K = \Delta\sigma\, Y \sqrt{\pi \sqrt{area}}\]Parameters
- delta_sigmaarray-like
applied stress range.
- yarray-like
geometric factor of the defects.
- sqrt_areaarray-like
Murakami’s characteristic length.
Returns
- array-like
stress intensity factor range.
- bfade.util.state_modifier(string: str, target: str, repl_text: str, add_text: str) str[source]
Modify a string by replacing or adding text based on a target substring.
Parameters
- stringstr
The input string to be modified.
- targetstr
The target substring to search in the input string.
- repl_textstr
The text that replaces the target substring when present.
- add_textstr
The text added to the input string when if the target substring is absent.
Returns
- str
The modified string after applying the specified modifications.
bfade.viewers module
- class bfade.viewers.BayesViewer(p1: str, b1: list, n1: int, p2: str, b2: list, n2: int, spacing: str = 'lin', **kwargs: Dict[str, Any])[source]
Bases:
AbstractMAPViewer- contour(element: str = 'log_prior', bayes=None, dataset=None)[source]
Create a contour plot for the specified element.
Parameters
- elementstr, optional
The element for which the contour plot is generated. The default is “log_prior”.
- bayesAbstractBayes
An instance of the Bayesian class. The default is None.
- datasetDataset
The training dataset. The default is None.
Returns
None
- class bfade.viewers.LaplacePosteriorViewer(p1: str, c1: float, n1: int, p2: str, c2: float, n2: int, bayes, **kwargs: Dict[str, Any])[source]
Bases:
AbstractMAPViewer
- class bfade.viewers.PreProViewer(x_edges: List[float] = [1, 1000], y_edges: List[float] = [100, 1000], n: int = 1000, scale: str = 'linear', **args: Dict[str, Any])[source]
Bases:
object- add_colourbar(ref, vmin: float, vmax: float)[source]
Add a colorbar to the El Haddad plot.
Parameters
- refmatplotlib.image.AxesImage
A reference to the image onto which the colorbar is drawn.
- vminfloat
Minimum value for color normalization.
- vmaxfloat
Maximum value for color normalization.
Returns
None
- add_scatter(x1: ndarray, x2: ndarray, marker: str, label: str, c: ndarray, vmin: float, vmax: float)[source]
Add scatter plot to the canvas.
Parameters
- x1np.ndarray
x-coordinates.
- x2np.ndarray
y-coordinates.
- markerstr
Marker style.
- labelstr
Label for the scatter plot.
- cnp.ndarray
Color values.
- vminfloat
Minimum value for color normalization.
- vmaxfloat
Maximum value for color normalization.
Returns
- matplotlib.collections.PathCollection
Scatter plot.
- static cbar_edges(data) Tuple[source]
Compute color bar edges.
Parameters
- dataDataset
Dataset containing color information.
Returns
- Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, float, float]
Indices of class 0, indices of class 1, color values for class 0, color values for class 1, minimum value for color normalization, maximum value for color normalization.
- config(save: bool = False, folder: str = './', fmt: str = 'png', dpi: int = 300) None[source]
Configure settings for saving plots.
Parameters
- savebool, optional
Flag indicating whether to save plots. The default is False.
- folderstr, optional
Folder path where plots will be saved. The default is “./”.
- fmtstr, optional
Format for saving plots. The default is “png”.
- dpiint, optional
Dots per inch for saving plots. The default is 300.
Returns
None
- config_canvas(xlabel: str = 'x1', ylabel: str = 'x2', cbarlabel: str = 'Class', class0: str = '0', class1: str = '1', legend_config: ~typing.Dict = None, translator: ~typing.Dict = <bfade.util.IdentityDictionary object>) None[source]
Configure the canvas for plotting.
Parameters
- xlabelstr, optional
Label for the x-axis. The default is “x1”.
- ylabelstr, optional
Label for the y-axis. The default is “x2”.
- cbarlabelstr, optional
Label for the color bar. The default is “Class”.
- class0str, optional
Label for class 0. The default is “0”.
- class1str, optional
Label for class 1. The default is “1”.
- legend_configDict, optional
Configuration for the legend. The default is None.
- translatorDict or callable
Translator for labels. The default is dummy_translator (from util).
Returns
None
- view(**kwargs: Dict[str, Any])[source]
Compose canvas.
Regarding the prediction interval and predictive posterior kwargs are used to probe the interface of the corresponding methods.
- kwargsDict[str, Any]
- train_dataDataset
Training data to display.
- test_dataDataset
Test data to display.
- curveList[AbstractCurve]
Curves to plot.
- prediction_intervalMonteCarlo
An instance of MonteCarlo.
- mc_bayesAbstractBayes
Bayesian infrastructure.
- mc_samplesint
Sample to draw from the posterior.
- mc_distributionstr
Posterior to be sampled: “joint” or “marginals”.
- confidencefloat
Confidence level for the prediction interval.
- predictive_posteriorAbstractBayes
Instance of AbstractBayes that contains the predictive_posterior to probe.
- post_samplesint
Samples to draw from the posterior.
- post_dataDataset
Provided input to forecast.
- post_opcallable
Function used to post-process.