import tensorflow as tf


    pred1, pred2 = tf.split(horizon_pred, 2, axis=0)
    tgt1, tgt2 = tf.split(horizon_tgt, 2, axis=0)

    geq = tf.cast((tgt1 - tgt2) > 0, tf.bool)
    tgt_larg = tf.where(geq, tgt1, tgt2)
    tgt_small = tf.where(geq, tgt2, tgt1)
    pred_larg = tf.where(geq, pred1, pred2)
    pred_small = tf.where(geq, pred2, pred1)

    loss = tf.maximum(0.0, ((tgt_larg - tgt_small) - (pred_larg - pred_small)))
    loss = tf.reduce_mean(loss)
    return loss


# randrom horizon
def contra_traj_lossV3(pred, tgt, horizon=12):
    # Step-wise contrastive loss
    horizon_pred, horizon_tgt = horizon_sumV2(pred, tgt, horizon)

