def mae(reference, predictions, idx=None, n=1):
'''
Mean absolute error (MAE) for (p x n) raster arrays, where p is the number
of bands and n is the number of pixels. Arguments:
reference Raster array of reference ("truth" or measured) data
predictions Raster array of predictions
idx Optional array of indices at which to sample the arrays
n A normalizing constant for residuals; e.g., the number
of endmembers when calculating RMSE for modeled reflectance
'''
if idx is None:
r = reference.shape[1]
residuals = reference - predictions
else:
r = len(idx)
residuals = reference[:, idx] - predictions[:, idx]
# Divide the MSE by the number of bands before taking the root
return np.apply_along_axis(lambda x: np.divide(np.abs(x).sum(), n), 0,
residuals)
评论列表
文章目录