luke14free / pm-prophet

GAM timeseries modeling with auto-changepoint detection. Inspired by Facebook Prophet and implemented in PyMC3
325 stars 42 forks source link

Heteroskedasticity #33

Open arainboldt opened 3 years ago

arainboldt commented 3 years ago

Hi,

Great package. I was considering attempting something similar, but was very grateful to find your implementation!

I'm modelling data that is generally periodic and trending but is heteroskedastic and rather than transform the heteroskedasticity out of the data as is usually recommended, I would like to model it specifically. My sense is that the GAM approach used by Prophet could model the data very well if I could model the varying variance explicitly.

My initial desire is to try to model the variance itself, as opposed to the original timeseries, and see if I can identify the points where the variance changes.

To that end, I'm trying to better understand how the truncated dirichlet process used herein and copied below accomplishes this. In particular, I don't understand the use of tt.extra_ops.cumprod(1 - beta)[:-1] is this the stickbreaking function?

Also, how does the switch work exactly at tt.switch(tt.gt(x, 1e-4), x, 0)

                    k = self.n_changepoints
                    alpha = pm.Gamma("alpha_%s" % self.name, 1.0, 1.0)
                    beta = pm.Beta("beta_%s" % self.name, 1.0, alpha, shape=k)
                    w1 = pm.Deterministic(
                        "w1_%s" % self.name,
                        tt.concatenate([[1], tt.extra_ops.cumprod(1 - beta)[:-1]])
                        * beta,
                    )
                    w, _ = theano.map(
                        fn=lambda x: tt.switch(tt.gt(x, 1e-4), x, 0), sequences=[w1]
                    )
                    self.w = pm.Deterministic("w_%s" % self.name, w)

can I access the probabilities for a given time-step being a changepoint after sampling?

Thanks in advance