Skip to main content
`Ctrl`+`K`

# SALib.util.problem module

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

  Bases: `dict`

  Dictionary-like object representing an SALib Problem specification.

  samples
    Type:

      np.array, of generated samples

  results
    Type:

      np.array, of evaluations (i.e., model outputs)

  analysis
    Type:

      np.array or dict, of sensitivity indices

  Attributes:
    analysis
    results
    samples

  Methods

  `analyze`(func, *args, **kwargs) | Analyze sampled results using given function.
  `analyze_parallel`(func, *args[, nprocs]) | Analyze sampled results using the given function in parallel.
  `clear`(/) | Remove all items from the dict.
  `copy`(/) | Return a shallow copy of the dict.
  `evaluate`(func, *args, **kwargs) | Evaluate a given model.
  `evaluate_distributed`(func, *args[, nprocs, ...]) | Distribute model evaluation across a cluster.
  `evaluate_parallel`(func, *args[, nprocs]) | Evaluate model locally in parallel.
  `fromkeys`(iterable[, value]) | Create a new dictionary with keys from iterable and values set to value.
  `get`(key[, default]) | Return the value for key if key is in the dictionary, else default.
  `heatmap`([metric, index, title, ax]) | Plot results as a heatmap.
  `items`(/) | Return a set-like object providing a view on the dict's items.
  `keys`(/) | Return a set-like object providing a view on the dict's keys.
  `plot`(**kwargs) | Plot results as a bar chart.
  `pop`(key[, default]) | If the key is not found, return the default if given; otherwise, raise a KeyError.
  `popitem`(/) | Remove and return a (key, value) pair as a 2-tuple.
  `sample`(func, *args, **kwargs) | Create sample using given function.
  `set_results`(results) | Set previously available model results.
  `set_samples`(samples) | Set previous samples used.
  `setdefault`(key[, default]) | Insert key with a value of default if key is not in the dictionary.
  `to_df`() | Convert results to Pandas DataFrame.
  `update`([E, ]**F) | If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
  `values`(/) | Return an object providing a view on the dict's values.

  property analysis
  analyze(func, *args, **kwargs)

    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)

    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)

    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)

    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)

    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

  heatmap(metric: str = None, index: str = None, title: str = None, ax=None)

    Plot results as a heatmap.

    Parameters:

      - metric (str or None, name of output to analyze (display all if None))

      - index (str or None, name of index to plot, dependent on what) – analysis was conducted (ST, S1, etc; displays all if None)

      - title (str, title of plot to use (defaults to the same as metric))

      - ax (axes object, matplotlib axes object to use for plot.) – Creates a new figure if not provided.

    Returns:

      ax

    Return type:

      matplotlib axes object

  plot(**kwargs)

    Plot results as a bar chart.

    Returns:

      axes

    Return type:

      matplotlib axes object

  property results
  sample(func, *args, **kwargs)

    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: ndarray)

    Set previously available model results.

  set_samples(samples: ndarray)

    Set previous samples used.

  to_df()

    Convert results to Pandas DataFrame.