# this file collects several utility functions import numpy as np from keras import backend as K def naive_percent_loss(y_true, y_pred): """TODO: Docstring for . # Sums up the relative errors at all wavelength points of a spectrum # in comparison to a target spectrum : y_true -- target spectrum : y_pred -- predicted spectrum Note that the user needs to ensure we are comparing similiar spectra """ y_err = np.abs(y_true - y_pred) / y_true y_err_f = K.flatten(y_err) return K.sum(y_err_f) def calc_mre(y_true, y_pred): """TODO: Docstring for . # Gives the mean relative errors in percentage terms comparing two sets of spectra """ y_err = np.abs(y_true - y_pred) / y_true y_err = 100*np.abs(y_true - y_pred)/y_true return np.mean(y_err) #legacy function to compare two size vectors, not really needed anymore # def size_percent_loss(y_true, y_pred): # y_true_a = 0.5*y_true*(size_max - size_min) + size_av # y_pred_a = 0.5*y_pred*(size_max - size_min) + size_av # y_err = np.abs(y_true_a - y_pred_a)/y_true_a # y_err_f = K.flatten(y_err) # return K.sum(y_err_f)