I am trying to write a custom loss function for the very first time. My model generates a time series data and I want a loss function which would penalize errors later in the series more than the earlier ones. Something like where index of tensor is used to determine the penalty. The tensors have following structure.
y_true <tf.Tensor 'IteratorGetNext:1' shape=(None, 48, 1) dtype=float32>
y_pred <tf.Tensor 'ResNet34/dense_1/BiasAdd:0' shape=(None, 48, 1) dtype=float32>
What should I do to make the penalty a function of index?
def custom_loss_function(y_true, y_pred):
squared_difference = tf.square(y_true - y_pred) * 'sqrt(tensor_index)' <- Desired part
return tf.reduce_mean(squared_difference, axis=-1)