EnsembleNormalizer

class ompy.EnsembleNormalizer(*, extractor, normalizer_nld=None, normalizer_gsf=None, normalizer_simultan=None)[source]

Bases: object

Normalizes NLD nad γSF extracted from the ensemble

Usage:

The calling syntax can be either to normalize simultaneously:

EnsembleNormalizer(extractor=...,
                   normalizer_simultan=...)

, or to normalize sequentially:

EnsembleNormalizer(extractor=...,
                     normalizer_nld=...,
                     normalizer_gsf=...)

Note

If one should add a functionality that depends on random numbers withing the parallelized loop make sure to use the random generator exposed via the arguments (see Ensemble class for an example). If one uses np.random instead, this will be the same an exact copy for each process. Note that this is not an issue for multinest seach routine, which is anyhow seeded by default as implemented in ompy.

Variables
  • extractor (Extractor) – Extractor instance

  • normalizer_nld (NormalizerNLD) – NormalizerNLD instance

  • normalizer_gsf (NormalizerGSF) – NormalizerGSF instance

  • normalizer_simultan (NormalizerSimultan) – NormalizerSimultan instance

  • res (List[ResultsNormalized]) – List of the results

  • nprocesses (int) – Number of processes for multiprocessing. Defaults to number of available cpus-1 (with mimimum 1).

Parameters
  • extractor (Extractor) – Extractor instance

  • normalizer_nld (NormalizerNLD, optional) – NormalizerNLD instance

  • normalizer_gsf (NormalizerGSF, optional) – NormalizerGSF instance

  • normalizer_simultan (NormalizerSimultan, optional) – NormalizerSimultan instance

Methods Summary

normalize()

Normalize ensemble

normalizeSimultan(num, *, nld, gsf)

Wrapper for simultaneous normalization

normalizeStagewise(num, *, nld, gsf)

Wrapper for stagewise normalization

plot([ax, add_figlegend, n_plot, …])

Plots randomly drawn samples

plot_gsf_ext_stats(ax, *, xlow, xhigh, …)

plot_nld_ext_stats(ax, *, x, samples, …)

plot_selection(*, ax, samples, …[, …])

Plot some nld and gsf samples

plot_vector_stats(ax, samples, percentiles)

samples_from_res([random_state])

Draw random samples from results with transformed nld & gsf

stats_from_df(df, fmap, shape_out, percentiles)

step(i, nld, gsf)

Normalization step for each ensemble member

Methods Documentation

normalize()[source]

Normalize ensemble

Return type

None

normalizeSimultan(num, *, nld, gsf)[source]

Wrapper for simultaneous normalization

Parameters
  • num (int) – Loop number

  • nld (Vector) – NLD before normalization

  • gsf (Vector) – gsf before normalization

Returns

results (/parameters) of normalization

Return type

res (ResultsNormalized)

normalizeStagewise(num, *, nld, gsf)[source]

Wrapper for stagewise normalization

Parameters
  • num (int) – Loop number

  • nld (Vector) – NLD before normalization

  • gsf (Vector) – gsf before normalization

Returns

results (/parameters) of normalization

Return type

res (ResultsNormalized)

plot(ax=None, add_figlegend=True, n_plot=5, plot_model_stats=False, random_state=None, **kwargs)[source]

Plots randomly drawn samples

Parameters
  • ax (Tuple[Any, Any], optional) – The matplotlib axis to plot onto. Creates axis is not provided.

  • add_figlegend (bool, optional) – Defaults to True.

  • n_plot (bool, optional) – Number of (nld, gsf) samples to plot

  • plot_model_stats (bool, optional) – Plot stats also for models used in normalization

  • random_state (np.random.RandomState, optional) – random state, set by default such that a repeated use of the function gives the same results.

  • **kwargs – Description

Todo

  • Refactor code

  • Could not find out how to not plot dublicate legend entries, thus using a workaround

  • Checks if extrapolating where nld or gsf is np.nan

Return type

Tuple[Any, Any]

Returns

fig, ax

static plot_gsf_ext_stats(ax, *, xlow, xhigh, samples, normalizer_gsf, percentiles, color)[source]
static plot_nld_ext_stats(ax, *, x, samples, normalizer_nld, percentiles, color)[source]
plot_selection(*, ax, samples, normalizer_nld, normalizer_gsf, n_plot=5, random_state=None)[source]

Plot some nld and gsf samples

Parameters
  • ax (Tuple[Any, Any]) – The matplotlib axis to plot onto. Creates axis is not provided.

  • samples (pd.DataFrame) – Random samples from results with transformed nld & gsf

  • normalizer_nld (NormalizerNLD) – NormalizerNLD instance. Note: Input a copy as the instance attributes will be changed.

  • normalizer_gsf (NormalizerGSF) – NormalizerGSF instance. Note: Input a copy as the instance attributes will be changed.

  • n_plot (bool, optional) – Number of (nld, gsf) samples to plot

  • random_state (np.random.RandomState, optional) – random state, set by default such that a repeated use of the function gives the same results.

Return type

None

static plot_vector_stats(ax, samples, percentiles)[source]
samples_from_res(random_state=None)[source]

Draw random samples from results with transformed nld & gsf

Parameters

random_state (np.random.RandomState, optional) – random state, set by default such that a repeated use of the function gives the same results.

Return type

DataFrame

Returns

Samples

static stats_from_df(df, fmap, shape_out, percentiles)[source]
step(i, nld, gsf)[source]

Normalization step for each ensemble member

Parameters
  • i (int) – Loop number

  • nld (Vector) – NLD before normalization

  • gsf (Vector) – gsf before normalization

Returns

results (/parameters) of normalization

Return type

res (ResultsNormalized)

normalize()[source]

Normalize ensemble

Return type

None

normalizeSimultan(num, *, nld, gsf)[source]

Wrapper for simultaneous normalization

Parameters
  • num (int) – Loop number

  • nld (Vector) – NLD before normalization

  • gsf (Vector) – gsf before normalization

Returns

results (/parameters) of normalization

Return type

res (ResultsNormalized)

normalizeStagewise(num, *, nld, gsf)[source]

Wrapper for stagewise normalization

Parameters
  • num (int) – Loop number

  • nld (Vector) – NLD before normalization

  • gsf (Vector) – gsf before normalization

Returns

results (/parameters) of normalization

Return type

res (ResultsNormalized)

plot(ax=None, add_figlegend=True, n_plot=5, plot_model_stats=False, random_state=None, **kwargs)[source]

Plots randomly drawn samples

Parameters
  • ax (Tuple[Any, Any], optional) – The matplotlib axis to plot onto. Creates axis is not provided.

  • add_figlegend (bool, optional) – Defaults to True.

  • n_plot (bool, optional) – Number of (nld, gsf) samples to plot

  • plot_model_stats (bool, optional) – Plot stats also for models used in normalization

  • random_state (np.random.RandomState, optional) – random state, set by default such that a repeated use of the function gives the same results.

  • **kwargs – Description

Todo

  • Refactor code

  • Could not find out how to not plot dublicate legend entries, thus using a workaround

  • Checks if extrapolating where nld or gsf is np.nan

Return type

Tuple[Any, Any]

Returns

fig, ax

plot_selection(*, ax, samples, normalizer_nld, normalizer_gsf, n_plot=5, random_state=None)[source]

Plot some nld and gsf samples

Parameters
  • ax (Tuple[Any, Any]) – The matplotlib axis to plot onto. Creates axis is not provided.

  • samples (pd.DataFrame) – Random samples from results with transformed nld & gsf

  • normalizer_nld (NormalizerNLD) – NormalizerNLD instance. Note: Input a copy as the instance attributes will be changed.

  • normalizer_gsf (NormalizerGSF) – NormalizerGSF instance. Note: Input a copy as the instance attributes will be changed.

  • n_plot (bool, optional) – Number of (nld, gsf) samples to plot

  • random_state (np.random.RandomState, optional) – random state, set by default such that a repeated use of the function gives the same results.

Return type

None

samples_from_res(random_state=None)[source]

Draw random samples from results with transformed nld & gsf

Parameters

random_state (np.random.RandomState, optional) – random state, set by default such that a repeated use of the function gives the same results.

Return type

DataFrame

Returns

Samples

step(i, nld, gsf)[source]

Normalization step for each ensemble member

Parameters
  • i (int) – Loop number

  • nld (Vector) – NLD before normalization

  • gsf (Vector) – gsf before normalization

Returns

results (/parameters) of normalization

Return type

res (ResultsNormalized)