%pylab inline
Populating the interactive namespace from numpy and matplotlib
import pyhf
from pyhf import Model
from pyhf.simplemodels import hepdata_like
import tensorflow as tf
source = {
"binning": [2,-0.5,1.5],
"bindata": {
"data": [120.0, 180.0],
"bkg": [100.0, 150.0],
"bkgerr": [10.0, 10.0],
"sig": [30.0, 95.0]
}
}
pdf = hepdata_like(source['bindata']['sig'], source['bindata']['bkg'], source['bindata']['bkgerr'])
data = source['bindata']['data'] + pdf.config.auxdata
init_pars = pdf.config.suggested_init()
par_bounds = pdf.config.suggested_bounds()
print '---\nas tensorflow\n-----'
import tensorflow as tf
pyhf.tensorlib = pyhf.tensorflow_backend()
v = pdf.logpdf(init_pars,data)
pyhf.tensorlib.session = tf.Session()
print type(v),pyhf.tensorlib.tolist(v)
import os
tf.summary.FileWriter(os.getcwd(), pyhf.tensorlib.session.graph)
--- as tensorflow ----- <class 'tensorflow.python.framework.ops.Tensor'> [-22.877851486206055]
<tensorflow.python.summary.writer.writer.FileWriter at 0x11fe1af90>
x = tf.Variable([1.])
y = tf.Variable([2.])
z = x**2*y + y**3*x
hessian = tf.hessians(z,[x,y])
sess = tf.Session()
sess.run(tf.global_variables_initializer())
sess.run(hessian)
[array([[4.]], dtype=float32), array([[12.]], dtype=float32)]
x = tf.cast([1.], tf.float64)
y = tf.cast([2.], tf.float64)
z = x**2*y + y**3*x
hessian = tf.hessians(z,[x,y])
sess = tf.Session()
sess.run(hessian)
[array([[4.]]), array([[12.]])]