コード例 #1
0
ファイル: test_gevfit.py プロジェクト: guziy/GevFit
    def test_ML(self):

        ksi0 = -0.1
        mu0 = 1000.0
        sigma0 = 100.0


        vals = []
        ps_0 = []
        ps_lm = []
        ps_gml = []
        ps_for_vals = []
        for i in range(30):
           p = random.random()
           ps_for_vals.append(p)
           vals.append(gev_cdf_inverse(p, sigma0, mu0, ksi0))

        vals = np.array(vals)

        xs = np.arange(800, 1500, 10)


        
        sigma_lm, mu_lm, ksi_lm, dummy = gevfit.optimize_stationary_for_period(vals, use_lmoments = True)
        sigma_gml, mu_gml, ksi_gml, dummy = gevfit.optimize_stationary_for_period(vals, use_lmoments = False)

        for x in xs:
            ps_0.append(gev_cdf(x, sigma0, mu0, ksi0))
            ps_lm.append(gev_cdf(x, sigma_lm, mu_lm, ksi_lm))
            ps_gml.append(gev_cdf(x, sigma_gml, mu_gml, ksi_gml))


        print('LM: ', sigma_lm, mu_lm, ksi_lm)
        print('GML: ', sigma_gml, mu_gml, ksi_gml)
        print(ps_lm)
        plt.title(r'$\sigma = %.2f , \mu = %.2f , \xi = %.2f$' % (sigma0, mu0, ksi0))
        plt.plot(xs, ps_0, linewidth = 2, label = 'Theory')
        plt.plot(xs, ps_lm, linewidth = 2, label = 'LM')
        plt.plot(xs, ps_gml, linewidth = 2, label = 'GML')

        plt.plot(vals, ps_for_vals, 'o',  label = 'Sample')

        plt.xlabel('$x$')
        plt.ylabel('CDF')

        plt.legend()
        plt.show()



        pass
コード例 #2
0
ファイル: bootstrap.py プロジェクト: guziy/GevFit
def function_for_each_process(args):
    sample_index, sampled_indices, extremes, \
    return_periods, high_flow, positions = args

    print('I work on sample %d' % sample_index)
    
    result = {}
    for the_period in return_periods:
        result[the_period] = []



    for pos in positions:
        pars = gevfit.optimize_stationary_for_period(extremes[sampled_indices, pos],
                                                    high_flow = high_flow)

        #calculate return levels for the current position and sample
        for the_period in return_periods:
            if high_flow:
                ret_level = gevfit.get_high_ret_level_stationary(pars, the_period)
            else:
                ret_level = gevfit.get_low_ret_level_stationary(pars, the_period)
            result[the_period].append(ret_level)
    return result