Trying to use a prior distribution inside a logarithm

I’m trying to model my data with an equation that has a logarithm:
y = A+B*log10(x-C)

x- is a predictor variable
A, B & C are parameters I want to predict with a posterior. The model works if I use a constant value for C, but once I replace it with a prior probability, it breaks down. (I even truncated the C prior distribution, below the minimum value of x so not to have a negative in the log10().)


curve_model = pm.Model()
with curve_model:
    # Define Prior Probabilities
    A = pm.Normal('A', mu=7.4, sd=2)
    B = pm.Normal('B', mu=-2, sd=2)
    C = pm.TruncatedNormal('C', mu=34, sd=2, upper=38)
    sd_y = pm.InverseGamma('t', mu=0.5, sd=0.25)
    mu_y = A+B*np.log10(x - C)
    # Write parameters for posterior
    post_fatigue = pm.Normal('post_fatigue', mu=mu_y , sd=sd_y, observed=y)


ValueError: length not known: Elemwise{sub,no_inplace} [id A] ''   
 |TensorConstant{[38.5   38..47 93.443]} [id B]
 |InplaceDimShuffle{x} [id C] ''   
   |ViewOp [id D] 'C'   
     |Elemwise{sub,no_inplace} [id E] ''   
       |TensorConstant{38} [id F]
       |Elemwise{exp,no_inplace} [id G] ''   
         |C_upperbound__ [id H]

I’m sure the problem has to do with getting the difference of a data set and a distribution. I just don’t know how to work around this.


This should work - what is the data type of x?

Hi :smile:

I’m reading ‘x’ from a csv file. the class is: <class ‘numpy.float64’>


Oh, And I should probably mention that I have been ignoring warnings that I can’t run theano:

WARNING (theano.configdefaults): g++ not available, if using conda: conda install m2w64-toolchain
C:\Users\Tazzy\Anaconda3\lib\site-packages\theano\ UserWarning: DeprecationWarning: there is no c++ compiler.This is deprecated and with Theano 0.11 a c++ compiler will be mandatory
warnings.warn(“DeprecationWarning: there is no c++ compiler.”
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.

I understood that theano makes my computer run more efficiently, Is this something that is required or optional?


We found a solution! We changed
mu_y = A+Bnp.log10(x - C)
mu_y = A+B
np.log10(x.to_list() - C)

And it worked :slight_smile: :grin:

Thanks for your input!

Glad you find a solution - I think the problem is likely that x is a pandas serie
Also, you should get the warning fix otherwise your pymc3 model will be quite slow - installing from Conda (Anaconda or Miniconda) is usually recommended