Skip to main content

ClikaRT::ops::kl_div

function

kl_div()

Tensor kl_div(
    Tensor input,
    Tensor target,
    Reduction reduction = Reduction::Mean,
    bool log_target = false
)

Kullback–Leibler divergence loss.

input is given in LOG space; target is probabilities unless log_target is set (then both are logs):

i=yi(logyixi)\ell_i = y_i\,(\log y_i - x_i)

Parameters

  • input: log-probabilities.
  • target: probabilities (or log-probabilities under log_target); same shape as input.
  • reduction: None / Mean / Sum; default Mean.
  • log_target: target is already in log space; default false.

Returns: the divergence (0-D under Mean/Sum).

Throws

  • ClikaRT::Error: (INVALID_ARGUMENT) on an input/target shape mismatch.

Declared in ClikaRT/compute/ops.h, line 2972