예제 #1
0
def reproduce1(data_path, normalization=1, if_sqrt=False, ylabel='mse'):
    data = tb.load_data(data_path)
    value_range = data['value_range']
    if if_sqrt:
        metric = np.sqrt(data['metric'] / normalization)
    else:
        metric = data['metric'] / normalization
    x_label = data['x_label']
    plt.plot(value_range, metric)
    plt.xlabel(x_label)
    plt.ylabel(ylabel)
    plt.tight_layout()
    plt.grid()
예제 #2
0
def reproduce2(data_path, normalization=1, if_sqrt=False):

    data = tb.load_data(data_path)
    X, Y = np.meshgrid(data['c_range'], data['r_range'])
    plt.figure()
    if if_sqrt:
        CS = plt.contour(X, Y, np.sqrt(data['metric'] / normalization))
    else:
        CS = plt.contour(X, Y, data['metric'] / normalization)
    plt.clabel(CS, inline=1, fontsize=10)
    # plt.title('MSE contour map')
    plt.annotate(data['annotate_text'],
                 xy=data['annotate_xy'],
                 xytext=data['annotate_xytext'],
                 arrowprops=dict(facecolor='black', shrink=0.05), )
    plt.plot(data['annotate_xy'][0], data['annotate_xy'][1], 'bo')
    plt.xlabel(data['x_label'])
    plt.ylabel(data['y_label'])
    plt.tight_layout()
    plt.grid()
예제 #3
0
def identifiable_range(data_path,
                       threshold,
                       sparsity_weight=0,
                       sparsity_order=1):
    data = tb.load_data(data_path)
    x = data['value_range']
    y = data['metric']
    z = np.poly1d(np.polyfit(x, y, 4))
    x_dense = np.linspace(min(x), max(x), 511)
    true_value = x[np.argmin(y)]
    x_dense = np.sort(np.append(x_dense, true_value))
    y_dense = z(x_dense)

    true_value = x[np.argmin(y)]
    # sparsity = np.power(np.sum(np.power(np.abs(x_dense), sparsity_order)), 1 / sparsity_order)
    sparsity = np.power(np.abs(x_dense), sparsity_order)
    total_loss = y_dense + sparsity_weight * sparsity - sparsity_weight * abs(
        true_value)
    x_range = x_dense[total_loss <= threshold]
    if x_range.size > 0:
        positive_derivation = max(x_range) - true_value
        negative_derivation = min(x_range) - true_value
    else:
        x_range = x_dense[np.argmin(total_loss)]
        positive_derivation = x_range - true_value
        negative_derivation = x_range - true_value

    label = modify_index(data['x_label'])
    output = {
        'label': label,
        'true_value': true_value,
        'positive_derivation': positive_derivation,
        'negative_derivation': negative_derivation,
        'x_axis': x_dense,
        'total_loss': total_loss,
    }
    return output
예제 #4
0
        return 3
    elif count == 4:
        return 2
    elif count == 2:
        return 1
    else:
        print(file_name)
        raise(ValueError)


DATA_PATH = os.path.join(PROJECT_DIR, 'experiments', 'cost_landscape', 'data')
SAVE_PATH = os.path.join(PROJECT_DIR, 'experiments', 'cost_landscape', 'images')
file_names = os.listdir(DATA_PATH)

# recover du for reference
data = tb.load_data(os.path.join(DATA_PATH, file_names[0]))
du = data['du']
du.recover_data_unit()
norm_y = tb.mse(du.get('y'), np.zeros(du.get('y').shape))


# rMSE can be seen as the reciprocal of SNR
# SNR = l2(y)/l2(error/noise)
# target_SNR = 10
# noise_MSE = norm_y / np.square(target_SNR)

noise_MSE = 0.05
SNR = np.sqrt(norm_y / noise_MSE)

# find out files that corresponding to one free parameter
target_files = [name for name in file_names if categorize(name) == 1]