def __update_params(_, self): value1 = self.s0.val value2 = self.s1.val value3 = self.s2.val if self.name == 'Weibull': dist = Weibull_Distribution(alpha=value1, beta=value2, gamma=value3) elif self.name == 'Loglogistic': dist = Loglogistic_Distribution(alpha=value1, beta=value2, gamma=value3) elif self.name == 'Gamma': dist = Gamma_Distribution(alpha=value1, beta=value2, gamma=value3) elif self.name == 'Loglogistic': dist = Loglogistic_Distribution(alpha=value1, beta=value2, gamma=value3) elif self.name == 'Lognormal': dist = Lognormal_Distribution(mu=value1, sigma=value2, gamma=value3) elif self.name == 'Beta': dist = Beta_Distribution(alpha=value1, beta=value2) elif self.name == 'Normal': dist = Normal_Distribution(mu=value1, sigma=value2) elif self.name == 'Exponential': dist = Exponential_Distribution(Lambda=value1, gamma=value2) else: raise ValueError(str(self.name + ' is an unknown distribution name')) plt.sca(self.ax_pdf) plt.cla() dist.PDF() plt.title('PDF') plt.xlabel('') plt.ylabel('') plt.sca(self.ax_cdf) plt.cla() dist.CDF() plt.title('CDF') plt.xlabel('') plt.ylabel('') plt.sca(self.ax_sf) plt.cla() dist.SF() plt.title('SF') plt.xlabel('') plt.ylabel('') plt.sca(self.ax_hf) plt.cla() dist.HF() plt.title('HF') plt.xlabel('') plt.ylabel('') plt.sca(self.ax_chf) plt.cla() dist.CHF() plt.title('CHF') plt.xlabel('') plt.ylabel('') plt.subplots_adjust(left=0.07, right=0.98, top=0.9, bottom=0.25, wspace=0.18, hspace=0.30) plt.suptitle(dist.param_title_long, fontsize=15) plt.draw()
def __init__(self): # initialise the 5 plots plt.figure('Distribution Explorer', figsize=(12, 7)) self.name = 'Weibull' # starting value dist = Weibull_Distribution(alpha=100, beta=2, gamma=0) plt.suptitle(dist.param_title_long, fontsize=15) self.ax_pdf = plt.subplot(231) dist.PDF() plt.title('PDF') plt.xlabel('') plt.ylabel('') self.ax_cdf = plt.subplot(232) dist.CDF() plt.title('CDF') plt.xlabel('') plt.ylabel('') self.ax_sf = plt.subplot(233) dist.SF() plt.title('SF') plt.xlabel('') plt.ylabel('') self.ax_hf = plt.subplot(234) dist.HF() plt.title('HF') plt.xlabel('') plt.ylabel('') self.ax_chf = plt.subplot(235) dist.CHF() plt.title('CHF') plt.xlabel('') plt.ylabel('') plt.subplots_adjust(left=0.07, right=0.98, top=0.9, bottom=0.25, wspace=0.18, hspace=0.30) # initialise the sliders x0 = 0.1 width = 0.8 height = 0.03 self.active_color = 'steelblue' self.background_color = 'whitesmoke' self.ax0 = plt.axes([x0, 0.15, width, height], facecolor=self.background_color) self.ax1 = plt.axes([x0, 0.1, width, height], facecolor=self.background_color) self.ax2 = plt.axes([x0, 0.05, width, height], facecolor=self.background_color) self.s0 = Slider(self.ax0, 'Alpha', valmin=0.1, valmax=500, valinit=dist.alpha, facecolor=self.active_color) self.s1 = Slider(self.ax1, 'Beta', valmin=0.2, valmax=25, valinit=dist.beta, facecolor=self.active_color) self.s2 = Slider(self.ax2, 'Gamma', valmin=0, valmax=500, valinit=dist.gamma, facecolor=self.active_color) plt.subplots_adjust(left=0.07, right=0.98, top=0.9, bottom=0.25, wspace=0.18, hspace=0.30) # initialise the radio button radio_ax = plt.axes([0.708, 0.25, 0.27, 0.28], facecolor=self.background_color) radio_ax.set_title('Distribution') self.radio = RadioButtons(radio_ax, ('Weibull', 'Gamma', 'Normal', 'Lognormal', 'Beta', 'Exponential', 'Loglogistic'), active=0, activecolor=self.active_color) # begin the interactive section distribution_explorer.__interactive(self, initial_run=True)
def test_Weibull_Distribution(): dist = Weibull_Distribution(alpha=5, beta=2, gamma=10) assert_allclose(dist.mean, 14.4311346272637895, rtol=rtol, atol=atol) assert_allclose(dist.standard_deviation, 2.316256875880522, rtol=rtol, atol=atol) assert_allclose(dist.variance, 5.365045915063796, rtol=rtol, atol=atol) assert_allclose(dist.skewness, 0.6311106578189344, rtol=rtol, atol=atol) assert_allclose(dist.kurtosis, 3.2450893006876456, rtol=rtol, atol=atol) assert dist.param_title_long == 'Weibull Distribution (α=5,β=2,γ=10)' assert_allclose(dist.quantile(0.2), 12.361903635387193, rtol=rtol, atol=atol) assert_allclose(dist.inverse_SF(q=0.7), 12.9861134604144417, rtol=rtol, atol=atol) assert_allclose(dist.mean_residual_life(20), 1.1316926249544481, rtol=rtol, atol=atol) xvals = [dist.gamma - 1, dist.quantile(0.001), dist.quantile(0.01), dist.quantile(0.1), dist.quantile(0.9), dist.quantile(0.99), dist.quantile(0.999)] assert_allclose(dist.PDF(xvals=xvals, show_plot=False), [0.0, 0.012639622357755485, 0.03969953988653618, 0.11685342455082046, 0.06069708517540586, 0.008583864105157392, 0.0010513043539513882], rtol=rtol, atol=atol) assert_allclose(dist.CDF(xvals=xvals, show_plot=False), [0.0, 0.001, 0.01, 0.1, 0.9, 0.99, 0.999], rtol=rtol, atol=atol) assert_allclose(dist.SF(xvals=xvals, show_plot=False), [1.0, 0.999, 0.99, 0.9, 0.1, 0.01, 0.001], rtol=rtol, atol=atol) assert_allclose(dist.HF(xvals=xvals, show_plot=False), [0.0, 0.012652274632387873, 0.04010054533993554, 0.12983713838980052, 0.6069708517540585, 0.8583864105157389, 1.0513043539513862], rtol=rtol, atol=atol) assert_allclose(dist.CHF(xvals=xvals, show_plot=False), [0.0, 0.0010005003335835354, 0.010050335853501409, 0.10536051565782631, 2.3025850929940455, 4.605170185988091, 6.907755278982135], rtol=rtol, atol=atol)