MeanSquaredLogarithmicError

public class MeanSquaredLogarithmicError

Computes the mean squared logarithmic errors between labels and predictions.

loss = square(log(labels + 1.) - log(predictions + 1.))

Standalone usage:

    Operand<TFloat32> labels =
        tf.constant(new float[][] { {0.f, 1.f}, {0.f, 0.f} });
    Operand<TFloat32> predictions =
        tf.constant(new float[][] { {1.f, 1.f}, {1.f, 0.f} });
    MeanSquaredLogarithmicError msle = new MeanSquaredLogarithmicError(tf);
    Operand<TFloat32> result = msle.call(labels, predictions);
    // produces 0.240f
 

Calling with sample weight:

    Operand<TFloat32> sampleWeight = tf.constant(new float[] {0.7f, 0.3f});
    Operand<TFloat32> result = msle.call(labels, predictions, sampleWeight);
    // produces 0.120f
 

Using SUM reduction type:

    MeanSquaredLogarithmicError msle = new MeanSquaredLogarithmicError(tf, Reduction.SUM);
    Operand<TFloat32> result = msle.call(labels, predictions);
    // produces 0.480f
 

Using NONE reduction type:

    MeanSquaredLogarithmicError msle = new MeanSquaredLogarithmicError(tf, Reduction.NONE);
    Operand<TFloat32> result = msle.call(labels, predictions);
    // produces [0.240f, 0.240f]
 

Inherited Fields

Public Constructors

MeanSquaredLogarithmicError(Ops tf)
Creates a MeanSquaredError Loss using getSimpleName() as the loss name and a Loss Reduction of REDUCTION_DEFAULT
MeanSquaredLogarithmicError(Ops tf, Reduction reduction)
Creates a MeanSquaredError Loss using getSimpleName() as the loss name
MeanSquaredLogarithmicError(Ops tf, String name, Reduction reduction)
Creates a MeanSquaredError

Public Methods

<T extends TNumber> Operand<T>
call(Operand<? extends TNumber> labels, Operand<T> predictions, Operand<T> sampleWeights)
Generates an Operand that calculates the loss.

Inherited Methods

Public Constructors

public MeanSquaredLogarithmicError (Ops tf)

Creates a MeanSquaredError Loss using getSimpleName() as the loss name and a Loss Reduction of REDUCTION_DEFAULT

Parameters
tf the TensorFlow Ops

public MeanSquaredLogarithmicError (Ops tf, Reduction reduction)

Creates a MeanSquaredError Loss using getSimpleName() as the loss name

Parameters
tf the TensorFlow Ops
reduction Type of Reduction to apply to the loss.

public MeanSquaredLogarithmicError (Ops tf, String name, Reduction reduction)

Creates a MeanSquaredError

Parameters
tf the TensorFlow Ops
name the name of the loss
reduction Type of Reduction to apply to the loss.

Public Methods

public Operand<T> call (Operand<? extends TNumber> labels, Operand<T> predictions, Operand<T> sampleWeights)

Generates an Operand that calculates the loss.

Parameters
labels the truth values or labels
predictions the predictions
sampleWeights Optional sampleWeights acts as a coefficient for the loss. If a scalar is provided, then the loss is simply scaled by the given value. If SampleWeights is a tensor of size [batch_size], then the total loss for each sample of the batch is rescaled by the corresponding element in the SampleWeights vector. If the shape of SampleWeights is [batch_size, d0, .. dN-1] (or can be broadcast to this shape), then each loss element of predictions is scaled by the corresponding value of SampleWeights. (Note on dN-1: all loss functions reduce by 1 dimension, usually axis=-1.)
Returns
  • the loss