human
Complete this python program:
def _transferred_similarity_loss(reconstructions, source_images, weight=1.0, method='mse', max_diff=0.4, name='similarity'):
assistant
#Here is the Python program you requested.

    """Computes a loss encouraging similarity between source and transferred.
    Args:
    reconstructions: A `Tensor` of shape [batch_size, height, width, channels]
    source_images: A `Tensor` of shape [batch_size, height, width, channels].
    weight: Multiple similarity loss by this weight before returning
    method: One of:
    mpse = Mean Pairwise Squared Error
    mse = Mean Squared Error
    hinged_mse = Computes the mean squared error using squared differences
    greater than hparams.transferred_similarity_max_diff
    hinged_mae = Computes the mean absolute error using absolute
    differences greater than hparams.transferred_similarity_max_diff.
    max_diff: Maximum unpenalized difference for hinged losses
    name: Identifying name to use for creating summaries
    Returns:
    A `Tensor` representing the transferred similarity loss.
    Raises:
    ValueError: if `method` is not recognized.
    """
    if (weight == 0):
        return 0
    source_channels = source_images.shape.as_list()[(-1)]
    reconstruction_channels = reconstructions.shape.as_list()[(-1)]
    if ((source_channels == 1) and (reconstruction_channels != 1)):
        source_images = tf.tile(source_images, [1, 1, 1, reconstruction_channels])
    if ((reconstruction_channels == 1) and (source_channels != 1)):
        reconstructions = tf.tile(reconstructions, [1, 1, 1, source_channels])
    if (method == 'mpse'):
        reconstruction_similarity_loss_fn = tf.contrib.losses.mean_pairwise_squared_error
    elif (method == 'masked_mpse'):
        def masked_mpse(predictions, labels, weight):
            'Masked    mpse    assuming    we    have    a    depth    to    create    a    mask    from.'
            assert (labels.shape.as_list()[(-1)] == 4)
            mask = tf.to_float(tf.less(labels[:, :, :, 3:4], 0.99))
            mask = tf.tile(mask, [1, 1, 1, 4])
            predictions *= mask
            labels *= mask
            tf.image_summary('masked_pred', predictions)
            tf.image_summary('masked_label', labels)
            return tf.contrib.losses.mean_pairwise_squared_error(predictions, labels, weight)
        reconstruction_similarity_loss_fn = masked_mpse
    elif (method == 'mse'):
        reconstruction_similarity_loss_fn = tf.contrib.losses.mean_squared_error
    elif (method == 'hinged_mse'):
        def hinged_mse(predictions, labels, weight):
            diffs = tf.square((predictions - labels))
            diffs = tf.maximum(0.0, (diffs - max_diff))
            return (tf.reduce_mean(diffs) * weight)
        reconstruction_similarity_loss_fn = hinged_mse
    elif (method == 'hinged_mae'):
        def hinged_mae(predictions, labels, weight):
            diffs = tf.abs((predictions - labels))
            diffs = tf.maximum(0.0, (diffs - max_diff))
            return (tf.reduce_mean(diffs) * weight)
        reconstruction_similarity_loss_fn = hinged_mae
    else:
        raise ValueError(('Unknown    reconstruction...