SALib.util package

Submodules

SALib.util.problem module

class SALib.util.problem.ProblemSpec(*args, **kwargs)[source]

Bases: dict

Dictionary-like object representing an SALib Problem specification.

property analysis
analyze(func, *args, **kwargs)[source]

Analyze sampled results using given function.

Parameters
  • func (function,) – Analysis method to use. The provided function must accept the problem specification as the first parameter, X values if needed, Y values, and return a numpy array.

  • *args (list,) – Additional arguments to be passed to func

  • nprocs (int,) – If specified, attempts to parallelize model evaluations

  • **kwargs (dict,) – Additional keyword arguments passed to func

Returns

self

Return type

ProblemSpec object

analyze_parallel(func, *args, nprocs=None, **kwargs)[source]

Analyze sampled results using the given function in parallel.

Parameters
  • func (function,) – Analysis method to use. The provided function must accept the problem specification as the first parameter, X values if needed, Y values, and return a numpy array.

  • *args (list,) – Additional arguments to be passed to func

  • nprocs (int,) – Number of processors to use. Capped to the number of outputs or available processors.

  • **kwargs (dict,) – Additional keyword arguments passed to func

Returns

self

Return type

ProblemSpec object

evaluate(func, *args, **kwargs)[source]

Evaluate a given model.

Parameters
  • func (function,) – Model, or function that wraps a model, to be run/evaluated. The provided function is required to accept a numpy array of inputs as its first parameter and must return a numpy array of results.

  • *args (list,) – Additional arguments to be passed to func

  • nprocs (int,) – If specified, attempts to parallelize model evaluations

  • **kwargs (dict,) – Additional keyword arguments passed to func

Returns

self

Return type

ProblemSpec object

evaluate_distributed(func, *args, nprocs=1, servers=None, verbose=False, **kwargs)[source]

Distribute model evaluation across a cluster.

Usage Conditions: * The provided function needs to accept a numpy array of inputs as

its first parameter

  • The provided function must return a numpy array of results

Parameters
  • func (function,) – Model, or function that wraps a model, to be run in parallel

  • nprocs (int,) – Number of processors to use for each node. Defaults to 1.

  • servers (list[str] or None,) – IP addresses or alias for each server/node to use.

  • verbose (bool,) – Display job execution statistics. Defaults to False.

  • *args (list,) – Additional arguments to be passed to func

  • **kwargs (dict,) – Additional keyword arguments passed to func

Returns

self

Return type

ProblemSpec object

evaluate_parallel(func, *args, nprocs=None, **kwargs)[source]

Evaluate model locally in parallel.

All detected processors will be used if nprocs is not specified.

Parameters
  • func (function,) – Model, or function that wraps a model, to be run in parallel. The provided function needs to accept a numpy array of inputs as its first parameter and must return a numpy array of results.

  • nprocs (int,) – Number of processors to use. Capped to the number of available processors.

  • *args (list,) – Additional arguments to be passed to func

  • **kwargs (dict,) – Additional keyword arguments passed to func

Returns

self

Return type

ProblemSpec object

plot()[source]

Plot results.

Returns

axes

Return type

matplotlib axes object

property results
sample(func, *args, **kwargs)[source]

Create sample using given function.

Parameters
  • func (function,) – Sampling method to use. The given function must accept the SALib problem specification as the first parameter and return a numpy array.

  • *args (list,) – Additional arguments to be passed to func

  • **kwargs (dict,) – Additional keyword arguments passed to func

Returns

self

Return type

ProblemSpec object

property samples
set_results(results: numpy.ndarray)[source]

Set previously available model results.

set_samples(samples: numpy.ndarray)[source]

Set previous samples used.

to_df()[source]

Convert results to Pandas DataFrame.

SALib.util.results module

class SALib.util.results.ResultDict(*args, **kwargs)[source]

Bases: dict

Dictionary holding analysis results.

Conversion methods (e.g. to Pandas DataFrames) to be attached as necessary by each implementing method

plot(ax=None)[source]

Create bar chart of results

to_df()[source]

Convert dict structure into Pandas DataFrame.

SALib.util.util_funcs module

SALib.util.util_funcs.avail_approaches(pkg)[source]

Create list of available modules.

Parameters

pkg (module) – module to inspect

Returns

method – A list of available submodules

Return type

list

SALib.util.util_funcs.read_param_file(filename, delimiter=None)[source]

Unpacks a parameter file into a dictionary

Reads a parameter file of format:

Param1,0,1,Group1,dist1
Param2,0,1,Group2,dist2
Param3,0,1,Group3,dist3

(Group and Dist columns are optional)

Returns a dictionary containing:
  • names - the names of the parameters

  • bounds - a list of lists of lower and upper bounds

  • num_vars - a scalar indicating the number of variables

    (the length of names)

  • groups - a list of group names (strings) for each variable

  • dists - a list of distributions for the problem,

    None if not specified or all uniform

Parameters
  • filename (str) – The path to the parameter file

  • delimiter (str, default=None) – The delimiter used in the file to distinguish between columns

Module contents

A set of utility functions

class SALib.util.ResultDict(*args, **kwargs)[source]

Bases: dict

Dictionary holding analysis results.

Conversion methods (e.g. to Pandas DataFrames) to be attached as necessary by each implementing method

plot(ax=None)[source]

Create bar chart of results

to_df()[source]

Convert dict structure into Pandas DataFrame.

SALib.util.avail_approaches(pkg)[source]

Create list of available modules.

Parameters

pkg (module) – module to inspect

Returns

method – A list of available submodules

Return type

list

SALib.util.read_param_file(filename, delimiter=None)[source]

Unpacks a parameter file into a dictionary

Reads a parameter file of format:

Param1,0,1,Group1,dist1
Param2,0,1,Group2,dist2
Param3,0,1,Group3,dist3

(Group and Dist columns are optional)

Returns a dictionary containing:
  • names - the names of the parameters

  • bounds - a list of lists of lower and upper bounds

  • num_vars - a scalar indicating the number of variables

    (the length of names)

  • groups - a list of group names (strings) for each variable

  • dists - a list of distributions for the problem,

    None if not specified or all uniform

Parameters
  • filename (str) – The path to the parameter file

  • delimiter (str, default=None) – The delimiter used in the file to distinguish between columns

SALib.util.scale_samples(params: numpy.ndarray, problem: Dict)[source]

Scale samples based on specified distribution (defaulting to uniform).

Adds an entry to the problem specification to indicate samples have been scaled to maintain backwards compatibility (sample_scaled).

Parameters
  • params (np.ndarray,) – numpy array of dimensions num_params-by-\(N\), where \(N\) is the number of samples

  • problem (dictionary,) – SALib problem specification

Returns

Return type

np.ndarray, scaled samples