Giter VIP home page Giter VIP logo

Comments (2)

simetenn avatar simetenn commented on June 5, 2024

Yes, the toolbox is usable with multiple model outputs. However, it does unfortunately not have direct support for this, you have to use a small trick. Uncertainpy by default only performs an uncertainty quantification of the first model output returned. But you can return the additional model outputs in the info dictionary, and then define new features that extract each model output from the info dictionary, and then returns the additional model output.

Here is an example that shows how to do this:

import uncertainpy as un
import chaospy as cp

# Example model with multiple outputs
def example_model(parameter_1, parameter_2):
    # Perform all model calculations here

    time = ...

    model_output_1 = ...
    model_output_2 = ...
    model_output_3 = ...

    # We can store the additional model outputs in an info
    # dictionary
    info = {"model_output_2": model_output_2,
            "model_output_3": model_output_3}

    # Return time, model output and info dictionary
    # The first model output (model_output_1) is automatically used in the
    # uncertainty quantification
    return time, model_output_1, info

We can perform an uncertainty quantification of the other model outputs by creating a feature for each of the additional model outputs by extracting the output from the info dictionary and then return the output:

def model_output_2(time, model_output_1, info):
    return time, info["model_output_2"]

def model_output_3(time, model_output_1, info):
    return time, info["model_output_3"]

feature_list = [model_output_2, model_output_3]

# Define the parameter dictionary
parameters = {"parameter_1": cp.Uniform(),
              "parameter_2": cp.Uniform()}

# Set up the uncertainty quantification
UQ = un.UncertaintyQuantification(model=example_model,
                                  parameters=parameters,
                                  features=feature_list)

# Perform the uncertainty quantification using
# polynomial chaos with point collocation (by default)
data = UQ.quantify()

Alternatively, we can directly return all model outputs, but you are then unable to use the built.in features in Uncertainpy.

# Example model with multiple outputs
def example_model(parameter_1, parameter_2):
    # Perform all model calculations here

    time = ...

    model_output_1 = ...
    model_output_2 = ...
    model_output_3 = ...

    # Return time, model output and info dictionary
    # The first model output (model_output_1) is automatically used in the
    # uncertainty quantification
    return time, model_output_1,  model_output_2, model_output_3


# We can perform an uncertainty quantification of the other model
# outputs by creating a feature for each of the additional
# model outputs by extracting the output from the info dictionary and
# then return the output

def model_output_2(time, model_output_1, model_output_2, model_output_3):
    return time, model_output_2

def model_output_3(time, model_output_1, model_output_2, model_output_3):
    return time, model_output_3

from uncertainpy.

tzipperle avatar tzipperle commented on June 5, 2024

Thanks for the quick response. I will try the workflow in the next days.

from uncertainpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.