mlmc.plot package
Subpackage provides plot functions to display pdf, violinplot, …
—
Submodules
—
mlmc.plot.plots
- mlmc.plot.plots.create_color_bar(range, label, ax=None)[source]
Create colorbar for a variable with given range and add it to given axes. :type range: :param range: single value as high bound or tuple (low bound, high bound) :type label: :param label: Label of the colorbar. :type ax: :param ax: :return: Function to map values to colors. (normalize + cmap)
- mlmc.plot.plots.moments_subset(n_moments, moments=None)[source]
Return subset of range(n_moments) for ploting. :type n_moments: :param n_moments: Actual number of moments. :type moments: :param moments: Type of subset:
None - all moments int - size of subset, formed by geometrical sequence
- Returns:
- class mlmc.plot.plots.Distribution(exact_distr=None, title='', quantity_name='X', legend_title='', log_density=False, cdf_plot=True, log_x=False, error_plot='l2')[source]
Bases:
objectClass for plotting distribution approximation: PDF and CDF (optional) Provides methods to: add more plots, add exact PDF, add ECDF/histogram from single level MC
- add_raw_samples(samples)[source]
Add histogram and ecdf for raw samples. :type samples: :param samples:
- add_distribution(distr_object, label=None)[source]
Add plot for distribution ‘distr_object’ with given label. :type distr_object: :param distr_object: Instance of Distribution, we use methods: density, cdf and attribute domain :type label: :param label: string label for legend :return:
- class mlmc.plot.plots.Eigenvalues(log_y=True, title='Eigenvalues')[source]
Bases:
objectPlot of eigenvalues (of the covariance matrix), several sets of eigenvalues can be added together with error bars and cut-tresholds. Colors are chosen automatically. Slight X shift is used to avoid point overlapping. For log Y scale only positive values are plotted.
- add_values(values, errors=None, threshold=None, label='')[source]
Add set of eigenvalues into the plot. :type values: :param values: array (n,); eigen values in increasing or decreasing ordred, automatically flipped to decreasing. :type errors: :param errors: array (n,); corresponding std errors :type threshold: :param threshold: horizontal line marking noise level or cut-off eigen value :return:
- mlmc.plot.plots.moments(moments_fn, size=None, title='', file='')[source]
Plot moment functions. :type moments_fn: :param moments_fn: :type size: :param size: :type title: :param title: :type file: :param file: :return:
- class mlmc.plot.plots.VarianceBreakdown(moments=None)[source]
Bases:
objectPlot total variance average over moments and variances of individual moments, Brake down to contribution of individual levels and optionally comparison to the reference level variances using error bars for the (signed) difference: ref_level_vars - level_vars
- add_variances(level_vars, n_samples, ref_level_vars=None)[source]
Add plot of variances for single MLMC instance.
- Parameters:
level_vars – Array (n_levels, n_moments) of level variances.
n_samples – Array (n_levels,) of numberf of samples on levels
ref_level_vars – reference level vars (e.g. from bootstrapping)
- Returns:
- class mlmc.plot.plots.Variance(moments=None)[source]
Bases:
objectPlot level variances, i.e. Var X^l as a function of the mesh step. Selected moments are plotted.
- class mlmc.plot.plots.BSplots(n_samples, bs_n_samples, n_moments, ref_level_var)[source]
Bases:
object- set_moments_color_bar(range, label, ax=None)[source]
Create colorbar for a variable with given range and add it to given axes. :type range: :param range: single value as high bound or tuple (low bound, high bound) :type label: :param label: Label of the colorbar. :type ax: :param ax: :return: Function to map values to colors. (normalize + cmap)
- plot_bootstrap_variance_compare()[source]
Plot fraction (MLMC var est) / (BS var set) for the total variance and level variances. :return:
- plot_bs_variances(variances, y_label=None, log=True, y_lim=None)[source]
Plot BS estimate of error of variances of other related quantities. :type variances: :param variances: Data, shape: (n_levels + 1, n_moments). :return:
- plot_bs_var_error_contributions()[source]
MSE of total variance and contribution of individual levels.
- plot_bs_var_log_var()[source]
Test that MSE of log V_l scales as variance of log chi^2_{N-1}, that is approx. 2 / (n_samples-1).
- plot_means_and_vars(moments_mean, moments_var, n_levels, exact_moments=None)[source]
Plot means with variance whiskers to given axes. :type moments_mean: :param moments_mean: array, moments mean :type moments_var: :param moments_var: array, moments variance :type n_levels: :param n_levels: array, number of levels :type exact_moments: :param exact_moments: array, moments from distribution :return:
- plot_var_regression(estimator, n_levels, moments_fn, i_moments=None)[source]
Plot total and level variances and their regression and errors of regression. :type i_moments: :param i_moments: List of moment indices to plot. If it is an int M, the range(M) is used.
If None, self.moments_fn.size is used.
- class mlmc.plot.plots.Aux[source]
Bases:
object- plot_bootstrap_variance_compare()[source]
Plot fraction (MLMC var est) / (BS var set) for the total variance and level variances. :param moments_fn: :return:
- plot_bs_variances(variances, y_label=None, log=True, y_lim=None)[source]
Plot BS estimate of error of variances of other related quantities. :type variances: :param variances: Data, shape: (n_levels + 1, n_moments). :return:
- plot_bs_var_error_contributions()[source]
MSE of total variance and contribution of individual levels.
- plot_bs_var_log_var()[source]
Test that MSE of log V_l scales as variance of log chi^2_{N-1}, that is approx. 2 / (n_samples-1).
- plot_means_and_vars(moments_mean, moments_var, n_levels, exact_moments)[source]
Plot means with variance whiskers to given axes. :type moments_mean: :param moments_mean: array, moments mean :type moments_var: :param moments_var: array, moments variance :type n_levels: :param n_levels: array, number of levels :type exact_moments: :param exact_moments: array, moments from distribution :param ex_moments: array, moments from distribution samples :return:
- mlmc.plot.plots.plot_diff_var_subsample(level_variance_diff, n_levels)[source]
Plot diff between V* and V :type level_variance_diff: :param level_variance_diff: array of moments sqrt(V/V*) :type n_levels: :param n_levels: array, number of levels :return: None
- mlmc.plot.plots.plot_vars(moments_mean, moments_var, n_levels, exact_moments=None, ex_moments=None)[source]
Plot means with variance whiskers :type moments_mean: :param moments_mean: array, moments mean :type moments_var: :param moments_var: array, moments variance :type n_levels: :param n_levels: array, number of levels :type exact_moments: :param exact_moments: array, moments from distribution :type ex_moments: :param ex_moments: array, moments from distribution samples :return: None
- mlmc.plot.plots.plot_convergence(quantiles, conv_val, title)[source]
Plot convergence with moment size for various quantiles. :type quantiles: :param quantiles: iterable with quantiles :type conv_val: :param conv_val: matrix of ConvResult, n_quantiles x n_moments :type title: :param title: plot title and filename used to save :return:
- mlmc.plot.plots.plot_var_regression(ref_level_vars, reg_vars, n_levels, n_moments)[source]
Plot levels variance regression
- mlmc.plot.plots.plot_regression_diffs(all_diffs, n_moments)[source]
Plot level variance difference regression :type all_diffs: :param all_diffs: list, difference between Estimate._variance_regression result and Estimate.estimate_diff_var result :type n_moments: :param n_moments: number of moments :return: