Can PyMC3 compute the gradients of sequences/series?

I’ve been reviewing a 2017 paper by Google where they expand media mix modelling (MMM) into a Bayesian framework. Vanilla MMM is just OLS regression where X is marketing spend on M unique channels over a time period, t, and y is the number of new customers acquired in each t. Google expands this framework to account for both saturation (diminishing returns on spend) and lag (peak might not be realized immediately and decay rate must be inferred.)

Of note, the lag function (or geometric decay) is a series. Consider $100 spent on advertising on day 1, followed by $0 spent on days 2-10. Further, suppose the effect on potential customers peaks on day 3, then rapidly declines after.


  1. Bayesian Methods for Media Mix Modeling with Carryover and Shape Effects – Google Research (whitepaper)

  2. Bayesian Media Mix Modeling using PyMC3, for Fun and Profit | by Luca Fiaschi | HelloTech ( (dumbed down writeup)

  3. A Bayesian Approach to Media Mix Modeling by Michael Johns & Zhenyu Wang - YouTube (video reviewing the writeup)

In link 3, the YT video, the authors write a geometric decay function in TensorFlow, however, they maintain that they are using PyMC3. As a PyMC user, I know that TF probability was used in PyMC4 before the project was scrapped; PyMC3 continues to use Theano as its workhorse. In other words, I may need to translate this function into Theano and hope that the gradient can be automatically computed.

In the event that PyMC3 cannot compute this gradient automatically, I would need to manually supply gradient information- but I have no idea how to do this. My calc 2 knowledge is atrophied at best and I don’t remember how the derivative of sequences and/or series are computed.

Could anyone point me in the right direction regarding some reading materials? (And any advice in general?)

Lastly, if anyone wants to see what these functions look like in practice, I’ve put together a Colab notebook that explores how parameter values effect curvature.

Hopefully someone can answer better from the pure pymc3 side of things, I’m not personally aware on that end, but theano does have a gradient library, see documentation here and code here on the pymc3-dev fork of theano.