mlmc.plot

Subpackage provides plot functions to display pdf, violinplot, …

Submodules

mlmc.plot.plots module

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_level_variances_error()[source]

Plot error of estimates of V_l. Scaled as V_l^2 / N_l

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_bs_variances(variances, y_label=None, log=True, y_lim=None)[source]

Plot BS estimate of error of variances of other related quantities. :param variances: Data, shape: (n_levels + 1, n_moments). :return:

plot_means_and_vars(moments_mean, moments_var, n_levels, exact_moments)[source]

Plot means with variance whiskers to given axes. :param moments_mean: array, moments mean :param moments_var: array, moments variance :param n_levels: array, number of levels :param exact_moments: array, moments from distribution :param ex_moments: array, moments from distribution samples :return:

plot_var_regression(i_moments=None)[source]

Plot total and level variances and their regression and errors of regression. :param i_moments: List of moment indices to plot. If it is an int M, the range(M) is used.

If None, self.moments.size is used.
class mlmc.plot.plots.BSplots(n_samples, bs_n_samples, n_moments, ref_level_var)[source]

Bases: object

plot_bootstrap_variance_compare()[source]

Plot fraction (MLMC var est) / (BS var set) for the total variance and level variances. :return:

plot_bs_level_variances_error()[source]

Plot error of estimates of V_l. Scaled as V_l^2 / N_l

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_bs_variances(variances, y_label=None, log=True, y_lim=None)[source]

Plot BS estimate of error of variances of other related quantities. :param variances: Data, shape: (n_levels + 1, n_moments). :return:

plot_means_and_vars(moments_mean, moments_var, n_levels, exact_moments=None)[source]

Plot means with variance whiskers to given axes. :param moments_mean: array, moments mean :param moments_var: array, moments variance :param n_levels: array, number of levels :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. :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.
set_moments_color_bar(range, label, ax=None)[source]

Create colorbar for a variable with given range and add it to given axes. :param range: single value as high bound or tuple (low bound, high bound) :param label: Label of the colorbar. :param ax: :return: Function to map values to colors. (normalize + cmap)

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: object

Class 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_distribution(distr_object, label=None)[source]

Add plot for distribution ‘distr_object’ with given label. :param distr_object: Instance of Distribution, we use methods: density, cdf and attribute domain :param label: string label for legend :return:

add_raw_samples(samples)[source]

Add histogram and ecdf for raw samples. :param samples:

adjust_domain(domain)[source]

Enlarge common domain by given bounds. :param value: [lower_bound, upper_bound]

reset()[source]
show(file='')[source]

Set colors according to the number of added plots. Set domain from all plots. Plot exact distribution. show, possibly save to file. :param file: None, or filename, default name is same as plot title.

class mlmc.plot.plots.Eigenvalues(log_y=True, title='Eigenvalues')[source]

Bases: object

Plot 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_linear_fit(values)[source]
add_values(values, errors=None, threshold=None, label='')[source]

Add set of eigenvalues into the plot. :param values: array (n,); eigen values in increasing or decreasing ordred, automatically flipped to decreasing. :param errors: array (n,); corresponding std errors :param threshold: horizontal line marking noise level or cut-off eigen value :return:

adjust_ylim(ylim)[source]

Enlarge common domain by given bounds. :param value: [lower_bound, upper_bound]

show(file='')[source]

Show the plot or save to file. :param file: filename base, None for show. :return:

class mlmc.plot.plots.Variance(moments=None)[source]

Bases: object

Plot level variances, i.e. Var X^l as a function of the mesh step. Selected moments are plotted.

add_level_variances(steps, variances)[source]

Add variances for single MLMC instance. :param steps, variances : as returned by Estimate.estimate_level_vars :param n_levels:

show(file='')[source]
class mlmc.plot.plots.VarianceBreakdown(moments=None)[source]

Bases: object

Plot 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:

show(file='')[source]

Show the plot or save to file. :param filename: filename base, None for show. :return:

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. :param range: single value as high bound or tuple (low bound, high bound) :param label: Label of the colorbar. :param ax: :return: Function to map values to colors. (normalize + cmap)

mlmc.plot.plots.make_monotone(X, Y)[source]
mlmc.plot.plots.moments(moments_fn, size=None, title='', file='')[source]

Plot moment functions. :param moments_fn: :param size: :param title: :param file: :return:

mlmc.plot.plots.moments_subset(n_moments, moments=None)[source]

Return subset of range(n_moments) for ploting. :param n_moments: Actual number of moments. :param moments: Type of subset:

None - all moments int - size of subset, formed by geometrical sequence
Returns:
mlmc.plot.plots.plot_convergence(quantiles, conv_val, title)[source]

Plot convergence with moment size for various quantiles. :param quantiles: iterable with quantiles :param conv_val: matrix of ConvResult, n_quantiles x n_moments :param title: plot title and filename used to save :return:

mlmc.plot.plots.plot_diff_var(ref_mc_diff_vars, n_moments, steps)[source]

Plot level diff vars

mlmc.plot.plots.plot_diff_var_subsample(level_variance_diff, n_levels)[source]

Plot diff between V* and V :param level_variance_diff: array of moments sqrt(V/V*) :param n_levels: array, number of levels :return: None

mlmc.plot.plots.plot_error(arr, ax, label)[source]
mlmc.plot.plots.plot_mlmc_conv(n_moments, vars_est, exact_mean, means_est, target_var)[source]
mlmc.plot.plots.plot_n_sample_est_distributions(title, cost, total_std, n_samples, rel_moments)[source]
mlmc.plot.plots.plot_pbs_flow_job_time()[source]
mlmc.plot.plots.plot_regression_diffs(all_diffs, n_moments)[source]

Plot level variance difference regression :param all_diffs: list, difference between Estimate._variance_regression result and Estimate.estimate_diff_var result :param n_moments: number of moments :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_vars(moments_mean, moments_var, n_levels, exact_moments=None, ex_moments=None)[source]

Plot means with variance whiskers :param moments_mean: array, moments mean :param moments_var: array, moments variance :param n_levels: array, number of levels :param exact_moments: array, moments from distribution :param ex_moments: array, moments from distribution samples :return: None

mlmc.plot.violinplot module

Module contents

Subpackage provides plot functions to display pdf, violinplot, …