Example #1
0
    def test_quantify_propagate_uncertainty1(self):
        '''
        It tests the function quantify_propagate_uncertainty with rooney & biegler's model.
        '''
        from idaes.apps.uncertainty_propagation.examples.rooney_biegler import rooney_biegler_model, rooney_biegler_model_opt
        variable_name = ['asymptote', 'rate_constant']
        data = pd.DataFrame(data=[[1, 8.3], [2, 10.3], [3, 19.0], [4, 16.0],
                                  [5, 15.6], [7, 19.8]],
                            columns=['hour', 'y'])

        def SSE(model, data):
            expr = sum((data.y[i] - model.response_function[data.hour[i]])**2
                       for i in data.index)
            return expr

        results = quantify_propagate_uncertainty(rooney_biegler_model,
                                                 rooney_biegler_model_opt,
                                                 data, variable_name, SSE)

        assert results.obj == approx(4.331711213656886)
        np.testing.assert_array_almost_equal(
            results.theta, [19.142575284617866, 0.53109137696521])
        assert list(results.theta.keys()) == ['asymptote', 'rate_constant']
        np.testing.assert_array_almost_equal(results.gradient_f,
                                             [0.99506259, 0.945148])
        assert list(results.propagation_c) == []
        np.testing.assert_array_almost_equal(results.dsdp.toarray(),
                                             [[1., 0.], [0., 1.]])
        np.testing.assert_array_almost_equal(
            results.cov,
            np.array([[6.30579403, -0.4395341], [-0.4395341, 0.04193591]]))
        assert results.propagation_f == pytest.approx(5.45439337747349)
Example #2
0
    def test_quantify_propagate_uncertainty_NRTL(self):
        '''
        It tests the function quantify_propagate_uncertainty with IDAES NRTL model.
        '''
        from idaes.apps.uncertainty_propagation.examples.NRTL_model_scripts import NRTL_model, NRTL_model_opt
        variable_name = [
            "fs.properties.tau['benzene','toluene']",
            "fs.properties.tau['toluene','benzene']"
        ]
        current_path = os.path.dirname(os.path.realpath(__file__))
        data = pd.read_csv(os.path.join(current_path, 'BT_NRTL_dataset.csv'))

        def SSE(model, data):
            expr = (
                (float(data["vap_benzene"]) -
                 model.fs.flash.vap_outlet.mole_frac_comp[0, "benzene"])**2 +
                (float(data["liq_benzene"]) -
                 model.fs.flash.liq_outlet.mole_frac_comp[0, "benzene"])**2)
            return expr * 1E4

        results = quantify_propagate_uncertainty(NRTL_model, NRTL_model_opt,
                                                 data, variable_name, SSE)
        np.testing.assert_array_almost_equal(results.obj, 5.074968578304798)
        np.testing.assert_array_almost_equal(
            np.fromiter(results.theta.values(), dtype=float),
            [-0.8987624, 1.41048611])
        np.testing.assert_array_almost_equal(results.gradient_f[0],
                                             [-0.19649493])
        np.testing.assert_almost_equal(
            results.cov,
            np.array([[0.01194738, -0.02557055], [-0.02557055, 0.05490639]]))
        assert results.propagation_f == pytest.approx(0.0021199499778127204)
Example #3
0
    def test_quantify_propagate_uncertainty2(self):
        '''
        This is the same test as test_quantify_propagate_uncertainty1,
        but with the second argument of quantify_propagate_uncertainty as Pyomo Concrete Model.
        '''
        from idaes.apps.uncertainty_propagation.examples.rooney_biegler import rooney_biegler_model
        variable_name = ['asymptote', 'rate_constant']
        data = pd.DataFrame(data=[[1, 8.3], [2, 10.3], [3, 19.0], [4, 16.0],
                                  [5, 15.6], [7, 19.8]],
                            columns=['hour', 'y'])

        def SSE(model, data):
            expr = sum((data.y[i] - model.response_function[data.hour[i]])**2
                       for i in data.index)
            return expr

        model_uncertain = ConcreteModel()
        model_uncertain.asymptote = Var(initialize=15)
        model_uncertain.rate_constant = Var(initialize=0.5)
        model_uncertain.obj = Objective(
            expr=model_uncertain.asymptote *
            (1 - exp(-model_uncertain.rate_constant * 10)),
            sense=minimize)

        results = quantify_propagate_uncertainty(rooney_biegler_model,
                                                 model_uncertain, data,
                                                 variable_name, SSE)

        assert results.obj == approx(4.331711213656886)
        np.testing.assert_array_almost_equal(
            np.fromiter(results.theta.values(), dtype=float),
            [19.142575284617866, 0.53109137696521])
        assert list(results.theta.keys()) == ['asymptote', 'rate_constant']
        np.testing.assert_array_almost_equal(results.gradient_f,
                                             [0.99506259, 0.945148])
        assert list(results.propagation_c) == []
        np.testing.assert_array_almost_equal(results.dsdp.toarray(),
                                             [[1., 0.], [0., 1.]])
        np.testing.assert_array_almost_equal(
            results.cov,
            np.array([[6.30579403, -0.4395341], [-0.4395341, 0.04193591]]))
        assert results.propagation_f == pytest.approx(5.45439337747349)
Example #4
0
    def test_Exception1(self):
        '''
        It tests an ValueError when the tee is not bool for the function quantify_propagate_uncertainty with rooney & biegler's model.
        '''
        from idaes.apps.uncertainty_propagation.examples.rooney_biegler import rooney_biegler_model, rooney_biegler_model_opt
        variable_name = ['asymptote', 'rate_constant']
        data = pd.DataFrame(data=[[1, 8.3], [2, 10.3], [3, 19.0], [4, 16.0],
                                  [5, 15.6], [7, 19.8]],
                            columns=['hour', 'y'])

        def SSE(model, data):
            expr = sum((data.y[i] - model.response_function[data.hour[i]])**2
                       for i in data.index)
            return expr

        tee = 1
        with pytest.raises(TypeError):
            results = quantify_propagate_uncertainty(rooney_biegler_model,
                                                     rooney_biegler_model_opt,
                                                     data, variable_name, SSE,
                                                     tee)
Example #5
0
    def test_quantify_propagate_uncertainty_NRTL_exception(self):
        '''
        It tests an exception error when the ipopt fails for the function quantify_propagate_uncertainty with IDAES NRTL model.
        '''
        from idaes.apps.uncertainty_propagation.examples.NRTL_model_scripts import NRTL_model, NRTL_model_opt_infeasible
        variable_name = [
            "fs.properties.tau['benzene','toluene']",
            "fs.properties.tau['toluene','benzene']"
        ]
        current_path = os.path.dirname(os.path.realpath(__file__))
        data = pd.read_csv(os.path.join(current_path, 'BT_NRTL_dataset.csv'))

        def SSE(model, data):
            expr = (
                (float(data["vap_benzene"]) -
                 model.fs.flash.vap_outlet.mole_frac_comp[0, "benzene"])**2 +
                (float(data["liq_benzene"]) -
                 model.fs.flash.liq_outlet.mole_frac_comp[0, "benzene"])**2)
            return expr * 1E4

        with pytest.raises(Exception):
            results = quantify_propagate_uncertainty(
                NRTL_model, NRTL_model_opt_infeasible, data, variable_name,
                SSE)
Example #6
0
# Solutions of Sandia, LLC, Carnegie Mellon University, West Virginia
# University Research Corporation, et al. All rights reserved.
#
# Please see the files COPYRIGHT.txt and LICENSE.txt for full copyright and
# license information, respectively. Both files are also available online
# at the URL "https://github.com/IDAES/idaes-pse".
##############################################################################
import sys
import os
sys.path.append(os.path.abspath('..')) # current folder is ~/examples
from idaes.apps.uncertainty_propagation.uncertainties import quantify_propagate_uncertainty
import pandas as pd
from idaes.apps.uncertainty_propagation.examples.rooney_biegler import rooney_biegler_model,rooney_biegler_model_opt


variable_name = ['asymptote', 'rate_constant']
data = pd.DataFrame(data=[[1,8.3],
                          [2,10.3],
                          [3,19.0],
                          [4,16.0],
                          [5,15.6],
                          [7,19.8]],
                    columns=['hour', 'y'])

def SSE(model, data):
    expr = sum((data.y[i] - model.response_function[data.hour[i]])**2 for i in data.index)
    return expr


results =  quantify_propagate_uncertainty(rooney_biegler_model,rooney_biegler_model_opt, data, variable_name, SSE)
Example #7
0
# Please see the files COPYRIGHT.txt and LICENSE.txt for full copyright and
# license information, respectively. Both files are also available online
# at the URL "https://github.com/IDAES/idaes-pse".
##############################################################################
import sys
import os

sys.path.append(os.path.abspath('..'))  # current folder is ~/examples
from idaes.apps.uncertainty_propagation.uncertainties import quantify_propagate_uncertainty
import pandas as pd
from idaes.apps.uncertainty_propagation.examples.NRTL_model_scripts import NRTL_model, NRTL_model_opt

variable_name = [
    "fs.properties.tau['benzene', 'toluene']",
    "fs.properties.tau['toluene','benzene']"
]
current_path = os.path.dirname(os.path.realpath(__file__))
data = pd.read_csv(os.path.join(current_path, 'BT_NRTL_dataset.csv'))


def SSE(model, data):
    expr = ((float(data["vap_benzene"]) -
             model.fs.flash.vap_outlet.mole_frac_comp[0, "benzene"])**2 +
            (float(data["liq_benzene"]) -
             model.fs.flash.liq_outlet.mole_frac_comp[0, "benzene"])**2)
    return expr * 1E4


results = quantify_propagate_uncertainty(NRTL_model, NRTL_model_opt, data,
                                         variable_name, SSE)