Skip to main content

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

Metadata

Release files for copula-scengen 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for copula-scengen 1.0.0
File Size Uploaded
copula_scengen-1.0.0.tar.gz 57.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for copula-scengen 1.0.0
File Interpreter ABI Platform
copula_scengen-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 70.7 kB

Release files / copula_scengen-1.0.0.tar.gz

Download URL copula_scengen-1.0.0.tar.gz
Size 57.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cbe470ff320743c3bd612e83d302657d643660425be5653d70f432fd0071df76
BLAKE2b-256 checksum
How to use checksums
f8263add324c1417af5247f1656bdfa8bfcfa6e9658b518535f9e6340d598b54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / copula_scengen-1.0.0-py3-none-any.whl

Download URL copula_scengen-1.0.0-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
144c0e0c14f106e7aba9e7dc9b7bbf11fbe7a84a7cba42b77c18d77513a37963
BLAKE2b-256 checksum
How to use checksums
e0d7f09a70a056c3c481b560cd70fa05d12758005bcc380b963595c067518c79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page