Skip to main content

Package implementing a scenario generation method based on copulas

Project description

Copula scenario generation method for stochastic programming

This library contains a Python implementantion of scenario generation method for scenario generation which is based on method introduced in article Michal Kaut (2014) and its extension for discrete data based on diploma thesis Komora (2024).

Usage

Simple usage is as follows.

from copula_scengen import ScenarioGenerator

generator = ScenarioGenerator()

scenario_generator = ScenarioGenerator(data=datafr)

scenarios_datafr = scenario_generator.generate(n_scenarios=10)

Note: ScenarioGenerator is a pydantic class. Therefore you need to specify 'data' parameter explicitly. The type of this parameter is 'pd.DataFrame'.

Expected data format.

It is expected that each column in input dataframe is a separate margin. There are no restrictions for continuous margins.

For discrete margins, there are following rules:

  1. Discrete margins consist of values from zero to some integer n, while each number between is present.
  2. Any categorical values, like 'No' and 'Yes', must be mapped by user to integer values (for example 0 and 1). After obtaining scenarios, it is possible to revert to original values.

Discrete margins are automatically inferred by the following function.

def is_discrete(arr: np.ndarray) -> bool:
    """
    Return True if all values in the numpy array are discrete (integers),
    False if any value is continuous (non-integer).
    NaN values are ignored.
    """
    if not np.issubdtype(arr.dtype, np.number):
        msg = "Array must contain numeric values only."
        raise TypeError(msg)

    # Ignore NaNs, compare integer-casted values to originals
    arr_no_nan = arr[~np.isnan(arr)]
    return np.allclose(arr_no_nan, np.round(arr_no_nan))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

copula_scengen-1.0.0.tar.gz (57.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

copula_scengen-1.0.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file copula_scengen-1.0.0.tar.gz.

File metadata

  • Download URL: copula_scengen-1.0.0.tar.gz
  • Upload date:
  • Size: 57.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for copula_scengen-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cbe470ff320743c3bd612e83d302657d643660425be5653d70f432fd0071df76
MD5 4993e5f481e01d85f28b374c0f2bc792
BLAKE2b-256 f8263add324c1417af5247f1656bdfa8bfcfa6e9658b518535f9e6340d598b54

See more details on using hashes here.

File details

Details for the file copula_scengen-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: copula_scengen-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for copula_scengen-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 144c0e0c14f106e7aba9e7dc9b7bbf11fbe7a84a7cba42b77c18d77513a37963
MD5 87123cb3fe540ff066142cb41c246d07
BLAKE2b-256 e0d7f09a70a056c3c481b560cd70fa05d12758005bcc380b963595c067518c79

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page