Esempio n. 1
0
def mc_sensitivity_linear(Ns, jpdf, w, sample_method='R'):

    Nrv = len(jpdf)

    # 1. Generate sample matrices
    A, B, C = generate_sample_matrices_mc(Ns, Nrv, jpdf, sample_method)

    # 2. Evaluate the model
    Y_A, Y_B, Y_C = evaluate_linear_model(A, B, C, w)

    # 3. Approximate the sensitivity indices
    S, ST = calculate_sensitivity_indices_mc(Y_A, Y_B, Y_C)

    return A, B, C, Y_A, Y_B, Y_C, S, ST
Esempio n. 2
0
def monte_carlo_sens_nonlin(Ns, jpdf, sample_method='R'):

    N_prms = len(jpdf)

    # 1. Generate sample matrices
    XA, XB, XC = generate_sample_matrices_mc(Ns, N_prms, jpdf, sample_method)

    # 2. Evaluate the model
    Y_A, Y_B, Y_C = evaluate_non_additive_linear_model(XA, XB, XC)

    # 3. Approximate the sensitivity indices
    S, ST = calculate_sensitivity_indices_mc(Y_A, Y_B, Y_C)

    return XA, XB, XC, Y_A, Y_B, Y_C, S, ST
Esempio n. 3
0
    # calculate statistics
    plotMeanConfidenceAlpha = 5.
    Y = np.hstack([Y_A, Y_B])
    expected_value = np.mean(Y, axis=1)
    variance = np.var(Y, axis=1)
    std = np.sqrt(np.var(Y, axis=1))
    prediction_interval = np.percentile(
        Y, [plotMeanConfidenceAlpha / 2., 100. - plotMeanConfidenceAlpha / 2.],
        axis=1)

    print('{:2.5f} | {:2.5f} : {}'.format(
        np.mean(expected_value) * unit_m2_cm2,
        np.mean(std) * unit_m2_cm2, name))

    # 3. Approximate the sensitivity indices
    S, ST = calculate_sensitivity_indices_mc(Y_A, Y_B, Y_C)

    ## Plots
    plt.figure('mean')
    plt.plot(pressure_range * unit_pa_mmhg,
             expected_value * unit_m2_cm2,
             label=name,
             color=color)
    plt.fill_between(pressure_range * unit_pa_mmhg,
                     prediction_interval[0] * unit_m2_cm2,
                     prediction_interval[1] * unit_m2_cm2,
                     alpha=0.3,
                     color=color)
    plt.xlabel('Pressure [mmHg]')
    plt.ylabel('Area [cm2]')
    plt.legend()
Esempio n. 4
0
        Y, [plotMeanConfidenceAlpha / 2., 100. - plotMeanConfidenceAlpha / 2.],
        axis=1)

    print('{:2.5f} | {:2.5f} : {}'.format(
        np.mean(expected_value) * unit_m2_cm2,
        np.mean(std) * unit_m2_cm2, name))

    # 3. Approximate the sensitivity indices
    # Better to centralize data before calculating sensitivities
    expected_value_col = expected_value.copy()
    expected_value_col.shape = (expected_value.shape[0], 1)
    Y_Ac = Y_A - expected_value_col
    Y_Bc = Y_B - expected_value_col
    Y_Cc = Y_C.transpose() - expected_value
    Y_Cc = Y_Cc.transpose()
    S, ST = calculate_sensitivity_indices_mc(Y_A, Y_B, Y_C)
    Sc, STc = calculate_sensitivity_indices_mc(Y_Ac, Y_Bc, Y_Cc)

    ## Plots
    fig = fig_mean
    ax_mean = ax_mean
    ax_mean.plot(pressure_range * unit_pa_mmhg,
                 expected_value * unit_m2_cm2,
                 label=name,
                 color=color)
    ax_mean.fill_between(pressure_range * unit_pa_mmhg,
                         prediction_interval[0] * unit_m2_cm2,
                         prediction_interval[1] * unit_m2_cm2,
                         alpha=0.3,
                         color=color)
    ax_mean.set_xlabel('Pressure [mmHg]')