Example #1
0
    def test_fragility(self):
        #in
        """
        btype=1

        Thresh=array([3.41376, 27.31008, 51.2064, 102.4128])
        SDcr=0.900320457314158
        beta=0.5

        #out

        0.00384212302089559  4.41097158798698e-012 3.33066907387547e-016 0

        Pr1=array([0.00384212302089559, 4.41097158798698e-012,
                   3.33066907387547e-016, 0])

        Pr_sd=array([0.996157876979104, 0.00384212301648462,
                     4.41063852107959e-012, 3.33066907387547e-016, 0])
        """

        threshold = array([3.41376, 27.31008, 51.2064, 102.4128])
        value = 0.900320457314158
        beta = 0.5
        cdf = cumulative_state_probability(threshold, beta, value)

        cdf_matlab = array([0.00384212302089559, 4.41097158798698e-012,
                            3.33066907387547e-016, 0])
        assert allclose(cdf, cdf_matlab)
        reduce_cumulative_to_pdf(cdf)
        pdf=cdf

        pdf_matlab = array([0.996157876979104, 0.00384212301648462,
                            4.41063852107959e-012, 3.33066907387547e-016, 0])

        assert allclose(pdf, pdf_matlab[1:])

        f1 = array((0.02, 0.1, 0.5, 1.0))	# [newaxis, newaxis, :]
        ci = 1.4516
        Area = 4351.656708
        cost = 113.9023

        damage_matlab = array([0.00875252912708771, 5.02381651487638e-011,
                               1.89685350759916e-014, 0])

        assert allclose(damage_matlab, f1*pdf*cost)

        cost_matlab = 55.2885441482002
        assert allclose(cost_matlab, (f1*pdf*cost*Area*ci).sum())
Example #2
0
    def test_fragility(self):
        #in
        """
        btype=1

        Thresh=array([3.41376, 27.31008, 51.2064, 102.4128])
        SDcr=0.900320457314158
        beta=0.5

        #out

        0.00384212302089559  4.41097158798698e-012 3.33066907387547e-016 0

        Pr1=array([0.00384212302089559, 4.41097158798698e-012,
                   3.33066907387547e-016, 0])

        Pr_sd=array([0.996157876979104, 0.00384212301648462,
                     4.41063852107959e-012, 3.33066907387547e-016, 0])
        """

        threshold = array([3.41376, 27.31008, 51.2064, 102.4128])
        value = 0.900320457314158
        beta = 0.5
        cdf = cumulative_state_probability(threshold, beta, value)

        cdf_matlab = array([0.00384212302089559, 4.41097158798698e-012,
                            3.33066907387547e-016, 0])
        assert allclose(cdf, cdf_matlab)
        reduce_cumulative_to_pdf(cdf)
        pdf=cdf

        pdf_matlab = array([0.996157876979104, 0.00384212301648462,
                            4.41063852107959e-012, 3.33066907387547e-016, 0])

        assert allclose(pdf, pdf_matlab[1:])

        f1 = array((0.02, 0.1, 0.5, 1.0))	# [newaxis, newaxis, :]
        ci = 1.4516
        Area = 4351.656708
        cost = 113.9023

        damage_matlab = array([0.00875252912708771, 5.02381651487638e-011,
                               1.89685350759916e-014, 0])

        assert allclose(damage_matlab, f1*pdf*cost)

        cost_matlab = 55.2885441482002
        assert allclose(cost_matlab, (f1*pdf*cost*Area*ci).sum())
Example #3
0
    def test_cumulative_state_probability(self):
        blocking_block_comments = True
        """Test that cumulative_state_probability works the same way
        as matlab function.

        Test that reduce_cumulative_to_pdf 'looks' right - it should
        look a bit like a bell curve - zero at ends with a max
        somewhere in the middle, and sum=one.
        """

        # test against matlab implementation:
        beta = 0.4
        value = 5.0
        
        threshold = array((0.000001, 0.00001, 1, 1.5, 2, 3, 4, 5, 10, 100, 1000))

        oldsettings = seterr(divide='ignore')
        x = (1/beta)*log(value/threshold)
        seterr(**oldsettings)
        # matlab:
        # Pr11 = normcdf2(1/THE_VUN_T.('beta_nsd_d')*log(SDcrAll./Thresh))

        root2 = sqrt(2)
        y = 0.5*(1 + erf(x/root2))
        # matlab:
        # root2 = sqrt(2);
        # y = 0.5*(1+erf(x/root2))
        y2 = cumulative_state_probability(threshold, beta, value)
        assert allclose(y, y2)

        reduce_cumulative_to_pdf(y)

        # y should now look a bit  like a bell curve - zero at ends
        # increasing to the middle, sum=one.
        assert (y.sum() == 1.0)
        assert y[0] == 0
        assert y[1] < y[2]
        assert y[-3] > y[-2]
Example #4
0
 def test_reduce_cumulative_to_pdf(self):
     cumulative = array([1.0, 0.6, 0.3, 0.1])
     non_cummulative = cumulative[:]
     reduce_cumulative_to_pdf(non_cummulative)
     actual = array([0.4, 0.3, 0.2, 0.1])
     assert allclose(asarray(non_cummulative),asarray(actual))
Example #5
0
 def test_reduce_cumulative_to_pdf(self):
     cumulative = array([1.0, 0.6, 0.3, 0.1])
     non_cummulative = cumulative[:]
     reduce_cumulative_to_pdf(non_cummulative)
     actual = array([0.4, 0.3, 0.2, 0.1])
     assert allclose(asarray(non_cummulative),asarray(actual))