Esempio n. 1
0
def test_recreate_model():
    nobs = 100
    endog = np.ones(nobs) * 2.0
    exog = np.ones(nobs)

    levels = [
        'irregular', 'ntrend', 'fixed intercept', 'deterministic constant',
        'dconstant', 'local level', 'llevel', 'random walk', 'rwalk',
        'fixed slope', 'deterministic trend', 'dtrend',
        'local linear deterministic trend', 'lldtrend',
        'random walk with drift', 'rwdrift', 'local linear trend',
        'lltrend', 'smooth trend', 'strend', 'random trend', 'rtrend']

    for level in levels:
        # Note: have to add in some stochastic component, otherwise we have
        # problems with entirely deterministic models

        # level + stochastic seasonal
        mod = UnobservedComponents(endog, level=level, seasonal=2,
                                   stochastic_seasonal=True, exog=exog)
        mod2 = UnobservedComponents(endog, exog=exog, **mod._get_init_kwds())
        check_equivalent_models(mod, mod2)

        # level + autoregressive
        mod = UnobservedComponents(endog, level=level, exog=exog,
                                   autoregressive=1)
        mod2 = UnobservedComponents(endog, exog=exog, **mod._get_init_kwds())
        check_equivalent_models(mod, mod2)

        # level + stochastic cycle
        mod = UnobservedComponents(endog, level=level, exog=exog,
                                   cycle=True, stochastic_cycle=True,
                                   damped_cycle=True)
        mod2 = UnobservedComponents(endog, exog=exog, **mod._get_init_kwds())
        check_equivalent_models(mod, mod2)
Esempio n. 2
0
def test_default_get_reference_model():
    endog, exog = [0, 0, 0], [1, 1, 1]

    signature = inspect.getargspec(UnobservedComponents.__init__)
    default_args = dict(zip(signature.args[::-1], signature.defaults[::-1]))
    default_args['level'] = True
    default_args['stochastic_level'] = True
    default_args['endog'] = endog

    model = UnobservedComponents(**default_args)
    ref_model = get_reference_model(model, [1, 1, 1], [2, 2, 2])

    assert ref_model._get_init_kwds() == model._get_init_kwds()
    assert array_equivalent(ref_model.endog, [[1], [1], [1]])
    assert ref_model.exog is None

    default_args['exog'] = exog
    model = UnobservedComponents(**default_args)
    ref_model = get_reference_model(model, [1, 1, 1], [2, 2, 2])

    ref_model_kwds = ref_model._get_init_kwds()
    model_kwds = model._get_init_kwds()

    ref_model_kwds.pop('exog')
    model_kwds.pop('exog')

    assert ref_model_kwds == model_kwds
    assert array_equivalent(ref_model.endog, [[1], [1], [1]])
    assert array_equivalent(ref_model.exog, [[2], [2], [2]])