Exemple #1
0
def test_burg():
    rnd = np.random.RandomState(12345)
    e = rnd.randn(10001)
    y = e[1:] + 0.5 * e[:-1]
    # R, ar.burg
    expected = [[0.3909931], [0.4602607, -0.1771582],
                [0.47473245, -0.21475602, 0.08168813],
                [0.4787017, -0.2251910, 0.1047554, -0.0485900],
                [0.47975462, -0.22746106, 0.10963527, -0.05896347, 0.02167001]]

    for i in range(1, 6):
        ar, _ = burg(y, i)
        assert_allclose(ar, expected[i - 1], atol=1e-6)
        as_nodemean, _ = burg(1 + y, i, False)
        assert np.all(ar != as_nodemean)
def test_burg():
    rnd = np.random.RandomState(12345)
    e = rnd.randn(10001)
    y = e[1:] + 0.5 * e[:-1]
    # R, ar.burg
    expected = [
        [0.3909931],
        [0.4602607, -0.1771582],
        [0.47473245, -0.21475602, 0.08168813],
        [0.4787017, -0.2251910, 0.1047554, -0.0485900],
        [0.47975462, - 0.22746106, 0.10963527, -0.05896347, 0.02167001]
    ]

    for i in range(1, 6):
        ar, _ = burg(y, i)
        assert_allclose(ar, expected[i - 1], atol=1e-6)
        as_nodemean, _ = burg(1 + y, i, False)
        assert np.all(ar != as_nodemean)
Exemple #3
0
def test_burg_errors():
    with pytest.raises(ValueError):
        burg(np.ones((100, 2)))
    with pytest.raises(ValueError):
        burg(np.random.randn(100), 0)
    with pytest.raises(ValueError):
        burg(np.random.randn(100), 'apple')
def test_burg_errors():
    with pytest.raises(ValueError):
        burg(np.ones((100, 2)))
    with pytest.raises(ValueError):
        burg(np.random.randn(100), 0)
    with pytest.raises(ValueError):
        burg(np.random.randn(100), 'apple')
 def obtain_arCoeff(self, signal) -> np.ndarray:
     arCoeff = np.array([])
     for col in signal.columns:
         val, _ = burg(signal[col], order=4)
         arCoeff = np.hstack((arCoeff, val))
     return arCoeff
Exemple #6
0
def burg(endog, ar_order=0, demean=True):
    """
    Estimate AR parameters using Burg technique.

    Parameters
    ----------
    endog : array_like or SARIMAXSpecification
        Input time series array, assumed to be stationary.
    ar_order : int, optional
        Autoregressive order. Default is 0.
    demean : bool, optional
        Whether to estimate and remove the mean from the process prior to
        fitting the autoregressive coefficients.

    Returns
    -------
    parameters : SARIMAXParams object
        Contains the parameter estimates from the final iteration.
    other_results : Bunch
        Includes one component, `spec`, which is the `SARIMAXSpecification`
        instance corresponding to the input arguments.

    Notes
    -----
    The primary reference is [1]_, section 5.1.2.

    This procedure assumes that the series is stationary.

    This function is a light wrapper around `statsmodels.linear_model.burg`.

    References
    ----------
    .. [1] Brockwell, Peter J., and Richard A. Davis. 2016.
       Introduction to Time Series and Forecasting. Springer.
    """
    spec = SARIMAXSpecification(endog, ar_order=ar_order)
    endog = spec.endog

    # Workaround for statsmodels.tsa.stattools.pacf_burg which doesn't work
    # on integer input
    # TODO: remove when possible
    if np.issubdtype(endog.dtype, np.dtype(int)):
        endog = endog * 1.0

    if not spec.is_ar_consecutive:
        raise ValueError('Burg estimation unavailable for models with'
                         ' seasonal or otherwise non-consecutive AR orders.')

    p = SARIMAXParams(spec=spec)

    if ar_order == 0:
        p.sigma2 = np.var(endog)
    else:
        p.ar_params, p.sigma2 = linear_model.burg(endog,
                                                  order=ar_order,
                                                  demean=demean)

        # Construct other results
    other_results = Bunch({
        'spec': spec,
    })

    return p, other_results