示例#1
0
    def test_multivariate_draw_sample(self):
        """
            Create an example MultivariateDistribution (Vanem2012 model).
            """

        # Define dependency tuple.
        dep1 = (None, None, None)
        dep2 = (0, None, 0)

        # Define parameters.
        shape = ConstantParam(1.471)
        loc = ConstantParam(0.8888)
        scale = ConstantParam(2.776)
        par1 = (shape, loc, scale)

        shape = FunctionParam('exp3', 0.0400, 0.1748, -0.2243)
        loc = None
        scale = FunctionParam('power3', 0.1, 1.489, 0.1901)
        par2 = (shape, loc, scale)

        del shape, loc, scale

        # Create distributions.
        dist1 = WeibullDistribution(*par1)
        dist2 = LognormalDistribution(*par2)

        distributions = [dist1, dist2]
        dependencies = [dep1, dep2]
        ref_points = 99119
        mul_var_dist = MultivariateDistribution(distributions, dependencies)
        my_points = mul_var_dist.draw_sample(ref_points)
        my_points0 = my_points[0].size
        my_points1 = my_points[1].size
        assert ref_points == my_points0
        assert ref_points == my_points1
示例#2
0
    def test_draw_sample_distribution(self):
        """
            Create an example MultivariateDistribution (Vanem2012 model).
            """

        # Define dependency tuple.
        dep1 = (None, None, None)
        dep2 = (0, None, 0)

        # Define parameters.
        shape = ConstantParam(1.471)
        loc = ConstantParam(0.8888)
        scale = ConstantParam(2.776)
        par1 = (shape, loc, scale)

        shape = FunctionParam('exp3', 0.0400, 0.1748, -0.2243)
        loc = None
        scale = FunctionParam('power3', 0.1, 1.489, 0.1901)
        par2 = (shape, loc, scale)

        del shape, loc, scale

        # Create distributions.
        dist1 = WeibullDistribution(*par1)
        dist2 = LognormalDistribution(*par2)

        distributions = [dist1, dist2]
        dependencies = [dep1, dep2]
        points = 1000000
        mul_var_dist = MultivariateDistribution(distributions, dependencies)
        my_points = mul_var_dist.draw_sample(points)

        #Fit the sample
        # Describe the distribution that should be fitted to the sample.
        dist_description_0 = {
            'name': 'Weibull',
            'dependency': (None, None, None),
            'width_of_intervals': 2
        }
        dist_description_1 = {
            'name': 'Lognormal',
            'dependency': (0, None, 0),
            'functions': ('exp3', None, 'power3')
        }
        my_fit = Fit([my_points[0], my_points[1]],
                     [dist_description_0, dist_description_1])
        print(my_fit.mul_var_dist.distributions[0].shape(0))
        print(mul_var_dist.distributions[0].shape(0))
        assert np.round(my_fit.mul_var_dist.distributions[0].shape(0),
                        2) == np.round(mul_var_dist.distributions[0].shape(0),
                                       2)
示例#3
0

def ecdf(data):
    """ Compute ECDF """
    x = np.sort(data)
    n = x.size
    F = np.arange(1, n + 1) / n
    return (x, F)


variable_list = [u, hs]
var_symbols = ['$U_{10}$ (m/s)', '$H_s$ (m)']
var_labels = [lu, lhs]

# Use a Monte Carlo sample from the joint model for subsequent calculations
mc_sample = joint_model_4.draw_sample(len(u) * MC_FACTOR)
mc_u = mc_sample[0]
mc_hs = mc_sample[1]

# Probability - Quantile plot
for i, x in enumerate(variable_list):
    x_ordered, F = ecdf(x)
    alpha = 1 - F
    tr = 1 / (alpha * 365.25 * 24)
    tr_threshold = 0.0001
    axs1[i].plot(tr[tr >= tr_threshold],
                 x_ordered[tr >= tr_threshold],
                 'ok',
                 markerfacecolor='none',
                 ms=3,
                 rasterized=True)