def relative_difference(prediction, label): dE = 30 / len(prediction) #how many eV's one dE is numerator = np.sum(dE * np.power((label - prediction), 2)) denominator = np.sum(dE * label) return 1 - np.sqrt(numerator) / denominator validation_loader = load_data.load_experiment_data('spectra.npz', 'validation') model = spectroscopy_cnn_model.create_network(300) model.load_state_dict(torch.load('results/model_exp17.pth', map_location='cpu')) model.eval() rmse_accuracy = helper_functions.get_model_error(validation_loader, model, True) best_prediction = np.argmin(rmse_accuracy) worst_prediction = np.argmax(rmse_accuracy) median_prediction = rmse_accuracy.index( np.percentile(rmse_accuracy, 50, interpolation='nearest')) index = 1836 index2 = 5670 error = relative_difference(spectra_predicted[index], energies_val[index]) error2 = relative_difference(spectra_predicted[index2], energies_val[index2]) print("LOSS", error) print("LOSS2", error2) print("Best index = {}\nWorst index = {}\nMedian index = {}".format(
import torch import pkg_resources pkg_resources.require("torch==1.0.0") import load_data import helper_functions import spectroscopy_cnn_model validation_loader = load_data.load_experiment_data('spectra_normalized.npz', 'validation') model = spectroscopy_cnn_model.create_network(300) model.load_state_dict(torch.load('results/model_exp17.pth', map_location='cpu')) model.eval() rmse_accuracy, rmse_rmse, rmse_mae, rmse_r2 = helper_functions.get_model_error( validation_loader, model, normalized=True) model.load_state_dict(torch.load('results/model_exp41.pth', map_location='cpu')) model.eval() smooth_accuracy, smooth_rmse, smooth_mae, smooth_r2 = helper_functions.get_model_error( validation_loader, model, normalized=True) model.load_state_dict(torch.load('results/model_exp42.pth', map_location='cpu')) model.eval() logcosh_accuracy, logcosh_rmse, logcosh_mae, logcosh_r2 = helper_functions.get_model_error( validation_loader, model, normalized=True) model.load_state_dict(torch.load('results/model_exp39.pth', map_location='cpu'))