# How to make a tensorflow model compatible with pymc4?

**URL:** <https://discourse.pymc.io/t/how-to-make-a-tensorflow-model-compatible-with-pymc4/10403>\
**Category:** v5\
**Tags:** modeling\
**Created:** [September 15, 2022, 5:28am UTC](https://discourse.pymc.io/t/how-to-make-a-tensorflow-model-compatible-with-pymc4/10403 "2022-09-15T05:28:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Areum](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Areum](https://discourse.pymc.io/u/Areum)\
**Post date:** [September 15, 2022, 5:28am UTC](https://discourse.pymc.io/t/how-to-make-a-tensorflow-model-compatible-with-pymc4/10403/1 "2022-09-15T05:28:19Z")

</div>

I am trying to implement MCMC using PyMC4(pymc). The issue that I have is that I have to feed the pymc distributions `a, b, c, d, e, f` into a machine learning model (in TensorFlow). the TensorFlow model recognize the distributions. But the distributions is same. (not inference). Is there a way to make the TensorFlow model compatible with PYMC4?

```
with Model() as model:
# define Priors
a = Uniform('a', lower = 0, upper = 1 )
b = Uniform('b', lower = 0, upper = 1 )
c = Uniform('c', lower = 0, upper = 1 )
d = Uniform('d', lower = 0, upper = 1 )
e = Uniform('e', lower = 0, upper = 1 )
f = Uniform('f', lower = 0, upper = 1 )
sd = Uniform("sd", lower = 0, upper = 1 )

params = Deterministic("params", math.stack([a,b,c,d,e,f], axis=0) )
params = params.eval().reshape(1,-1)
aesara.dprint(params)

# Expected
yhat_1 = m1.predict(params)
yhat_2 = m2.predict(params)
yhat_3 = m3.predict(params)
yhat_4 = m4.predict(params)
yhat_5 = m5.predict(params)
yhat_6 = m6.predict(params)
yhat_7 = m7.predict(params)
yhat_8 = m8.predict(params)
yhat_9 = m9.predict(params)
yhat_10 = m10.predict(params)
yhat_11 = m11.predict(params)
yhat_12 = m12.predict(params)
yhatArr = np.append(yhatArr, np.array([yhat_1, yhat_2, yhat_3, yhat_4, yhat_5, yhat_6, yhat_7, yhat_8, yhat_9, yhat_10, yhat_11, yhat_12]))

pred = Deterministic("pred", math.stack(yhatArr).flatten())
print("pred ################################ START")
print(pred.eval())
print("pred ################################ END")

likelihood = Normal("likelihood", mu = pred, sigma = sd, observed = merge.iloc[3,2:]) # merge => 1*12
start = find_MAP()
print("trace ################################################## START")
trace = sample(3000, tune=3000, chains=1, start = start, progressbar=True)
print("trace ################################################## END")

```
