Beispiel #1
0
def PlotPossibleGeoSpace(figname, Xpred_dir, compare_original=False):
    """
    Function to plot the possible geometry space for a model evaluation result.
    It reads from Xpred_dir folder and finds the Xpred result insdie and plot that result
    :params figname: The name of the figure to save
    :params Xpred_dir: The directory to look for Xpred file which is the source of plotting
    :output A plot containing 4 subplots showing the 8 geomoetry dimensions
    """
    Xpredfile = os.path.join(Xpred_dir,
                             get_pred_truth_file.get_Xpred(Xpred_dir))
    Xpred = pd.read_csv(Xpredfile, header=None, delimiter=' ').values

    Xtruthfile = os.path.join(Xpred_dir,
                              get_pred_truth_file.get_Xtruth(Xpred_dir))
    Xtruth = pd.read_csv(Xtruthfile, header=None, delimiter=' ').values

    f = plt.figure()
    ax0 = plt.gca()
    print(np.shape(Xpred))
    #print(Xpred)
    plt.title(figname)
    for i in range(4):
        ax = plt.subplot(2, 2, i + 1)
        ax.scatter(Xpred[:, i], Xpred[:, i + 4], label="Xpred")
        if (compare_original):
            ax.scatter(Xtruth[:, i], Xtruth[:, i + 4], label="Xtruth")
        plt.xlabel('h{}'.format(i))
        plt.ylabel('r{}'.format(i))
        plt.xlim(-1, 1)
        plt.ylim(-1, 1)
        plt.legend()
    #plt.title(figname)
    f.savefig(figname + '.png')
Beispiel #2
0
def PlotPairwiseGeometry(figname, Xpred_dir):
    """
    Function to plot the pair-wise scattering plot of the geometery file to show
    the correlation between the geometry that the network learns
    """

    Xpredfile = get_pred_truth_file.get_Xpred(Xpred_dir)
    Xpred = pd.read_csv(Xpredfile, header=None, delimiter=' ')
    f = plt.figure()
    axes = pd.plotting.scatter_matrix(Xpred, alpha=0.2)
    #plt.tight_layout()
    plt.title("Pair-wise scattering of Geometery predictions")
    plt.savefig(figname)
Beispiel #3
0
def after_Tandem_pred():
    """
    This function handles the rest of the evaluation after the Ypred has been generated by the Tandem model (forward model)
    """
    data_dir = 'data'
    Ypred_file = get_pred_truth_file.get_Ypred(data_dir)
    Xpred_file = get_pred_truth_file.get_Xpred(data_dir)
    Ytruth_file = get_pred_truth_file.get_Ytruth(data_dir)
    Ypred = np.loadtxt(Ypred_file, delimiter=' ')
    Ytruth = np.loadtxt(Ytruth_file, delimiter=' ')
    Xpred = np.loadtxt(Xpred_file, delimiter=' ')

    l_Ypred = len(Ypred)
    l_Ytruth = len(Ytruth)
    k = l_Ypred / l_Ytruth
    print("l_Ypred", l_Ypred)
    print("l_Ytruth", l_Ytruth)
    print("k", k)
    assert k - int(
        k) < 0.001, "Check you length, the divide result k is not an int!!"
    print(
        'For each data point in your truth file, the VAE generated {} data points'
        .format(k))
    k = int(k)
    #best_index_list = np.zeros([1,l_Ytruth])
    Xpred_new = np.zeros([l_Ytruth, 8])
    Ypred_new = np.zeros(np.shape(Ytruth))
    for i in range(l_Ytruth):
        diff_mat = Ypred[i * k:(i + 1) * k, :] - Ytruth[i, :]
        distance_mat = np.linalg.norm(diff_mat, axis=1)
        best_index = np.argmax(distance_mat)
        #best_index_list[i] = best_index
        Xpred_new[i, :] = Xpred[i * k + best_index, :]
        Ypred_new[i, :] = Ypred[i * k + best_index, :]
    with open(Xpred_file, 'w') as f1:
        np.savetxt(f1, Xpred_new, fmt='%.3f')
    with open(Ypred_file, 'w') as f2:
        np.savetxt(f2, Ypred_new, fmt='%.3f')

    mae, mse = compare_truth_pred(Ypred_file, Ytruth_file)

    plt.figure(figsize=(12, 6))
    plt.hist(mse, bins=100)
    plt.xlabel('Mean Squared Error')
    plt.ylabel('cnt')
    plt.suptitle('VAE (Avg MSE={:.4e})'.format(np.mean(mse)))
    plt.savefig(os.path.join(os.path.abspath(''), 'data', 'VAE.png'))
    plt.show()
    print('VAE (Avg MSE={:.4e})'.format(np.mean(mse)))
Beispiel #4
0
def PlotPossibleGeoSpace(figname,
                         Xpred_dir,
                         compare_original=False,
                         calculate_diversity=None):
    """
    Function to plot the possible geometry space for a model evaluation result.
    It reads from Xpred_dir folder and finds the Xpred result insdie and plot that result
    :params figname: The name of the figure to save
    :params Xpred_dir: The directory to look for Xpred file which is the source of plotting
    :output A plot containing 4 subplots showing the 8 geomoetry dimensions
    """
    Xpredfile = get_pred_truth_file.get_Xpred(Xpred_dir)
    Xpred = pd.read_csv(Xpredfile, header=None, delimiter=' ').values

    Xtruthfile = get_pred_truth_file.get_Xtruth(Xpred_dir)
    Xtruth = pd.read_csv(Xtruthfile, header=None, delimiter=' ').values

    f = plt.figure()
    ax0 = plt.gca()
    print(np.shape(Xpred))
    #print(Xpred)
    #plt.title(figname)
    if (calculate_diversity == 'MST'):
        diversity_Xpred, diversity_Xtruth = calculate_MST(Xpred, Xtruth)
    elif (calculate_diversity == 'AREA'):
        diversity_Xpred, diversity_Xtruth = calculate_AREA(Xpred, Xtruth)

    for i in range(4):
        ax = plt.subplot(2, 2, i + 1)
        ax.scatter(Xpred[:, i], Xpred[:, i + 4], s=3, label="Xpred")
        if (compare_original):
            ax.scatter(Xtruth[:, i], Xtruth[:, i + 4], s=3, label="Xtruth")
        plt.xlabel('h{}'.format(i))
        plt.ylabel('r{}'.format(i))
        plt.xlim(-1, 1)
        plt.ylim(-1, 1)
        plt.legend()
    if (calculate_diversity != None):
        plt.text(-4,
                 3.5,
                 'Div_Xpred = {}, Div_Xtruth = {}, under criteria {}'.format(
                     diversity_Xpred, diversity_Xtruth, calculate_diversity),
                 zorder=1)
    plt.suptitle(figname)
    f.savefig(figname + '.png')