Пример #1
0
def HistogramPLOT_wbm(data, month, year):
    #Initiate
    Situation = []
    mon = [
        'January', 'Febuary', 'March', 'April', 'May', 'June', 'July',
        'August', 'September', 'October', 'November', 'December'
    ]
    data01 = data[['DateTime', 'WS95']].copy()
    data01.dropna(how='any', inplace=True)
    logicY = (data01["DateTime"].apply(lambda x: x.year) == (year))
    data01 = data01[logicY].copy()
    fig = plt.figure(figsize=(20, 32), facecolor='w', edgecolor='r')
    #Plotting 12 graph
    xvals = np.linspace(0, 30, 1000)
    for i in range(month):
        ax = plt.subplot2grid((4, 3), (int(np.floor(i / 3)), int(i % 3)))
        logic = (data01["DateTime"].apply(lambda x: x.month)) == (i + 1)
        ws = data01['WS95'][logic]
        ws = ws + 0.0001
        failures = []
        censored = []
        threshold = 30
        for item in ws:
            if item > threshold:
                censored.append(threshold)
            else:
                failures.append(item)
        xvals = np.linspace(0, 30, 1000)
        if (np.sum(logic) != 0):
            ax.hist(ws, bins=30, density=True)
            hist, edge = np.histogram(np.array(ws),
                                      bins=1000,
                                      range=(0, 30),
                                      density=True)
            wbm = Fit_Weibull_Mixture(failures=failures,
                                      right_censored=censored,
                                      show_plot=False,
                                      print_results=False)
            part1_pdf = Weibull_Distribution(alpha=wbm.alpha_1,
                                             beta=wbm.beta_1).PDF(
                                                 xvals=xvals, show_plot=False)
            part2_pdf = Weibull_Distribution(alpha=wbm.alpha_2,
                                             beta=wbm.beta_2).PDF(
                                                 xvals=xvals, show_plot=False)
            Mixture_PDF = part1_pdf * wbm.proportion_1 + part2_pdf * wbm.proportion_2
            ax.plot(xvals, Mixture_PDF, label='Weibull_Mixture')
        ax.legend()
        ax.set_ylim(0, 0.18)
        ax.set_xlim(0, 30)
        ax.set_xticks([0, 5, 10, 15, 20, 25, 30])
        ax.tick_params(axis="x", labelsize=30)
        ax.tick_params(axis="y", labelsize=26)
        ax.set_title('{}'.format(mon[i]), fontweight='bold', size=30)
    plt.tight_layout()
    plt.show()
Пример #2
0
def test_Fit_Weibull_Mixture():
    group_1 = Weibull_Distribution(alpha=10, beta=3).random_samples(40, seed=2)
    group_2 = Weibull_Distribution(alpha=40, beta=4).random_samples(60, seed=2)
    raw_data = np.hstack([group_1, group_2])
    data = make_right_censored_data(data=raw_data, threshold=40)
    fit = Fit_Weibull_Mixture(failures=data.failures, right_censored=data.right_censored, print_results=False, show_probability_plot=False)
    assert_allclose(fit.alpha_1, 8.711417800323375,rtol=rtol,atol=atol)
    assert_allclose(fit.alpha_2, 36.96927163816745, rtol=rtol, atol=atol)
    assert_allclose(fit.beta_1, 3.8780149153215278, rtol=rtol, atol=atol)
    assert_allclose(fit.beta_2, 4.901762153365169, rtol=rtol, atol=atol)
    assert_allclose(fit.AICc, 678.8135631521253, rtol=rtol, atol=atol)
    assert_allclose(fit.loglik, -334.08763263989243, rtol=rtol, atol=atol)
Пример #3
0
def test_Fit_Weibull_Mixture():
    d1 = Weibull_Distribution(alpha=10, beta=3)
    d2 = Weibull_Distribution(alpha=40, beta=4)
    dist = Mixture_Model(distributions=[d1, d2], proportions=[0.2, 0.8])
    raw_data = dist.random_samples(100, seed=2)
    data = make_right_censored_data(data=raw_data, threshold=dist.mean)

    MLE = Fit_Weibull_Mixture(failures=data.failures, right_censored=data.right_censored, show_probability_plot=False, print_results=False)
    assert_allclose(MLE.alpha_1, 11.06604639424718, rtol=rtol, atol=atol)
    assert_allclose(MLE.beta_1, 2.735078296796997, rtol=rtol, atol=atol)
    assert_allclose(MLE.alpha_2, 34.325433665495346, rtol=rtol, atol=atol)
    assert_allclose(MLE.beta_2, 7.60238532821206, rtol=rtol, atol=atol)
    assert_allclose(MLE.proportion_1, 0.23640116719132157, rtol=rtol, atol=atol)
    assert_allclose(MLE.proportion_2, 0.7635988328086785, rtol=rtol, atol=atol)
    assert_allclose(MLE.AICc, 471.97390405380236, rtol=rtol, atol=atol)
    assert_allclose(MLE.BIC, 484.3614571114024, rtol=rtol, atol=atol)
    assert_allclose(MLE.loglik, -230.66780309073096, rtol=rtol, atol=atol)
    assert_allclose(MLE.AD, 320.1963544647712, rtol=rtol, atol=atol)
Пример #4
0
def HistogramPLOT_all(data, month, year):
    #Initiate
    Situation = []
    mon = [
        'January', 'Febuary', 'March', 'April', 'May', 'June', 'July',
        'August', 'September', 'October', 'November', 'December'
    ]
    #Get just Full day data
    logicF = (data["isFULL"].apply(lambda x: x) == (1))
    data01 = data[logicF].copy()
    data01.fillna(method='ffill', inplace=True)

    logicY = (data01["DateTime"].apply(lambda x: x.year) == (year))
    data01 = data01[logicY].copy()

    fig = plt.figure(figsize=(24, 18), dpi=80, facecolor='w', edgecolor='r')
    #Plotting 12 graph
    xvals = np.linspace(0, 30, 1000)
    for i in range(month):
        ax = plt.subplot2grid((4, 3), (int(np.floor(i / 3)), int(i % 3)))
        logic = (data01["DateTime"].apply(lambda x: x.month)) == (i + 1)
        ws = data01['WS95'][logic]
        ws = ws + 0.0001
        failures = []
        censored = []
        threshold = 30
        for item in ws:
            if item > threshold:
                censored.append(threshold)
            else:
                failures.append(item)
        xvals = np.linspace(0, 30, 1000)
        print(ws.shape)
        if (np.sum(logic) != 0):
            ax.hist(ws, bins=30, normed=True)
            hist, edge = np.histogram(np.array(ws),
                                      bins=1000,
                                      range=(0, 30),
                                      normed=True)
            wb2 = Fit_Weibull_2P(failures=failures,
                                 show_probability_plot=False,
                                 print_results=False)
            wb3 = Fit_Weibull_3P(failures=failures,
                                 show_probability_plot=False,
                                 print_results=False)
            gm2 = Fit_Gamma_2P(failures=failures,
                               show_probability_plot=False,
                               print_results=False)
            gm3 = Fit_Gamma_3P(failures=failures,
                               show_probability_plot=False,
                               print_results=False)
            ln2 = Fit_Lognormal_2P(failures=failures,
                                   show_probability_plot=False,
                                   print_results=False)
            wbm = Fit_Weibull_Mixture(failures=failures,
                                      right_censored=censored,
                                      show_plot=False,
                                      print_results=False)

            wb2_pdf = Weibull_Distribution(alpha=wb2.alpha, beta=wb2.beta).PDF(
                xvals=xvals, show_plot=True, label='Weibull_2P')
            wb3_pdf = Weibull_Distribution(alpha=wb3.alpha,
                                           beta=wb3.beta,
                                           gamma=wb3.gamma).PDF(
                                               xvals=xvals,
                                               show_plot=True,
                                               label='Weibull_3P')
            gm2_pdf = Gamma_Distribution(alpha=gm2.alpha,
                                         beta=gm2.beta).PDF(xvals=xvals,
                                                            show_plot=True,
                                                            label='Gamma_2P')
            gm3_pdf = Gamma_Distribution(alpha=gm3.alpha,
                                         beta=gm3.beta,
                                         gamma=gm3.gamma).PDF(xvals=xvals,
                                                              show_plot=True,
                                                              label='Gamma_3P')
            ln2_pdf = Lognormal_Distribution(mu=ln2.mu, sigma=ln2.sigma).PDF(
                xvals=xvals, show_plot=True, label='Lognormal_2P')

            part1_pdf = Weibull_Distribution(alpha=wbm.alpha_1,
                                             beta=wbm.beta_1).PDF(
                                                 xvals=xvals, show_plot=False)
            part2_pdf = Weibull_Distribution(alpha=wbm.alpha_2,
                                             beta=wbm.beta_2).PDF(
                                                 xvals=xvals, show_plot=False)
            Mixture_PDF = part1_pdf * wbm.proportion_1 + part2_pdf * wbm.proportion_2
            ax.plot(xvals, Mixture_PDF, label='Weibull_Mixture')
        ax.legend()
        ax.set_ylim(0, 0.16)
        ax.set_xlim(0, 30)
        ax.set_xticks([0, 5, 10, 15, 20, 25, 30])
        ax.tick_params(axis="x", labelsize=20)
        ax.tick_params(axis="y", labelsize=20)
        ax.set_title('{}'.format(mon[i]), fontweight='bold', size=20)
    plt.tight_layout()
    plt.show()