Class: Gsplat::Training::ImageFitter::MeanSquaredError

Inherits:
Autograd::Function show all
Defined in:
lib/gsplat/training/image_fitter.rb

Overview

Scalar image MSE used to drive the example's reverse pass.

Class Method Summary collapse

Methods inherited from Autograd::Function

apply

Class Method Details

.backward(context, grad_output) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the rendered-image VJP; targets are constants.



23
24
25
26
# File 'lib/gsplat/training/image_fitter.rb', line 23

def backward(context, grad_output)
  difference, count = context.saved_values
  [(2.0 * difference / count) * grad_output.to_f, nil]
end

.forward(context, rendered, target) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Evaluates scalar mean squared error.



15
16
17
18
19
# File 'lib/gsplat/training/image_fitter.rb', line 15

def forward(context, rendered, target)
  difference = rendered - target
  context.save(difference, rendered.size)
  rendered.class.cast((difference**2).sum / rendered.size)
end