mseMatrixGPU function

GPUTensor<Scalar> mseMatrixGPU(
  1. GPUTensor<Matrix> predictions,
  2. GPUTensor<Matrix> targets,
  3. CommandBuffer tape, {
  4. GPUTensor<Scalar>? outTensor,
})

Appends commands for calculating the mean square error over between the matrices predictions and targets to tape.

Implementation

GPUTensor<Scalar> mseMatrixGPU(GPUTensor<Matrix> predictions,
    GPUTensor<Matrix> targets, CommandBuffer tape,
    {GPUTensor<Scalar>? outTensor}) {
  int numRows = predictions.shape[0];
  int numCols = predictions.shape[1];

  GPUTensor<Scalar> out = outTensor ?? GPUTensor<Scalar>(0.0);

  tape.putInt(OP_MSE_LOSS_FORWARD);
  tape.putString(predictions.id);
  tape.putString(targets.id);
  tape.putString(out.id);

  out.creator = GPUNode(
    [predictions, targets],
    (CommandBuffer bTape) {
      bTape.putInt(OP_MSE_LOSS_BACKWARD);
      bTape.putString(out.gradId); // 1. gradOut (Der Skalar 1.0)
      bTape.putString(predictions.id); // 2. Prediction
      bTape.putString(targets.id); // 3. Target
      bTape.putString(predictions.gradId); // 4. gradIn (Ziel für das Update)
    },
    opName: 'mse_matrixGPU',
    cost: 3 * numRows * numCols,
  );

  return out;
}