def huber(y_true, y_pred, d): if not isinstance(y_true, R.Tensor): y_true = R.Tensor(y_true) if not isinstance(y_pred, R.Tensor): y_pred = R.Tensor(y_pred) d = R.Scalar(d) x = R.sub(y_true, y_pred) if R.abs(x) <= d: return R.elemul(R.Scalar(d), R.elemul(x, x)) if R.abs(x) > d: return R.add(R.elemul(R.Scalar(d), R.mul(d, d)), R.elemul(d, R.sub(R.abs(x), d)))
def mean_absolute_error(y_true, y_pred): """ Mean Absolute Error """ if not isinstance(y_true, R.Tensor): y_true = R.Tensor(y_true) if not isinstance(y_pred, R.Tensor): y_pred = R.Tensor(y_pred) return R.mean(R.abs(R.sub(y_pred, y_true)))