Exemplo n.º 1
0
def cmpt_Y_C(N):
    print('Computing system output...')

    # Sampling from the stratum using LHS251
    problem = {
        'nvars': 3,
        'names': ['x1', 'y1', 'z1'],
        'bounds': [[0, 1], [0, 1], [0, 1]],
        'dists': ['UNIFORM', 'UNIFORM', 'UNIFORM']
    }
    param_values = lhs(problem, N, seed=933090934)

    Y = np.zeros((Ma, Mb, N, Mc, N), dtype=np.float32)
    for i in range(Ma):
        for k in range(Mb):

            if (i == 0 and k == 0):
                theta_non_K_set = param_values[:, [0, 1]]
                for j in range(N):
                    for m in range(Mc):
                        if m == 0:
                            theta_K_set = param_values[:, 0]
                        else:
                            theta_K_set = param_values[:, 0]
                        values = np.hstack(
                            (np.repeat(theta_non_K_set[j, :].reshape(1, -1),
                                       N,
                                       axis=0), theta_K_set.reshape(-1, 1)))
                        Y[i, k, j, m, :] = evaluate(
                            values, delta,
                            np.array([alpha[0, i], alpha[1, k], alpha[2, m]]),
                            np.array([a[0, i], a[1, k], a[2, m]]))

            if (i == 0 and k == 1):
                theta_non_K_set = param_values[:, [0, 1]]
                for j in range(N):
                    for m in range(Mc):
                        if m == 0:
                            theta_K_set = param_values[:, 0]
                        else:
                            theta_K_set = param_values[:, 0]
                        values = np.hstack(
                            (np.repeat(theta_non_K_set[j, :].reshape(1, -1),
                                       N,
                                       axis=0), theta_K_set.reshape(-1, 1)))
                        Y[i, k, j, m, :] = evaluate(
                            values, delta,
                            np.array([alpha[0, i], alpha[1, k], alpha[2, m]]),
                            np.array([a[0, i], a[1, k], a[2, m]]))

            if (i == 1 and k == 0):
                theta_non_K_set = param_values[:, [0, 1]]
                for j in range(N):
                    for m in range(Mc):
                        if m == 0:
                            theta_K_set = param_values[:, 0]
                        else:
                            theta_K_set = param_values[:, 0]
                        values = np.hstack(
                            (np.repeat(theta_non_K_set[j, :].reshape(1, -1),
                                       N,
                                       axis=0), theta_K_set.reshape(-1, 1)))
                        Y[i, k, j, m, :] = evaluate(
                            values, delta,
                            np.array([alpha[0, i], alpha[1, k], alpha[2, m]]),
                            np.array([a[0, i], a[1, k], a[2, m]]))

            if (i == 1 and k == 1):
                theta_non_K_set = param_values[:, [0, 1]]
                for j in range(N):
                    for m in range(Mc):
                        if m == 0:
                            theta_K_set = param_values[:, 0]
                        else:
                            theta_K_set = param_values[:, 0]
                        values = np.hstack(
                            (np.repeat(theta_non_K_set[j, :].reshape(1, -1),
                                       N,
                                       axis=0), theta_K_set.reshape(-1, 1)))
                        Y[i, k, j, m, :] = evaluate(
                            values, delta,
                            np.array([alpha[0, i], alpha[1, k], alpha[2, m]]),
                            np.array([a[0, i], a[1, k], a[2, m]]))

    print('Numerical mean Y =', np.mean(Y))
    return Y
Exemplo n.º 2
0
max_points_per_bin = 10  # Estimated max number of points in each bin
max_bins_total = nbins_per_dim**2  # Estimated max number of bins
bin_results = pd.DataFrame({
    k: v
    for k, v in zip(problem['names'], [
        np.tile(np.linspace(0, 1, nbins_per_dim +
                            1), (problem['nvars'], 1))[i, :]
        for i in range(problem['nvars'])
    ])
})

# Generate parameters using SALib.sample.saltelli
# param_values = saltelli.sample(problem, N, calc_second_order=False, seed=2**30)[::5, :]

# Generate parameters using LHS
param_values = lhs(problem, N, seed=933090936)

np.save('Sobol_G_param_values_binning_100.npy', param_values)


# Compute the model outputs
def cmpt_Y():
    Y = np.zeros((Ma, Mb, Mc, N))
    for i in range(Ma):
        for k in range(Mb):
            for m in range(Mc):
                Y[i, k, m, :] = evaluate(
                    param_values, delta,
                    np.array([alpha[0, i], alpha[1, k], alpha[2, m]]),
                    np.array([a[0, i], a[1, k], a[2, m]]))
    return Y