Imposing coefficient bounds on a SARIMAX model

234 views
Skip to first unread message

Ani Sengupta

unread,
Nov 16, 2020, 9:16:13 AM11/16/20
to pystatsmodels
Hi all

Hope that you are all well.

I am currently developing an automodeller tool which can create ARIMA models based on some input data, parameters and transformations.

It does a series of optimizations which evaluates exogenous variable combinations with the lowest AIC as well as trying to obtain positive coefficients. I am try to make it impose coefficient bounds (upper and lower) in order to return a model with sensible coefficients.

Is there any way I can do this? In from sklearn.linear_modelLinearRegression you can impose bounds like this but not sure you can do that in our case.

Any help on this would be greatly appreciated, thanks
Aniruddha

Chad Fulton

unread,
Nov 17, 2020, 7:27:48 AM11/17/20
to Statsmodels Mailing List
Hello,

Nice to hear that SARIMAX might be useful for your tool.

Unfortunately, there is no built-in way to impose bounds on the estimated coefficients for exogenous variables, although it would be possible to do this by creating a subclass of SARIMAX.

All bounds on parameters in SARIMAX models are enforced via parameter transformations (see, for example, the "transform / untransform" section of https://www.statsmodels.org/dev/examples/notebooks/generated/statespace_local_linear_trend.html).  You can use similar transformations to impose arbitrary bounds on a given parameter. So in your subclass, you could extend the `transform_params` and `untransform_params` methods to do that.

Best,
Chad


--
You received this message because you are subscribed to the Google Groups "pystatsmodels" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pystatsmodel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pystatsmodels/099c7b40-92b2-4b62-bf1b-7f62b302b86an%40googlegroups.com.
Message has been deleted

Chad Fulton

unread,
Nov 18, 2020, 10:05:55 AM11/18/20
to Statsmodels Mailing List


On Tue, Nov 17, 2020 at 12:47 PM 'Ani Sengupta' via pystatsmodels <pystat...@googlegroups.com> wrote:
Hi Chad

Thanks so much your comment and tip, the link you sent has been super helpful. However you said that in order for me to implement this it would have to be a subclass of SARIMAX, not MLEModel as indicated in the example. I have tried to make a class like this:
image.png
However, I have gotten this error:
image.png

Not sure if I should brush up my knowledge on Stats and Python Class/Subclasses (or both) but how can I go forward in creating a subclass of SARIMAX where I can choose the bounds of the exogenous variables inputted to create the model?

Thanks,
Ani



Hi Ani,

Yes, you'll want to create a subclass of SARIMAX, which will mean that you don't have to implement most of those methods, since they will be handled by the SARIMAX base class. I think a minimal example of what you're after would be something like:

class SARIMAXCoeffBounds(SARIMAX):
    def __init__(self, endog, bounds=None, *args, **kwargs):
        # Setup the basic model
        super().__init_(endog, *args, **kwargs)

        # Handle the bounds argument in whatever way you want to
        ...

    def transform_params(self, unconstrained):
        # Perform the transformations required for the base SARIMAX model
        constrained = super().transform_params(unconstrained)

        # Now modify the appropriate elements of the `constrained` array in
        # order to transform the regression coefficients to satisfy the bounds
        ...

        return constrained

    def untransform_params(self, constrained):
        # Perform the reverse transformations required for the base SARIMAX
        # model
        unconstrained = super().untransform_params(constrained)

        # Now modify the appropriate elements of the `unconstrained` array in
        # order to reverse the transformation on the regression coefficients
        ...

        return unconstrained


We use a transformation to bound one of the parameters in the `UnobservedComponents` model, and you can look there for one way to do that (right after the comment "Cycle frequency must be between between our bounds").

Best,
Chad 
Reply all
Reply to author
Forward
0 new messages