import tensorflow as tf

constraint_tf = {}
for key in constraint.keys():
    low = constraint[key][0]
    high = constraint[key][1]
    constraint_tf[key] = (tf.constant(low, dtype=tf.float64),
                          tf.constant(high, dtype=tf.float64))


print("N.B.: using direct data entry")
likelihood = sum_pdf(data, nsig, sigmean, sigwidth, nbkg, m0, argpar, constraint_tf['mes'][0], constraint_tf['mes'][1])
nll = tf.neg(tf.reduce_sum(tf.log(likelihood)), name="nll")


variables = tf.all_variables()

grads = tf.gradients(nll, variables)

# ### build constraint inequalities
inequalities = []
for key, (lower, upper) in constraint_tf.iteritems():
    if key != 'mes':
        inequalities.append(vdict[key] - lower)
        inequalities.append(upper - vdict[key])

# ### build bounds instead of inequalities (only for L-BFGS-B, TNC and SLSQP)
# N.B.: order important! Also supply variables to be sure the orders match.
