# How to create Custom base Log for PYMC3?

When attempting to create target y_hats for my pareto distribution, I came across this error:

TypeError Traceback (most recent call last)
in
32 base_a = m_prior / x1
33 number_a = 1 - y1
—> 34 alpha = math.log(number_a, base_a)
35

TypeError: must be real number, not TensorVariable

I soon realized that math and numpy are unable to take TensorVariables. However, when looking into pm.math.log. I realized that I am unable to create custom base logs as well.

So my question is, how does one create custom base logs to work in pymc3?

Code:

``````import pymc3 as pm
import math

np.random.seed(123)
``````

### Observed X

``````X = np.array([x_1, x_2, x_3])
Y = np.array([0.25, 0.5, 0.75])
``````

# model to identify ideal Pareto Priors

``````with pm.Model() as pareto_priors_model:
# Lower & Upper bound of unobserved variables
# m_prior = scale parameter or smallest value
# alpha = shape parameter = n/SUM(ln(x_i / m))
min_alpha = 0.1
max_alpha = 10
alpha_prior = pm.Uniform('alpha', min_alpha, max_alpha)
m_prior = pm.Uniform('m', 0.1, cost_20_perc)

x1 = X[0]
y1 = Y[0]

# y_hat = 1 - (m / X_i)^a

# y1 = 1 - ((m_prior / x1) ** alpha_prior)
# ((m_prior / x1) ** alpha_prior) = 1 - y1
number_m = 1 - y1
m = (number_m ** (1/ alpha_prior)) * x1

# y1 = 1 - ((m_prior / x1) ** alpha_prior)
# ((m_prior / x1) ** alpha_prior) = 1 - y1
base_a = m_prior / x1
number_a = 1 - y1
alpha = math.log(number_a, base_a)

q = pm.Pareto(name='q', alpha=alpha, m=m,
observed=X)
``````

Thank you for your time and help

Here’s a link on the change-of-base formula which you can use to express the log in a different base.

``````denominator = np.log(a)

def log_base_a(x):
return pm.math.log(x) / denominator``````
3 Likes

Thank you!