Exemplo n.º 1
0
    def test_calc_PRESS_res(self):
        """
        Design and Analysis of Experiments 8th Ed (2013), (pg. 454, Ex. 10.1)
        Douglas C. Montgomery
        """
        x0 = symbols('x0')
        x1 = symbols('x1')

        var_list_symb = [x0, x1]
        var_basis_vect_symb = Matrix([[1, x0, x1]])

        var_basis_func = lambdify(
            (var_list_symb,), var_basis_vect_symb, modules='numpy'
        )

        # region: new samples
        var_list = []
        order = 1

        interval_low = 80
        interval_high = 100
        var_list.append(
            UniformVariable(interval_low, interval_high, order=order, number=0)
        )

        interval_low = 8
        interval_high = 13
        var_list.append(
            UniformVariable(interval_low, interval_high, order=order, number=1)
        )

        var_list[0].std_vals = np.array([
            80, 93, 100, 82, 90, 99, 81, 96, 94, 93, 97, 95, 100, 85, 86, 87
        ])

        var_list[1].std_vals = np.array([
            8, 9, 10, 12, 11, 8, 8, 10, 12, 11, 13, 11, 8, 12, 9, 12
        ])

        act_model_size = len(var_list[0].std_vals)

        new_resps = np.array([
            2256, 2340, 2426, 2293, 2330, 2368, 2250, 2409, 2364, 2379, 2440,
            2364, 2404, 2317, 2309, 2328
        ])

        new_basis = evaluate_points(
            var_basis_func, 0, act_model_size, var_list, 'std_vals'
        )

        true_press = 5207.7
        press = calc_PRESS_res(new_basis, new_resps)

        self.assertAlmostEqual(
            true_press, press, delta=1e-1,
            msg='statistics function calc_PRESS_res is not correct'
        )
Exemplo n.º 2
0
    def test_evaluate_points(self):
        """
        Testing evaluate_points to ensure that points are evaluated 
        correctly.
        """
        low = -1
        high = 1
        thresh = 1e-8
        var_list = [
            UniformVariable(low, high, number=0),
            UniformVariable(low, high, number=1),
            UniformVariable(low, high, number=2)
        ]

        var_list[0].stdvals = np.array([
            0.81772598, -0.06381505, 0.14684707, 0.1240739, 0.9744819,
            -0.27647688, -0.9233829, -0.67351042, -0.09180627, 0.95404397
        ])
        var_list[1].stdvals = np.array([
            -0.2753504, 0.5171086, -0.97586483, -0.30631548, 0.50056239,
            -0.02663459, 0.23837264, 0.23206214, 0.99304867, -0.83170756
        ])
        var_list[2].stdvals = np.array([
            0.18747112, -0.31858939, 0.13468345, -0.97464967, -0.73878923,
            -0.68208937, -0.72570261, 0.06601919, 0.34919762, -0.64923021
        ])

        x0 = symbols('x0')
        x1 = symbols('x1')
        x2 = symbols('x2')

        var_list_symb = np.array([x0, x1, x2])
        var_basis_vect_symb = Matrix([[x0 * x1 * x2 + 3],
                                      [x0**6 * x1**3 / x2**3]]).T

        func = lambdify((var_list_symb, ),
                        var_basis_vect_symb,
                        modules='numpy')

        eval_pnts_calc = evaluate_points(func, 0, 10, var_list, 'stdvals')

        eval_pnts_act = np.array([[2.95778878e+00, -9.47328905e-01],
                                  [3.01051323e+00, -2.88795246e-07],
                                  [2.98069947e+00, -3.81432782e-03],
                                  [3.03704230e+00, 1.13251462e-07],
                                  [2.63962675e+00, -2.66351803e-01],
                                  [2.99497720e+00, 2.65929871e-08],
                                  [3.15973384e+00, -2.19676768e-02],
                                  [2.98968145e+00, 4.05385508e+00],
                                  [2.96816432e+00, 1.37699332e-05],
                                  [3.51515481e+00, 1.58535356e+00]])

        self.assertTrue(
            (np.abs(eval_pnts_calc - eval_pnts_act) < thresh).all(),
            msg='statistics function evaluate_points is not correct')
Exemplo n.º 3
0
    def test_calc_mean_conf_int(self):
        """
        Applied Statistics and Probability for Engineers 4th Ed. (2007), 
        (pg. 13, 440, 467) Douglas C. Montgomery & George C. Runger

        Adapted to work for the format required by the ProbabilityBoxes method 
        calc_mean_conf_int.
        """
        signif = 0.05

        mean_act = 27.66
        uncert_act = 1

        responses = np.array([
            9.95, 24.45, 31.75, 35.0, 25.02, 16.86, 14.38, 9.6, 24.35, 27.5,
            17.08, 37.0, 41.95, 11.66, 21.65, 17.89, 69.0, 10.3, 34.93, 46.59,
            44.88, 54.12, 56.63, 22.13, 21.15, 27.66
        ])

        var_basis = np.array([[1, 2, 50], [1, 8, 110], [1, 11, 120],
                              [1, 10, 550], [1, 8, 295], [1, 4, 200],
                              [1, 2, 375], [1, 2, 52], [1, 9, 100],
                              [1, 8, 300], [1, 4, 412], [1, 11, 400],
                              [1, 12, 500], [1, 2, 360], [1, 4, 205],
                              [1, 4, 400], [1, 20, 600], [1, 1, 585],
                              [1, 10, 540], [1, 15, 250], [1, 15, 290],
                              [1, 16, 510], [1, 17, 590], [1, 6, 100],
                              [1, 5, 400], [1, 8, 275]])

        var_list = [
            UniformVariable(2, 18, order=1, number=0),
            UniformVariable(50, 600, order=1, number=1)
        ]
        pbox = ProbabilityBoxes(var_list)
        pbox.matrix_coeffs = solve_coeffs(var_basis, responses)
        pbox.var_basis_resamp = var_basis

        mean_calc, uncert_calc = pbox.calc_mean_conf_int(
            var_basis, responses, signif)

        self.assertTrue(
            np.isclose(mean_calc[-1], mean_act, rtol=0, atol=0.01),
            msg='ProbabilityBoxes calc_mean_conf_int is not correct.')

        self.assertTrue(
            np.isclose(uncert_calc[-1], uncert_act, rtol=0, atol=0.05),
            msg='ProbabilityBoxes calc_mean_conf_int is not correct.')
Exemplo n.º 4
0
    def test_generate_sample_set(self):
        """
        Testing generate_sample_set to ensure points are generated correctly.
        """
        cnt = 50

        p_val_min = 0.05
        ks_stat_max = 0.2

        lows = np.array([-1, 0, -2, 10])
        highs = np.array([1, 12, 2, 11])

        var_list = [
            UniformVariable(lows[0], highs[0], number=0),
            UniformVariable(lows[1], highs[1], number=1),
            UniformVariable(lows[2], highs[2], number=2),
            UniformVariable(lows[3], highs[3], number=3)
        ]

        var_cnt = len(var_list)

        ks_stat = np.zeros(var_cnt)
        p_val = np.zeros(var_cnt)

        set_crt = generate_sample_set(var_list, sample_count=cnt)

        # Verify that standardized points are generated for each variable- since
        # the 'genreate_samples' is tested for every variable, only one variable
        # type needs to be used to ensure this method is working.

        scale = 2
        args = (-1, scale)
        for i in range(var_cnt):

            ks_stat[i], p_val[i] = kstest(set_crt[i, :], 'uniform', args=args)

        self.assertTrue(
            (ks_stat < ks_stat_max).all(),
            msg='statistics function generate_sample_set is not correct')

        self.assertTrue(
            (p_val > p_val_min).all(),
            msg='statistics function generate_sample_set is not correct')
Exemplo n.º 5
0
    def test_calc_R_sq_adj(self):
        """
        Design and Analysis of Experiments 8th ed, pg 454, 464
        Douglas C. Montgomery
        """
        tol = 1e-5  # book rounds, so this is a higher value than default

        responses = np.array([
            2256, 2340, 2426, 2293, 2330, 2368, 2250, 2409, 2364, 2379, 2440,
            2364, 2404, 2317, 2309, 2328
        ])

        interval_low = -10
        interval_high = 10
        order = 2

        var_list = [
            UniformVariable(interval_low, interval_high, order=order, number=0),
            UniformVariable(interval_low, interval_high, order=order, number=1)
        ]

        var_basis = np.array([
            [1, 80, 8], [1, 93, 9], [1, 100, 10], [1, 82, 12],
            [1, 90, 11], [1, 99, 8], [1, 81, 8], [1, 96, 10],
            [1, 94, 12], [1, 93, 11], [1, 97, 13], [1, 95, 11],
            [1, 100, 8], [1, 85, 12], [1, 86, 9], [1, 87, 12]
        ])

        for i in range(1, 3):
            var_list[i - 1].std_vals = var_basis[:, i]
            var_list[i - 1].vals = var_basis[:, i]

        matrix_coeffs = solve_coeffs(var_basis, responses)

        R_sq_adj_calc = calc_R_sq_adj(var_basis, matrix_coeffs, responses)
        R_sq_adj_act = 0.915735

        self.assertTrue(
            np.isclose(R_sq_adj_calc, R_sq_adj_act, rtol=0, atol=tol),
            msg='statistics function calc_R_sq_adj is not correct'
        )
Exemplo n.º 6
0
    def test_calc_coeff_conf_int(self):
        """
        Design and Analysis of Experiments, 8th Ed. (pg 468)
        Douglas Montgomery
        """
        tol = 1e-3  # book rounds, so this is a higher value than default

        # Design and Analysis of Experiments 8th ed, pg 468
        responses = np.array([
            2256, 2340, 2426, 2293, 2330, 2368, 2250, 2409, 2364, 2379, 2440,
            2364, 2404, 2317, 2309, 2328
        ])

        order = 2
        signif = 0.05

        interval_low = -10
        interval_high = 10

        var_list = [
            UniformVariable(interval_low, interval_high, order=order, number=0),
            UniformVariable(interval_low, interval_high, order=order, number=1)
        ]

        var_basis = np.array([
            [1, 80, 8], [1, 93, 9], [1, 100, 10], [1, 82, 12],
            [1, 90, 11], [1, 99, 8], [1, 81, 8], [1, 96, 10],
            [1, 94, 12], [1, 93, 11], [1, 97, 13], [1, 95, 11],
            [1, 100, 8], [1, 85, 12], [1, 86, 9], [1, 87, 12]
        ])

        for i in range(1, 3):
            var_list[i - 1].std_vals = var_basis[:, i]
            var_list[i - 1].vals = var_basis[:, i]

        matrix_coeffs = solve_coeffs(var_basis, responses)

        coeff_uncert = calc_coeff_conf_int(
            var_basis, matrix_coeffs, responses, signif
        )

        calc_coeff = matrix_coeffs[1]
        act_coeff = 7.62129

        calc_low_bound = matrix_coeffs[1] - coeff_uncert[1]
        act_low_bound = 6.2855

        calc_high_bound = matrix_coeffs[1] + coeff_uncert[1]
        act_high_bound = 8.9570

        self.assertTrue(
            np.isclose(calc_coeff, act_coeff, rtol=0, atol=tol),
            msg='calc_coeff_conf_int is not correct.'
        )

        self.assertTrue(
            np.isclose(calc_low_bound, act_low_bound, rtol=0, atol=tol),
            msg='calc_coeff_conf_int is not correct.'
        )

        self.assertTrue(
            np.isclose(calc_high_bound, act_high_bound, rtol=0, atol=tol),
            msg='calc_coeff_conf_int is not correct.'
        )
Exemplo n.º 7
0
    def setUp(self):
        np.random.seed(33)

        order = 2

        mean = 1
        stdev = 0.5
        norm_var = NormalVariable(mean, stdev, number=0)

        interval_low = 1.75
        interval_high = 2.25
        unif_var = UniformVariable(interval_low,
                                   interval_high,
                                   order=order,
                                   number=1)

        lambd = 3
        exp_var = ExponentialVariable(lambd, order=order, number=2)

        alpha = 0.5
        beta = 2
        beta_var = BetaVariable(alpha, beta, order=order, number=3)

        alpha = 1.0
        theta = 0.5
        gamma_var = GammaVariable(alpha, theta, number=4)

        self.resp_mean = 9.8
        self.sig = 0.05
        self.conv_thresh_percent = 0.05

        x0 = symbols('x0')
        x1 = symbols('x1')
        x2 = symbols('x2')
        x3 = symbols('x3')
        x4 = symbols('x4')

        # region: symbolic basis
        self.var_basis_vect_symb = Matrix([[
            1, x0, x1, x2 - (1 / 3), x3 - 0.2, x4 - 1.0, x0**2 - 1.0, x0 * x1,
            x0 * (x2 - (1 / 3)), x0 * (x3 - 0.2), x0 * (x4 - 1),
            1.5 * x1**2 - 0.5, x1 * (x2 - (1 / 3)),
            x1 * (x3 - 0.2), x1 * (x4 - 1), x2**2 - (4 / 3) * x2 + (2 / 9),
            (1 * x2 - (1 / 3)) * (x3 - 0.2), (1 * x2 - (1 / 3)) * (x4 - 1),
            x3**2 - (2 / 3) * x3 + 0.0476190476190476,
            (1 * x3 - 0.2) * (x4 - 1), x4**2 - 4 * x4 + 2
        ]])
        # endregion: symbolic basis

        # region: matrix coefficients
        self.matrix_coeffs = np.array([
            9.8, 1.5, 0.75, 3, 4, 1.5, 0, 0.125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0.25
        ])
        # endregion: matrix coefficients

        # region: responses
        self.responses = np.array([
            12.16415154, 9.01613385, 7.20322875, 8.36029185, 8.540021,
            16.30878819, 9.28935313, 7.28973858, 5.31318168, 14.56672245,
            7.00861861, 9.54068883, 9.13214135, 8.02767443, 19.70304007,
            7.63480473, 6.70858894, 14.69559745, 10.99514746, 6.83015151,
            14.35737085, 7.95809045, 11.66095904, 10.73357651, 14.93505371,
            9.78495628, 10.64606339, 9.25057275, 6.02522479, 13.94699517,
            8.72677666, 11.38571172, 10.4209789, 10.56328017, 10.13697017,
            7.85520941, 9.3960816, 10.5062668, 11.4930689, 6.89224321,
            7.71822458, 7.5307172, 8.66196112, 13.17345374, 11.16095766,
            6.05241665, 11.90003052, 9.86202873, 9.09930809, 9.78234558
        ])
        # endregion: responses

        # region: var_basis_sys_eval
        self.var_basis_sys_eval = np.array([
            [
                1.00000000e+00, -1.69821780e+00, 9.67008120e-01,
                5.35784952e-01, 6.29187303e-01, 4.63649240e-01, 1.88394370e+00,
                -1.64219040e+00, -9.09879542e-01, -1.06849708e+00,
                -7.87377392e-01, 9.02657056e-01, 5.18108399e-01,
                6.08429231e-01, 4.48352580e-01, -1.81235564e-01,
                3.37109089e-01, 2.48416286e-01, 1.82379096e-01, 2.91722215e-01,
                -1.71232786e+00
            ],
            [
                1.00000000e+00, 2.64654700e-01, -5.54940320e-01,
                8.81321237e-02, -1.18436145e-01, -3.11138060e-01,
                -9.29957890e-01, -1.46867564e-01, 2.33245807e-02,
                -3.13446823e-02, -8.23441499e-02, -3.80618619e-02,
                -4.89080689e-02, 6.57249920e-02, 1.72663055e-01,
                -1.62098589e-01, -1.04380289e-02, -2.74212580e-02,
                -1.04193473e-04, 3.68499923e-02, -2.80916988e-01
            ],
            [
                1.00000000e+00, 9.04885000e-02, -9.27743680e-01,
                -2.61758959e-01, -7.37760500e-02, -8.96952220e-01,
                -9.91811831e-01, -8.39501340e-02, -2.36861755e-02,
                -6.67588410e-03, -8.11638610e-02, 7.91062504e-01,
                2.42845220e-01, 6.84452641e-02, 8.32141753e-01, 1.31912614e-01,
                1.93115420e-02, 2.34785279e-01, -2.05977668e-02,
                6.61735918e-02, 1.59842772e+00
            ],
            [
                1.00000000e+00, -1.27260262e+00, -3.13090800e-02,
                -1.82294361e-01, 3.97955199e-01, -3.35356640e-01,
                6.19517428e-01, 3.98440172e-02, 2.31988282e-01,
                -5.06438829e-01, 4.26775739e-01, -4.98529612e-01,
                5.70746874e-03, -1.24596112e-02, 1.04997079e-02,
                4.36496973e-02, -7.25449888e-02, 6.11336245e-02,
                6.53266830e-03, -1.33456918e-01, -2.16822644e-01
            ],
            [
                1.00000000e+00, -7.19942640e-01, 4.53624240e-01,
                -2.98857159e-01, 2.85083543e-01, -5.48411880e-01,
                -4.81682595e-01, -3.26583433e-01, 2.15160012e-01,
                -2.05243799e-01, 3.94825097e-01, -1.91337573e-01,
                -1.35568851e-01, 1.29320806e-01, -2.48772922e-01,
                1.77442596e-01, -8.51992577e-02, 1.63896816e-01,
                -4.04639374e-02, -1.56343202e-01, 3.97579350e-01
            ],
            [
                1.00000000e+00, -5.06701820e-01, 8.57896520e-01,
                -1.56670693e-01, 1.38422586e-01, 3.60217012e+00,
                -7.43253266e-01, -4.34697728e-01, 7.93853255e-02,
                -7.01389763e-02, -1.82522616e+00, 6.03979659e-01,
                -1.34407243e-01, 1.18752255e-01, 3.09028921e+00,
                1.78817239e-02, -2.16867625e-02, -5.64354490e-01,
                -6.34661630e-02, 4.98621703e-01, 4.77128933e+00
            ],
            [
                1.00000000e+00, 6.93335920e-01, -8.54372920e-01,
                -1.80414762e-01, -1.49891019e-01, 4.93979340e-01,
                -5.19285302e-01, -5.92367435e-01, -1.25088035e-01,
                -1.03924827e-01, 3.42493620e-01, 5.94929630e-01,
                1.54141487e-01, 1.28062827e-01, -4.22042571e-01,
                4.17148836e-02, 2.70425525e-02, -8.91211652e-02,
                1.67239700e-02, -7.40430664e-02, -1.74394309e+00
            ],
            [
                1.00000000e+00, -5.45266640e-01, -4.71937640e-01,
                -3.30505713e-01, 4.83296500e-02, -3.53641820e-01,
                -7.02684291e-01, 2.57331851e-01, 1.80213740e-01,
                -2.63525459e-02, 1.92829087e-01, -1.65912296e-01,
                1.55978086e-01, -2.28085810e-02, 1.66896886e-01,
                2.18460057e-01, -1.59732254e-02, 1.16880642e-01,
                -5.62664373e-02, -1.70913854e-02, -1.67653823e-01
            ],
            [
                1.00000000e+00, -1.15439366e+00, -5.68066960e-01,
                -2.92440300e-01, -1.54760782e-01, -8.42045240e-01,
                3.32624722e-01, 6.55772897e-01, 3.37591229e-01, 1.78654866e-01,
                9.72051686e-01, -1.59498934e-02, 1.66125672e-01,
                8.79144870e-02, 4.78338080e-01, 1.69370418e-01, 4.52582896e-02,
                2.46247963e-01, 1.95061558e-02, 1.30315580e-01, 1.39313067e+00
            ],
            [
                1.00000000e+00, 3.14226700e-01, 9.41083520e-01, 1.10277119e-01,
                2.92172781e-01, 1.63487722e+00, -9.01261581e-01,
                2.95713569e-01, 3.46520151e-02, 9.18084888e-02, 5.13722074e-01,
                8.28457287e-01, 1.03779979e-01, 2.74958989e-01, 1.53855601e+00,
                -1.72468147e-01, 3.22199724e-02, 1.80289549e-01,
                -3.82620934e-02, 4.77666624e-01, -1.59693092e+00
            ],
            [
                1.00000000e+00, -2.38433090e+00, 6.43114280e-01,
                8.79885637e-02, 1.95519339e-01, -3.28580380e-01,
                4.68503384e+00, -1.53339725e+00, -2.09793851e-01,
                -4.66182802e-01, 7.83444353e-01, 1.20393966e-01,
                5.65867018e-02, 1.25741279e-01, -2.11314735e-01,
                -1.62028166e-01, 1.72034658e-02, -2.89113157e-02,
                -5.96249642e-02, -6.42438187e-02, -2.34874174e-01
            ],
            [
                1.00000000e+00, 1.58421000e-02, 7.10066600e-01,
                -2.67395242e-01, -1.10118481e-01, 5.88922000e-01,
                -9.99749028e-01, 1.12489461e-02, -4.23610216e-03,
                -1.74450798e-03, 9.32976122e-03, 2.56291865e-01,
                -1.89868430e-01, -7.81914550e-02, 4.18173842e-01,
                1.38652599e-01, 2.94451577e-02, -1.57474941e-01,
                -4.22327783e-03, -6.48511958e-02, -1.83101488e+00
            ],
            [
                1.00000000e+00, -4.34847420e-01, 8.01878080e-01,
                5.65695537e-02, 3.47594250e-02, -7.86996480e-01,
                -8.10907721e-01, -3.48694614e-01, -2.45991245e-02,
                -1.51150463e-02, 3.42223389e-01, 4.64512683e-01,
                4.53618851e-02, 2.78728210e-02, -6.31075226e-01,
                -1.45624032e-01, 1.96632516e-03, -4.45200396e-02,
                -5.37752481e-02, -2.73555451e-02, 1.19335642e+00
            ],
            [
                1.00000000e+00, -1.85133760e-01, 2.35352640e-01,
                -1.32436687e-01, -1.93678144e-01, -2.60655660e-01,
                -9.65725491e-01, -4.35717192e-02, 2.45185019e-02,
                3.58563631e-02, 4.82561624e-02, -4.16913702e-01,
                -3.11693240e-02, -4.55826626e-02, -6.13459977e-02,
                -5.28051007e-03, 2.56500919e-02, 3.45203721e-02,
                4.34444431e-02, 5.04833046e-02, -4.10747307e-01
            ],
            [
                1.00000000e+00, 1.06583192e+00, 9.80257200e-01,
                -1.12700383e-01, -9.28667440e-02, 4.13125394e+00,
                1.35997682e-01, 1.04478941e+00, -1.20119666e-01,
                -9.89803401e-02, 4.40322232e+00, 9.41356267e-01,
                -1.10475362e-01, -9.10332944e-02, 4.04969142e+00,
                -2.32761458e-02, 1.04661176e-02, -4.65593903e-01,
                -1.23255885e-02, -3.83656102e-01, 7.80475124e+00
            ],
            [
                1.00000000e+00, -2.56422140e-01, 2.89414200e-01,
                -1.25480769e-01, -1.87106063e-01, -7.56584760e-01,
                -9.34247686e-01, -7.42122085e-02, 3.21760474e-02,
                4.79781370e-02, 1.94005083e-01, -3.74359131e-01,
                -3.63159165e-02, -5.41511514e-02, -2.18966373e-01,
                -1.17118414e-02, 2.34782127e-02, 9.49368378e-02,
                3.91893430e-02, 1.41561595e-01, 1.08559002e+00
            ],
            [
                1.00000000e+00, -5.93495580e-01, -1.99344200e-01,
                -2.79644517e-01, -1.25344887e-01, -5.52429860e-01,
                -6.47762997e-01, 1.18309902e-01, 1.65967785e-01,
                7.43916366e-02, 3.27864680e-01, -4.40392835e-01,
                5.57455125e-02, 2.49867763e-02, 1.10123688e-01, 1.53519623e-01,
                3.50520105e-02, 1.54483981e-01, 3.42235839e-03, 6.92442586e-02,
                4.10038470e-01
            ],
            [
                1.00000000e+00, 1.58175620e+00, 5.13432760e-01,
                -7.42201093e-02, 5.25738158e-01, 3.71565400e-01,
                1.50195268e+00, 8.12125451e-01, -1.17398118e-01,
                8.31589591e-01, 5.87725875e-01, -1.04580201e-01,
                -3.81070356e-02, 2.69931193e-01, 1.90773849e-01,
                -5.61224136e-02, -3.90203436e-02, -2.75776246e-02,
                9.04894829e-02, 1.95346109e-01, -1.60506995e+00
            ],
            [
                1.00000000e+00, 1.14220158e+00, -4.44342840e-01,
                -3.32295743e-01, -1.95261110e-01, 1.40967742e+00,
                3.04624449e-01, -5.07529094e-01, -3.79548722e-01,
                -2.23027548e-01, 1.61013578e+00, -2.03839161e-01,
                1.47653234e-01, 8.67628760e-02, -6.26380068e-01,
                2.20839845e-01, 6.48844355e-02, -4.68429805e-01,
                4.44822445e-02, -2.75255177e-01, -1.83216441e+00
            ],
            [
                1.00000000e+00, -8.32056640e-01, -2.05315920e-01,
                -2.32616395e-01, -2.99811380e-02, -6.16319660e-01,
                -3.07681748e-01, 1.70834475e-01, 1.93550016e-01,
                2.49460049e-02, 5.12812865e-01, -4.36768059e-01,
                4.77598492e-02, 6.15560493e-03, 1.26540238e-01, 9.80768732e-02,
                6.97410425e-03, 1.43366058e-01, -3.68204469e-02,
                1.84779648e-02, 6.12489243e-01
            ],
            [
                1.00000000e+00, -1.43800290e+00, -5.81506800e-01,
                -1.02115026e-01, -2.11784300e-03, 3.86883146e+00,
                1.06785234e+00, 8.36208465e-01, 1.46841704e-01, 3.04546438e-03,
                -5.56339086e+00, 7.22523767e-03, 5.93805822e-02,
                1.23154011e-03, -2.24975180e+00, -3.26069483e-02,
                2.16263594e-04, -3.95065826e-01, -4.51450423e-02,
                -8.19357763e-03, 6.23019395e+00
            ],
            [
                1.00000000e+00, 1.09658540e-01, -3.04797160e-01,
                -3.23520499e-01, -1.90071115e-01, 1.97475260e-01,
                -9.87975005e-01, -3.34236116e-02, -3.54767855e-02,
                -2.08429210e-02, 2.16548487e-02, -3.60648037e-01,
                9.86081292e-02, 5.79331361e-02, -6.01898984e-02,
                2.09234734e-01, 6.14919020e-02, -6.38872946e-02,
                4.10983738e-02, -3.75343429e-02, -1.35595404e+00
            ],
            [
                1.00000000e+00, 8.19371940e-01, 6.98318920e-01,
                -2.28715814e-01, -5.89674350e-02, 9.72309700e-01,
                -3.28629624e-01, 5.72182928e-01, -1.87403320e-01,
                -4.83162616e-02, 7.96683285e-01, 2.31473971e-01,
                -1.59716580e-01, -4.11780755e-02, 6.78982260e-01,
                9.36770222e-02, 1.34867849e-02, -2.22382605e-01,
                -2.65124780e-02, -5.73346090e-02, -1.99923325e+00
            ],
            [
                1.00000000e+00, 1.20206106e+00, -7.42100480e-01,
                -3.10566127e-01, 1.08622785e-01, 4.86583020e-01,
                4.44950792e-01, -8.92050090e-01, -3.73319448e-01,
                1.30571220e-01, 5.84902501e-01, 3.26069684e-01, 2.30471272e-01,
                -8.06090209e-02, -3.61093493e-01, 1.92384293e-01,
                -3.37345577e-02, -1.51116204e-01, -6.28814523e-02,
                5.28540028e-02, -1.73640300e+00
            ],
            [
                1.00000000e+00, 1.52916818e+00, 5.47669640e-01, 1.28060969e+00,
                -1.82393732e-01, -6.38221460e-01, 1.33835532e+00,
                8.37478987e-01, 1.95826758e+00, -2.78910692e-01,
                -9.75947948e-01, -5.00869481e-02, 7.01351046e-01,
                -9.98915097e-02, -3.49534517e-01, 6.75110267e-01,
                -2.33575180e-01, -8.17312584e-01, 3.61915164e-02,
                1.16407594e-01, 6.83769552e-01
            ],
            [
                1.00000000e+00, 3.78635860e-01, -6.06849520e-01,
                -1.60451189e-01, -1.97465589e-01, 1.11260496e+00,
                -8.56634886e-01, -2.29774990e-01, -6.07525741e-02,
                -7.47675532e-02, 4.21272136e-01, 5.23995099e-02,
                9.73697272e-02, 1.19831898e-01, -6.75183786e-01,
                2.16009326e-02, 3.16835887e-02, -1.78518789e-01,
                4.59358638e-02, -2.19701194e-01, -1.98732012e+00
            ],
            [
                1.00000000e+00, 1.35367938e+00, -9.72782600e-01,
                2.52141893e-01, -3.16609400e-02, -8.51167860e-01,
                8.32447864e-01, -1.31683575e+00, 3.41319281e-01,
                -4.28587616e-02, -1.15220838e+00, 9.19458980e-01,
                -2.45279246e-01, 3.07992115e-02, 8.28001284e-01,
                -2.15630172e-01, -7.98304934e-03, -2.14615075e-01,
                -3.62689533e-02, 2.69487745e-02, 1.42682245e+00
            ],
            [
                1.00000000e+00, -4.72663200e-02, -2.01521560e-01,
                -2.76113388e-01, 3.63035836e-01, -9.08909580e-01,
                -9.97765895e-01, 9.52518254e-03, 1.30508638e-02,
                -1.71593680e-02, 4.29608111e-02, -4.39083591e-01,
                5.56428008e-02, -7.31595480e-02, 1.83164876e-01,
                1.49203084e-01, -1.00239055e-01, 2.50962104e-01,
                -1.07288238e-02, -3.29966749e-01, 1.64393578e+00
            ],
            [
                1.00000000e+00, -1.80170454e+00, -6.38147600e-01,
                1.68757702e-01, -1.99229209e-01, -2.07441120e-01,
                2.24613925e+00, 1.14975343e+00, -3.04051517e-01,
                3.58952171e-01, 3.73747608e-01, 1.10848539e-01,
                -1.07692322e-01, 1.27137642e-01, 1.32378053e-01,
                -1.95137084e-01, -3.36214635e-02, -3.50072866e-02,
                4.71057813e-02, 4.13283303e-02, -5.42085942e-01
            ],
            [
                1.00000000e+00, 2.43353480e-01, -2.06763960e-01,
                8.01916767e-01, 4.76278623e-01, -1.21210260e-01,
                -9.40779084e-01, -5.03167292e-02, 1.95149236e-01,
                1.15904060e-01, -2.94969386e-02, -4.35872997e-01,
                -1.65807486e-01, -9.84772542e-02, 2.50619134e-02,
                -2.65178823e-03, 3.81935813e-01, -9.72005398e-02,
                5.41194082e-02, -5.77298557e-02, -7.42887553e-01
            ],
            [
                1.00000000e+00, -8.09955400e-02, -2.68522000e-02,
                -1.45052550e-01, 9.41239390e-02, -7.72320640e-01,
                -9.93439723e-01, 2.17490844e-03, 1.17486096e-02,
                -7.62361927e-03, 6.25545273e-02, -4.98918439e-01,
                3.89498009e-03, -2.52743483e-03, 2.07385083e-02,
                6.63083147e-03, -1.36529174e-02, 1.12027079e-01,
                -6.19546869e-02, -7.26938608e-02, 1.14112045e+00
            ],
            [
                1.00000000e+00, -8.54345480e-01, -8.49278720e-01,
                -2.94781873e-01, -9.70384490e-02, 2.87277794e+00,
                -2.70093801e-01, 7.25577436e-01, 2.51845561e-01,
                8.29043603e-02, -2.45434485e+00, 5.81911516e-01,
                2.50351972e-01, 8.24126898e-02, -2.43978917e+00,
                1.72306490e-01, 2.86051757e-02, -8.46842861e-01,
                -1.04209054e-02, -2.78769916e-01, 1.50729721e+00
            ],
            [
                1.00000000e+00, 2.18048206e+00, -3.74158920e-01,
                -2.88714621e-01, -1.69354756e-01, -5.48905600e-01,
                3.75450201e+00, -8.15846813e-01, -6.29537051e-01,
                -3.69275007e-01, -1.19687881e+00, -2.90007654e-01,
                1.08025151e-01, 6.33655925e-02, 2.05377926e-01, 1.64721435e-01,
                4.88951941e-02, 1.58477072e-01, 2.81280158e-02, 9.29597738e-02,
                3.99108558e-01
            ],
            [
                1.00000000e+00, 5.24642240e-01, 6.82173040e-01,
                -2.25650119e-01, 2.13467481e-01, -5.95677540e-01,
                -7.24750520e-01, 3.57896792e-01, -1.18385584e-01,
                1.11994057e-01, -3.12517599e-01, 1.98040085e-01,
                -1.53932428e-01, 1.45621760e-01, -4.06355158e-01,
                9.02402781e-02, -4.81689626e-02, 1.34414708e-01,
                -5.70705819e-02, -1.27157784e-01, 5.46186812e-01
            ],
            [
                1.00000000e+00, 1.75837654e+00, -1.99996320e-01,
                -1.75045343e-01, -1.65527328e-01, -8.50032100e-01,
                2.09188806e+00, -3.51668837e-01, -3.07795625e-01,
                -2.91059370e-01, -1.49467650e+00, -4.40002208e-01,
                3.50084245e-02, 3.31048564e-02, 1.70003292e-01, 3.62266567e-02,
                2.89747879e-02, 1.48794161e-01, 2.58256312e-02, 1.40703542e-01,
                1.42261877e+00
            ],
            [
                1.00000000e+00, 1.89996820e-01, -8.10524520e-01,
                -9.10953563e-02, -1.51000267e-01, -5.51353280e-01,
                -9.63901208e-01, -1.53997081e-01, -1.73078280e-02,
                -2.86895706e-02, -1.04755370e-01, 4.85424996e-01,
                7.38350200e-02, 1.22389419e-01, 4.46885353e-01,
                -4.20825096e-02, 1.37554232e-02, 5.02257235e-02,
                1.73535330e-02, 8.32544927e-02, 4.06696999e-01
            ],
            [
                1.00000000e+00, 8.93080800e-01, 3.61368360e-01,
                -3.11571681e-01, -6.63251780e-02, -7.42846840e-01,
                -2.02406685e-01, 3.22731144e-01, -2.78258686e-01,
                -5.92337430e-02, -6.63422250e-01, -3.04119363e-01,
                -1.12592148e-01, -2.39678208e-02, -2.68441344e-01,
                1.93680256e-01, 2.06650472e-02, 2.31450039e-01,
                -2.36285423e-02, 4.92694489e-02, 1.03751511e+00
            ],
            [
                1.00000000e+00, 6.22657640e-01, 3.78005280e-01, 4.52957657e-02,
                2.60509690e-02, -6.29942760e-01, -6.12297463e-01,
                2.35367876e-01, 2.82037546e-02, 1.62208349e-02,
                -3.92238672e-01, -2.85668012e-01, 1.71220386e-02,
                9.84740383e-03, -2.38121689e-01, -1.39256582e-01,
                1.17999859e-03, -2.85337396e-02, -5.19825578e-02,
                -1.64106193e-02, 6.56713401e-01
            ],
            [
                1.00000000e+00, 4.13346580e-01, -9.18781320e-01,
                7.15057627e-02, 2.39001432e-01, 7.48878960e-01,
                -8.29144605e-01, -3.79775116e-01, 2.95566624e-02,
                9.87904245e-02, 3.09546557e-01, 7.66238671e-01,
                -6.56981590e-02, -2.19590051e-01, -6.88055999e-01,
                -1.53668545e-01, 1.70899797e-02, 5.35491612e-02,
                -5.23263164e-02, 1.78983144e-01, -1.93693822e+00
            ],
            [
                1.00000000e+00, -2.11162360e-01, -1.17471400e-01,
                -3.24297192e-01, -1.69882718e-01, -7.40774800e-01,
                -9.55410458e-01, 2.48055381e-02, 6.84793603e-02,
                3.58728357e-02, 1.56423755e-01, -4.79300705e-01,
                3.80956451e-02, 1.99563607e-02, 8.70198528e-02, 2.10255685e-01,
                5.50924884e-02, 2.40231187e-01, 2.84479103e-02, 1.25844836e-01,
                1.03029690e+00
            ],
            [
                1.00000000e+00, -9.90015000e-01, 3.15745200e-02,
                -2.67667763e-01, 1.03288932e-01, 2.31867600e-02,
                -1.98702998e-02, -3.12592484e-02, 2.64995101e-01,
                -1.02257592e-01, -2.29552402e-02, -4.98504575e-01,
                -8.45148115e-03, 3.26129845e-03, 7.32110817e-04,
                1.38980096e-01, -2.76471174e-02, -6.20634819e-03,
                -6.25893974e-02, 2.39493568e-03, -1.04583589e+00
            ],
            [
                1.00000000e+00, -6.83331920e-01, -8.36100760e-01,
                2.54633238e-01, -1.49004343e-01, -7.45421960e-01,
                -5.33057487e-01, 5.71334338e-01, -1.73999019e-01,
                1.01819424e-01, 5.09370619e-01, 5.48596721e-01,
                -2.12899044e-01, 1.24582644e-01, 6.23247867e-01,
                -2.16028517e-01, -3.79414582e-02, -1.89809207e-01,
                1.62224998e-02, 1.11071109e-01, 1.04649782e+00
            ],
            [
                1.00000000e+00, -1.36265982e+00, 9.92398280e-01,
                2.96920935e-01, 7.56681370e-02, -7.55404580e-01,
                8.56841785e-01, -1.35230126e+00, -4.04602227e-01,
                -1.03109930e-01, 1.02935947e+00, 9.77281519e-01,
                2.94663825e-01, 7.50929290e-02, -7.49662206e-01,
                -2.20896359e-01, 2.24674540e-02, -2.24295434e-01,
                -6.01667886e-02, -5.71600572e-02, 1.08144524e+00
            ],
            [
                1.00000000e+00, -3.16765880e-01, 5.37317360e-01,
                3.01680247e-02, -1.80986885e-01, 2.62615756e+00,
                -8.99659377e-01, -1.70203806e-01, -9.55620088e-03,
                5.73304701e-02, -8.31877111e-01, -6.69350820e-02,
                1.62098034e-02, -9.72473955e-02, 1.41108005e+00,
                -1.30313018e-01, -5.46001683e-03, 7.92259860e-02,
                3.53051365e-02, -4.75300078e-01, 6.44388410e-01
            ],
            [
                1.00000000e+00, 7.16310160e-01, -4.14467000e-01,
                -1.17746724e-01, 4.41686770e-02, 8.71249900e-01,
                -4.86899755e-01, -2.96886923e-01, -8.43431749e-02,
                3.16384721e-02, 6.24085155e-01, -2.42325659e-01,
                4.88021316e-02, -1.83064591e-02, -3.61104332e-01,
                -1.87490038e-02, -5.20071703e-03, -1.02586822e-01,
                -5.55417276e-02, 3.84819554e-02, -1.98342341e+00
            ],
            [
                1.00000000e+00, -1.00456128e+00, -9.40804320e-01,
                -4.91374303e-02, -1.55594934e-01, -7.89187220e-01,
                9.14336528e-03, 9.45095592e-01, 4.93615599e-02, 1.56304646e-01,
                7.92786924e-01, 8.27669153e-01, 4.62287067e-02, 1.46384386e-01,
                7.42470746e-01, -7.59383372e-02, 7.64553522e-03,
                3.87786320e-02, 1.99874801e-02, 1.22793533e-01, 1.20119091e+00
            ],
            [
                1.00000000e+00, -4.12394260e-01, 6.95524720e-01,
                -1.84930913e-02, -3.85466200e-02, 1.84317468e+00,
                -8.29930974e-01, -2.86830402e-01, 7.62644472e-03,
                1.58964048e-02, -7.60114658e-01, 2.25631954e-01,
                -1.28624022e-02, -2.68101271e-02, 1.28197355e+00,
                -9.84403891e-02, 7.12846164e-04, -3.40859977e-02,
                -3.39493451e-02, -7.10481540e-02, -1.28905646e+00
            ],
            [
                1.00000000e+00, 9.54209420e-01, 4.13589560e-01,
                -3.12780915e-01, 1.61749000e-04, -6.45176300e-01,
                -8.94843828e-02, 3.94651054e-01, -2.98458496e-01,
                1.54342419e-04, -6.15633303e-01, -2.43415514e-01,
                -1.29362921e-01, 6.68976977e-05, -2.66838182e-01,
                1.95241400e-01, -5.05920003e-05, 2.01798834e-01,
                -4.57573926e-02, -1.04356621e-04, 7.06605058e-01
            ],
            [
                1.00000000e+00, -1.19403680e-01, 2.27365200e-01,
                -1.76593100e-01, -1.94909078e-01, 7.35469880e-01,
                -9.85742761e-01, -2.71482416e-02, 2.10858660e-02,
                2.32728612e-02, -8.78178102e-02, -4.22457599e-01,
                -4.01511256e-02, -4.43155415e-02, 1.67220256e-01,
                3.78027455e-02, 3.44195984e-02, -1.29878906e-01,
                4.42510171e-02, -1.43349756e-01, -1.93002382e+00
            ],
            [
                1.00000000e+00, 4.98915360e-01, -3.17935240e-01,
                1.88166350e-01, -1.99624237e-01, -2.38930000e-02,
                -7.51083464e-01, -1.58622775e-01, 9.38790821e-02,
                -9.95955979e-02, -1.19205847e-02, -3.48375775e-01,
                -5.98247135e-02, 6.34675796e-02, 7.59642669e-03,
                -2.01148769e-01, -3.75625639e-02, -4.49585859e-03,
                4.73686799e-02, 4.76962189e-03, -9.51643125e-01
            ]
        ])
        # endregion: var_basis_sys_eval

        self.var_list = [norm_var, unif_var, exp_var, beta_var, gamma_var]
        self.epist_samps = 125
        self.aleat_samps = 25000

        self.pbox = ProbabilityBoxes(self.var_list)
        self.pbox.matrix_coeffs = self.matrix_coeffs
        self.pbox.count_epistemic()
        self.pbox.generate_aleatory_samples()
        self.pbox.generate_epistemic_samples()

        self.eval_resps, self.out_msg = self.pbox.evaluate_surrogate(
            self.var_basis_vect_symb, self.sig, self.matrix_coeffs,
            self.conv_thresh_percent)

        self.approx_mean, self.mean_uncert = self.pbox.calc_mean_conf_int(
            self.var_basis_sys_eval, self.responses, self.sig)

        setattr(self.var_list[1], 'type', UncertaintyType.EPISTEMIC)
        self.pbox = ProbabilityBoxes(self.var_list)
        self.pbox.matrix_coeffs = self.matrix_coeffs
        self.pbox.count_epistemic()
        self.pbox.generate_aleatory_samples()
        self.pbox.generate_epistemic_samples()
        self.epist_var_count = self.pbox.epist_var_count
Exemplo n.º 8
0
    def read_var_input(self, var_dict, order):
        """
        Inputs: var_dict- the variable dictionaries
                order- the order value at this step in the program
        
        Constructs Variable types in the appropriate subclass based on the 
        information in each of the Variable dictionaries.
        """
        var_names = list(var_dict)
        var_count = len(var_dict)
        self.var_count = var_count

        comm = MPI_COMM_WORLD
        size = comm.size
        rank = comm.rank

        base = var_count // size
        rem = var_count % size
        count = base + (rank < rem)

        var_list = np.zeros(count, dtype=object)

        if is_manager and self.verbose:
            print('Initializing Problem\n\nSetting up Variables\n')

        i = rank
        idx = 0

        while i < var_count:

            curr_var_dict = var_dict[var_names[i]]
            distribution = curr_var_dict.pop('distribution')
            dist = Distribution.from_name(distribution)

            if dist is Distribution.NORMAL:
                var_list[idx] = NormalVariable(curr_var_dict.pop('mean'),
                                               curr_var_dict.pop('stdev'),
                                               number=i,
                                               order=order,
                                               **curr_var_dict)

            elif dist is Distribution.UNIFORM:
                var_list[idx] = UniformVariable(
                    curr_var_dict.pop('interval_low'),
                    curr_var_dict.pop('interval_high'),
                    number=i,
                    order=order,
                    **curr_var_dict)

            elif dist is Distribution.BETA:
                var_list[idx] = BetaVariable(curr_var_dict.pop('alpha'),
                                             curr_var_dict.pop('beta'),
                                             number=i,
                                             order=order,
                                             **curr_var_dict)

            elif dist is Distribution.EXPONENTIAL:
                var_list[idx] = ExponentialVariable(
                    curr_var_dict.pop('lambda'),
                    number=i,
                    order=order,
                    **curr_var_dict)

            elif dist is Distribution.GAMMA:
                var_list[idx] = GammaVariable(curr_var_dict.pop('alpha'),
                                              curr_var_dict.pop('theta'),
                                              number=i,
                                              order=order,
                                              **curr_var_dict)

            elif dist is Distribution.CONTINUOUS:
                var_list[idx] = ContinuousVariable(
                    curr_var_dict.pop('pdf'),
                    curr_var_dict.pop('interval_low'),
                    curr_var_dict.pop('interval_high'),
                    number=i,
                    order=order,
                    **curr_var_dict)

            elif dist is Distribution.DISCRETE_UNIFORM:
                var_list[idx] = DiscUniformVariable(
                    curr_var_dict.pop('interval_low'),
                    curr_var_dict.pop('interval_high'),
                    number=i,
                    order=order,
                    **curr_var_dict)

            elif dist is Distribution.NEGATIVE_BINOMIAL:
                var_list[idx] = NegativeBinomialVariable(
                    curr_var_dict.pop('r'),
                    curr_var_dict.pop('p'),
                    number=i,
                    order=order,
                    **curr_var_dict)

            elif dist is Distribution.POISSON:
                var_list[idx] = PoissonVariable(curr_var_dict.pop('lambda'),
                                                number=i,
                                                order=order,
                                                **curr_var_dict)

            elif dist is Distribution.HYPERGEOMETRIC:
                var_list[idx] = HypergeometricVariable(curr_var_dict.pop('M'),
                                                       curr_var_dict.pop('n'),
                                                       curr_var_dict.pop('N'),
                                                       number=i,
                                                       order=order,
                                                       **curr_var_dict)

            elif dist is Distribution.DISCRETE:
                var_list[idx] = DiscreteVariable(
                    curr_var_dict.pop('pdf'),
                    curr_var_dict.pop('interval_low'),
                    curr_var_dict.pop('interval_high'),
                    number=i,
                    order=order,
                    **curr_var_dict)

            i += size
            idx += 1

        var_list_tot = comm.allgather(var_list)
        self.var_list = np.zeros(var_count, dtype=object)

        for i in range(size):

            idx = i
            var_cnk = var_list_tot[i]
            var_cnk_size = len(var_cnk)

            for j in range(var_cnk_size):
                self.var_list[idx] = var_cnk[j]

                idx += size

        return self.var_list
Exemplo n.º 9
0
    1.57110079, 0.58397168, 0.28099855, 1.05482927, 1.40968597, 1.60103053,
    1.76458409, 1.18931793, 1.67683969, 0.97636684, 0.09914773, 1.12167674,
    0.95950223, 0.57282726, 2.09024103, 1.26232112, 1.87918827, 1.09499841,
    1.4465404, 1.31132882, 1.20667329, 0.89441882, 0.5049925, 0.65833404,
    0.31867009, 0.84161706, 1.35815508, 0.49771936, 0.79380287, 1.47710471,
    0.94029816, 1.24945768
])
norm_var.std_vals = norm_var.standardize('vals', 'std_vals')
norm_var.std_verify_vals = norm_var.standardize_points(
    np.array([1.029939809893880]))
# endregion: normal variable

# region: uniform variable
interval_low = 1.75
interval_high = 2.25
unif_var = UniformVariable(interval_low, interval_high, order=order, number=1)
unif_var.vals = np.array([
    2.24175203, 1.86126492, 1.76806408, 1.99217273, 2.11340606, 2.21447413,
    1.78640677, 1.88201559, 1.85798326, 2.23527088, 2.16077857, 2.17751665,
    2.20046952, 2.05883816, 2.2450643, 2.07235355, 1.95016395, 2.12835819,
    1.88891429, 1.94867102, 1.8546233, 1.92380071, 2.17457973, 1.81447488,
    2.13691741, 1.84828762, 1.75680435, 1.94961961, 1.8404631, 1.94830901,
    1.99328695, 1.78768032, 1.90646027, 2.17054326, 1.95000092, 1.79736887,
    2.09034209, 2.09450132, 1.77030467, 1.97063215, 2.00789363, 1.79097481,
    2.24809957, 2.13432934, 1.89638325, 1.76479892, 2.17388118, 2.10339739,
    2.0568413, 1.92051619
])
unif_var.std_vals = unif_var.standardize('vals', 'std_vals')
unif_var.std_verify_vals = unif_var.standardize_points(
    np.array([2.103023044009805]))
# endregion: uniform variable