Custom Likelihood - sum of weighted exponentials with transformed data


I am working on a research problem where I have a random variable R that can take values in range R+. I have a sequence of (already known) values w1,w2,…wT. The size of this sequence may increase over time i.e., we may obtain w_{T+1}. The likelihood of a single observation of the random variable R is given as:

P(r | w1, … wT, lambda) = \sum{t=1}_{T} [phi(w1,…wt) * lambda * e^{-lambda (r - t)}]

The above likelihood consists of two parts. The first phi(w1,…wt) is a function that takes in the sequence up to the current item t and returns a scalar positive value. The second is an exponential distribution that takes produces f(r-t | lambda), where r -t is the data minus the current t value. For simplicity, we assume that the lambda parameter is shared across the exponentials. In the future, we may want this to be distinct for each exponential.

Is there a way to implement this above function as a custom likelihood in pymc such that the posterior distribution of lambda may be generated? The goal is to plot the P(r|w1,…wT, lambda) for all T values.

Any help is greatly appreciated.

Thank you!

Is it possible to model \phi(w_1,w_2,...,w_t) for each t with a hyperprior of some sorts that depends on priors of w_1,…,w_n and sums upto 1 (after multiplying with lambda)? If so then I assume this could be achieved via

If however not and you need to define your custom distribution, then there is the CustomDist class which you may try to use. An example of it can be found here (which uses the approach of defining the logp for the custom dist which might be what you need here):

as well as other examples here