maeLossGPU function

GPUTensor<Scalar> maeLossGPU(
  1. GPUTensor<Vector> preds,
  2. GPUTensor<Vector> targets,
  3. CommandBuffer tape
)

Calculates the Mean Absolute Error (MAE) loss between predictions and targets. Computes the absolute differences between the preds and targets vectors, sums the errors, and divides by the total number of elements to yield a single average error scalar. The operations are appended to tape for execution.

Implementation

GPUTensor<Scalar> maeLossGPU(
    GPUTensor<Vector> preds, GPUTensor<Vector> targets, CommandBuffer tape) {
  GPUTensor<Vector> diff = subtractGPU<Vector>(preds, targets, tape);
  GPUTensor<Vector> absoluteDiff = absGPU<Vector>(diff, tape);
  GPUTensor<Scalar> totalError = sumGPU(absoluteDiff, tape);
  GPUTensor<Scalar> nScalar = GPUTensor<Scalar>(preds.shape[0].toDouble());
  GPUTensor<Scalar> out = divideGPU<Scalar>(totalError, nScalar, tape);
  out.subMap["diff"] = diff;
  out.subMap["absoluteDiff"] = absoluteDiff;
  out.subMap["totalError"] = totalError;
  out.subMap["nScalar"] = nScalar;
  return out;
}