def test_pdf_nD(self, mock_show, tmp): fig_pdf = pdf(data, xdata=np.linspace(1, 12, 12), range_cbar=[0, 0.5], ticks_nbr=6, fname=os.path.join(tmp, 'pdf_nd.pdf')) reshow(fig_pdf) plt.plot([0, 10], [25, 25]) plt.show() plt.close()
def test_sobols_aggregated(self, mock_show, tmp): fun = Ishigami() indices = [fun.s_first, fun.s_total] fig = sensitivity_indices(indices, conf=0.05) fig = reshow(fig[0]) plt.plot([0, 10], [0.5, 0.5]) fig.show() sensitivity_indices(indices, plabels=['x1', 't', 'y'], fname=os.path.join(tmp, 'sobol.pdf')) sensitivity_indices(indices, polar=True, conf=[[0.2, 0.1, 0.1], [0.1, 0.1, 0.1]]) sensitivity_indices([indices[0]])
sample_scaled = np.concatenate([sample_scaled, sample_]) data = np.concatenate([data, fun(scaler_inverse_transform(sample_))]) sample.empty() sample += scaler_inverse_transform(sample_scaled) doe(sample, fname='final_doe.pdf') # Analysis print(f'\n########### N-samples ###########\n {sample.shape}') # Filtering in/out mask_threashold = data >= threashold mask_threashold = mask_threashold.flatten() inv_mask_threashold = np.logical_not(mask_threashold) sample_in = sample[mask_threashold] sample_out = sample[inv_mask_threashold] ratio = len(sample_in) / len(sample) * 100 print(f'{ratio:.2f}% of sampling is inside') ####### Visualization ####### fig = response_surface(corners, fun=fun, ticks_nbr=20, contours=[-20]) fig = reshow(fig) plt.scatter(sample_in[:, 0], sample_in[:, 1], c='r') plt.scatter(sample_out[:, 0], sample_out[:, 1], c='b') plt.show()
def test_doe_3D(self, ishigami_data, tmp): fig, ax = doe(ishigami_data.space, fname=os.path.join(tmp, 'DOE.pdf')) fig = reshow(fig) ax[0].plot([0, 6], [4, -3]) fig.savefig(os.path.join(tmp, 'DOE_change.pdf'))
def test_hdr_basic(self, hdr, tmp, seed): print('Data shape: ', data.shape) assert len(hdr.extra_quantiles) == 0 median_t = [ 24.27, 25.67, 25.98, 25.05, 23.76, 22.40, 21.31, 20.43, 20.20, 20.47, 21.17, 22.37 ] npt.assert_almost_equal(hdr.median, median_t, decimal=2) quant = np.vstack([hdr.outliers, hdr.hdr_90, hdr.hdr_50]) quant_t = np.vstack([[ 27.20, 28.16, 29.00, 28.94, 28.27, 27.24, 25.84, 24.01, 22.37, 22.24, 22.38, 23.26 ], [ 23.94, 26.16, 27.07, 26.50, 26.40, 25.92, 25.36, 24.70, 24.52, 24.67, 25.76, 27.02 ], [ 28.01, 28.83, 29.12, 28.23, 27.18, 25.33, 23.41, 22.11, 21.25, 21.56, 21.64, 23.01 ], [ 25.63, 26.99, 27.63, 27.11, 26.10, 24.65, 23.55, 22.50, 22.13, 22.51, 23.37, 24.54 ], [ 23.04, 24.58, 24.71, 23.41, 21.98, 20.74, 19.85, 19.09, 18.85, 19.04, 19.58, 20.80 ], [ 24.85, 26.15, 26.56, 25.78, 24.58, 23.20, 22.11, 21.17, 20.93, 21.25, 22.00, 23.23 ], [ 23.67, 25.14, 25.46, 24.28, 22.94, 21.62, 20.59, 19.75, 19.51, 19.73, 20.37, 21.54 ]]) npt.assert_almost_equal(quant, quant_t, decimal=0) figs, axs = hdr.plot(fname=os.path.join(tmp, 'hdr_boxplot.pdf'), labels=labels, x_common=np.linspace(1, 12, 12), xlabel='Month of the year (-)', flabel='Water surface temperature (C)') assert len(figs) == 3 assert len(axs) == 3 fig = reshow(figs[2]) plt.plot([0, 10], [25, 25]) axs[2].plot([0, 6], [4, -3]) fig.savefig(os.path.join(tmp, 'hdr_boxplot_change_sample.pdf')) fig = reshow(figs[1]) axs[1][0].plot([0, 6], [4, -3]) fig.savefig(os.path.join(tmp, 'hdr_boxplot_change_scatter.pdf'))