# TransformedRV object is not Callable Error - Non-Linear Regression

G’day Team
I am 3wks old in Python. Trying to implement bayes with pymc3, but i run into error and would appreciate any help i can get…

### Prior

$$p(\sigma_{ci}) = \frac{1}{(\sigma_{ci ; upper} - \sigma_{ci ;lower})}$$

$$p(m_i) = \frac{1}{(m_{i ; upper} - m_{i ; lower})}$$

$$p(\sigma) = \frac{1}{100stdev(\sigma_{1 ; data}) - 0.01stdev(\sigma_{1; data})}$$

$$p(\nu) = \frac{1}{29}e^{-\frac{1}{29}(\nu-1)}$$

$$p(\sigma_{ci},m_i,\sigma,\nu) = p(\sigma_{ci})p(m_i)p(\sigma)p(\nu)$$

### Likelihood

$$If >\sigma_{3;data};>0:\ \sigma_{1;model};=;\sigma_{3;data} + \sigma_{ci}\left(m_i\frac{\sigma_{3;data}}{\sigma_{ci}} + 1\right)^{0.5 }$$

$$error = \sigma_{1 ; data} - \sigma_{1 ; model}$$

$$If >\sigma_{3;data};<0:\ \sigma_{3;model};=;\frac{\sigma_{ci}}{2}\left(m_i - \sqrt{{m_i}^2 + 4}\right)$$

$$error = \sigma_{3 ; data} - \sigma_{3 ; model}$$

$$p(data|\sigma_{ci},m_i,\sigma,\nu) = \prod_{j=1}^{n} \frac{\Gamma(\frac{\nu + 1}{2})}{\Gamma(\frac{\nu}{2})\sqrt{\pi\nu\sigma}} \left[1+\frac{1}{\nu}\left(\frac{error_j}{\sigma}\right)^2 \right]^{-\frac{\nu+1}{2}}$$

my code implementation…

with Model() as HB_model:

# Priors
σ_ci = Uniform('σ_ci', 0.2,120)
m_i = Uniform('m_i', 1,50)
σ = Uniform('σ', 0.22, 2200)
ν = Exponential('ν_minus_one', 1/29.) + 1

#Likelihood

for σ1_data in σ1:
for σ3_data in σ3:
if σ3_data > 0:
σ1_model = σ3_data + σ_ci(m_i(σ3_data/σ_ci)+1)**0.5
error = σ1_data - σ1_model
elif σ3_data < 0:
σ3_model = (σ_ci/2)(m_i-(m_i**2+4)**0.5)
error = σ3_data - σ3_model

HB_like = StudentT('HB_like', nu=ν, sd=σ, mu=error, observed = 'esatxl')
trace_HB = sample(5000, random_seed=RANDOM_SEED)


TypeError                                 Traceback (most recent call last)
<ipython-input-34-0d41d0e912f5> in <module>()
12         for σ3_data in σ3:
13             if σ3_data > 0:
---> 14                 σ1_model = σ3_data + σ_ci(m_i(σ3_data/σ_ci)+1)**0.5
15                 error = σ1_data - σ1_model
16             elif σ3_data < 0:

TypeError: 'TransformedRV' object is not callable


As the error message read, RVs are not callable. From the description of your model, it seems it should be a multiplication? If that’s the case, you should do something like m_i*(σ3_data/σ_ci) instead of m_i(σ3_data/σ_ci)

Thanks. I don’t think it is the multiplication - same error occurs. I am not sure if it has to do with passing two columns sig1 and sig3 to the likelihood in the form of the ‘error’?

Also, you can not pass string as observed

Emcee_to_PyMC3.py (17.7 KB)

Hi Junpeng

continuing with our previous discussion, please find attached a file containing my struggle to implement an emcee code in pymc3. You have already assisted me on the pymc3 coding part…but i don’t seem to be able to replicate the results.

Any assistance with this will be greatly appreciated
Liwi

You really should not be using emcee. NUTS is your friend and if you dong have gradient, try SMC

If you insist to try emcee, here is some previous effort: https://github.com/pymc-devs/pymc3/pull/2253

agreed, if you check the code, now trying to replicate in pymc3. at your convenience please have a look, at the moment not getting similar results