import tensorflow as tf

    last = activation[L-1]
    labels= tf.transpose(Y)

    if last == 'sigmoid' or last == 'softmax': #use cross entropy loss function
          logits= tf.transpose(betan*zn[1])
          cost  = tf.reduce_mean(tf.losses.sigmoid_cross_entropy(logits = logits, multi_class_labels=labels))

    elif last == 'esp' or last == 'relu': #use minimum squared error (L2 loss)
          out = tf.transpose(zn[0])
          cost = tf.reduce_mean(tf.squared_difference(out, labels))/2

    return cost

#------------Hessian-------------------

def flatten(tensor):
