Viewers
B-FADE is provided with three viewers to display the input data as well as results:
bfade.viewers.BayesViewerdisplays:the contour of the log-prior;
the contour of the log-likelihood;
the contour of the log-posterior.
bfade.viewers.LaplacePosteriorViewerdisplays:the contour of the joint posterior;
the marginal posterior distributions.
bfade.viewers.PreProViewerarranges a common canvas to inspect:datasets;
curves;
prediction intervals;
predictive posterior distribution.
Each viewer has a config method to configure the options to export the pictures. Both BayesViewer and LaplacePosteriorViewer are subclassed from bfade.abstract.AbstractMAPViewer, so their retains similar interfaces.
Bayes Viewer
Initially, we instantiate a viewer:
v = BayesViewer("dk_th", aListEdgesX1, aIntN1, "ds_w", aListEdgesX2, aIntN2, name=aStringName)
where dk_th and ds_w selects the variables whereby the elements of the Bayes theorem are plotted. Next we the elements theorem in their logarithmic form via:
v.contour("log_prior", bay) v.contour("log_likelihood", bay, dat) v.contour("log_posterior", bay, dat)
Laplace Posterior Viewer
Similarly, we instantiate a viewer:
l = LaplacePosteriorViewer("dk_th", aInt1, aIntN1, "ds_w", aInt2, aIntN2, name=aStringName)
where aInt* is the coverage factor. The we run:
l.contour(bay) l.marginals("dk_th", bay) l.marginals("ds_w", bay)
to display the joint (contour) and the marginal posterior distributions. If one wishes to override the limits of the x- and y-axis, they would call config_contour.
Pre- and Post-Processing Viewer
Before displaying anything we need to instantiate a viewer:
pp = PreProViewer(aListEdgesX1, aListEdgesX2, aIntResCurves, scale="log")
Everything is set up, hence let us make a few examples. Bear in mind that the viewer progressively compose the figure based upon the inputs. Therefore, it allows many glyph to be overlaid. For convenience we assume that the dataset has been acquired and then split, so we have:
the training dataset in
dat_trthe test dataset in
dat_ts
Plot only training dataset:
pp.view(train_data = dat_tr)
Plot only test dataset:
pp.view(test_data = dat_ts)
Plot both datasets:
pp.view(train_data = dat_tr, test_data = dat_ts)
Plot an El Haddad curve
ehalong with the datasets:pp.view(train_data = dat_tr, test_data = dat_ts, curve = [bay.el_haddad_hat]) #list!
the argument is a list as the method allows for plotting multiple curves. Consider one instantiated via bfade.elhaddad.ElHaddadCurve, i.e. eh1. Hence:
pp.view(train_data = dat_tr, test_data = dat_ts, curve = [eh, eh1])
Plot the frequentist propagating crack region along with the training dataset:
pp.view(train_data = dat_tr, prediction_interval = mc, mc_samples=aInt, mc_distribution=aString, mc_bayes=bay, confidence=aInt)
where aString can take either joint or marginals to determine how the posterior must be sampled.
Plot the Bayesian and frequentist propagating crack region along with the training dataset and. An additional argument must be passed to indicate which statistical indicator has to be plot. For instance, the
meanand standard deviationstd:pp.view(train_data=dat_tr, prediction_interval = mc, mc_samples=aInt, mc_distribution=aString, mc_bayes=bay, confidence=aInt predictive_posterior = bay, post_samples, post_data=dataset, post_op=aFunction)
Importantly, post_op can be used to load numpy functions to process the predictions. For instance, we can compute the mean and the standard deviation by passing np.mean and np.std, respectively.