Skip to main content

Case generator, optimizer, and summarizer for models.

Project description

CASEGEN MC

Probe a model to see the possibilities. Takes model and input dictionary and evaluates cases to explore the model space using grids, random sampling, and optimization techniques.

The input dictionary is defined by the user with mean value, uncertainty, uncertainty distribution, range, and bounds. Sparse definition okay and assumes 0 unc and range by default. Numerical and categorical parameters are supported. For categorical parameters, the range is defined as a list of options (subset of options), and the uncertainty distribution is defined as "choice" with unc defining the probability of each option. If no unc is defined, it is assumed to be uniform.

Includes matplotlib utility functions for standard plotting.

Analysis Type Description
estimate Runs the model with the mean values of the input parameters.
estimate_with_unc Runs the model with sampled input parameters based on their uncertainty distributions.
estimate_with_unc_combos Runs the model with combinations of extreme values of the input parameters.
sensitivity_analysis_unc Performs sensitivity analysis by varying each parameter individually based on its uncertainty distribution.
sensitivity_analysis_range Performs sensitivity analysis by varying each parameter individually over its entire range.
sensitivity_analysis_2D Performs 2D sensitivity analysis by varying two parameters simultaneously over a grid.
regular_grid Runs the model over a regular grid of input parameter values.
random_uniform_grid Runs the model over a grid of randomly sampled input

Install

pip install casegenmc

Use

import casegenmc as cgm 

# Define model
def model(x):
    out = {}
    out["y0"] = x["x0"]**2 + np.exp(x["x1"]) + x['x3']
    out["y1"] = x["x0"] + x["x1"] + x["x2"] + x["x3"]
    return out

# Create input stack. some parameters fixed - don't have uncertainty or range of options.
# mean, unc, range, bounds (minimum and maximum value), unc_type
input_stack = {
    "x0": {"mean": 1., "unc": .2, 'range': [0, 5], 'bounds': [0, 100], 'unc_type': 'normal'},
    "x1": {"mean": 1., "unc": .2, 'range': [0, 3], 'unc_type': 'lognormal'},
    "x2": 3., 
    "x3": 4, 
    "x4": {"mean": "a",  'range': ["a", "b"], "options": ["a", "b", "c"], "unc_type": "choice", },
    "x5": {"mean": "a", 'unc':[.2,.8], 'range': ["a", "b"], "options": ["a", "b", "c"], "unc_type": "choice", },
    }

# Pre-process input stack
input_stack = cgm.process_input_stack(input_stack)
print(input_stack)

# Evaluate the model with the input_stack.
cgm.run_analysis(model=model, input_stack=input_stack, analyses=["estimate"])

# Estimate with uncertainty.
cgm.run_analysis(model, input_stack, n_samples=1000, analyses=["estimate_with_unc"], par_output="y0")  

# Estimate with uncertainty combinations.
cgm.run_analysis(model, input_stack, n_samples=1000, analyses=["estimate_with_unc_combos"], par_output="y0")  

# 2d sensitivity analysis and analysis w.r.t 1 output parameter.
cgm.run_analysis(model, input_stack, n_samples=1000, analyses=["sensitivity_analysis_2D"],  par_grid_xy=["x0", "x1"], par_output="y0")

# sample a regular grid defined by range.
cgm.run_analysis(model, input_stack, n_samples=1000, analyses=["regular_grid"],  par_output="y0")

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

casegenmc-0.1.1.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

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

casegenmc-0.1.1-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file casegenmc-0.1.1.tar.gz.

File metadata

  • Download URL: casegenmc-0.1.1.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for casegenmc-0.1.1.tar.gz
Algorithm Hash digest
SHA256 573e8967231101ecc55f18b4fb6285900f8330392b89603185f0f9b0fa91b368
MD5 44a4ba55a07680754f12975264bac165
BLAKE2b-256 99678c84ae77ab9a18085d07d15adb2a61e44de9d22c964d3d2b5dd1870fbd17

See more details on using hashes here.

File details

Details for the file casegenmc-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: casegenmc-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 28.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for casegenmc-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 02f5474dae833853195d08d97d1b5ef82f67dcd0a371ce1629d666d522b68c91
MD5 f1837d3f0d68ad05b6340eb899396607
BLAKE2b-256 191bc16e075dd4512f00832c4aab516dcbee90265e639e2c5e2cf0e7d20ba31b

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