コード例 #1
0
ファイル: test_tools.py プロジェクト: quuhua911/statsmodels
    def test_cases(self):
        for constrained in self.constrained_cases:
            unconstrained = tools.unconstrain_stationary_univariate(constrained)  # noqa:E501
            reconstrained = tools.constrain_stationary_univariate(unconstrained)  # noqa:E501
            assert_allclose(reconstrained, constrained)

        for unconstrained in self.unconstrained_cases:
            constrained = tools.constrain_stationary_univariate(unconstrained)
            reunconstrained = tools.unconstrain_stationary_univariate(constrained)  # noqa:E501
            assert_allclose(reunconstrained, unconstrained)
コード例 #2
0
ファイル: test_tools.py プロジェクト: yl565/statsmodels
    def test_cases(self):
        for constrained in self.constrained_cases:
            unconstrained = tools.unconstrain_stationary_univariate(constrained)
            reconstrained = tools.constrain_stationary_univariate(unconstrained)
            assert_allclose(reconstrained, constrained)

        for unconstrained in self.unconstrained_cases:
            constrained = tools.constrain_stationary_univariate(unconstrained)
            reunconstrained = tools.unconstrain_stationary_univariate(constrained)
            assert_allclose(reunconstrained, unconstrained)
コード例 #3
0
    def untransform_params(self, constrained):
        """
        Transform constrained parameters used in likelihood evaluation
        to unconstrained parameters used by the optimizer

        Parameters
        ----------
        constrained : array_like
            Array of constrained parameters used in likelihood evalution, to be
            transformed.

        Returns
        -------
        unconstrained : array_like
            Array of unconstrained parameters used by the optimizer.
        """
        # Inherited parameters
        unconstrained = super(MarkovAutoregression, self).untransform_params(
            constrained)

        # Autoregressive
        # TODO may provide unexpected results when some coefficients are not
        # switching
        for i in range(self.k_regimes):
            s = self.parameters[i, 'autoregressive']
            unconstrained[s] = unconstrain_stationary_univariate(
                constrained[s])

        return unconstrained
コード例 #4
0
    def untransform_params(self, constrained):
        """
        Transform constrained parameters used in likelihood evaluation
        to unconstrained parameters used by the optimizer

        Parameters
        ----------
        constrained : array_like
            Array of constrained parameters used in likelihood evalution, to be
            transformed.

        Returns
        -------
        unconstrained : array_like
            Array of unconstrained parameters used by the optimizer.
        """
        # Inherited parameters
        unconstrained = super(MarkovAutoregression, self).untransform_params(
            constrained)

        # Autoregressive
        # TODO may provide unexpected results when some coefficients are not
        # switching
        for i in range(self.k_regimes):
            s = self.parameters[i, 'autoregressive']
            unconstrained[s] = unconstrain_stationary_univariate(
                constrained[s])

        return unconstrained
コード例 #5
0
	def untransform_params(self, constrained):
		# Perform the typical DFM untransformation (w/o the new parameters).
		unconstrained = super(ExtendedDFM, self).untransform_params(constrained[:-3])

		# Redo the factor AR unconstraint, since we only want an AR(2), and the previous unconstraint was for an AR(4).
		ar_params = constrained[self._params_factor_ar]
		unconstrained[self._params_factor_ar] = (tools.unconstrain_stationary_univariate(ar_params))

		# Return all the parameters.
		return np.r_[unconstrained, constrained[-3:]]
コード例 #6
0
    def untransform_params(self, constrained):
        # 执行典型的 DFM 逆转换(不添加新参数)
        unconstrained = super(ExtendedDFM,
                              self).untransform_params(constrained[:-3])

        # 重做不受约束的因子 AR,因为我们只想要一个 AR(2),而先前不受约束的是针对 AR(4)
        ar_params = constrained[self._params_factor_ar]
        unconstrained[self._params_factor_ar] = (
            tools.unconstrain_stationary_univariate(ar_params))

        # 返回所有参数
        return np.r_[unconstrained, constrained[-3:]]
コード例 #7
0
    def untransform_params(self, constrained):
        # Perform the typical DFM untransformation (w/o the new parameters)
        unconstrained = super(ExtendedDFM,
                              self).untransform_params(constrained[:-3])

        # Redo the factor AR unconstraint, since we only want an AR(2),
        # and the previous unconstraint was for an AR(4)
        ar_params = constrained[self._params_factor_ar]
        unconstrained[self._params_factor_ar] = (
            tools.unconstrain_stationary_univariate(ar_params))

        # Return all the parameters
        return np.r_[unconstrained, constrained[-3:]]
コード例 #8
0
    def untransform_params(self, constrained):
        """
        Transform constrained parameters used in likelihood evaluation
        to unconstrained parameters used by the optimizer

        Used primarily to reverse enforcement of stationarity of the
        autoregressive lag polynomial and invertibility of the moving average
        lag polynomial.

        Parameters
        ----------
        constrained : array_like
            Constrained parameters used in likelihood evaluation.

        Returns
        -------
        constrained : ndarray
            Unconstrained parameters used by the optimizer.
        """
        constrained = np.array(constrained, ndmin=1)
        unconstrained = constrained
        # Transform the covariance params to be positive
        unconstrained[0] = np.sqrt(constrained[0])
        for i in self.state_cov_param_indices:
            unconstrained[i] = np.sqrt(constrained[i])
        # Transform ARMA params to be stationary
        for i in range(len(self.exog_models)):
            AR_params_idx = self.AR_param_indices[i]
            MA_params_idx = self.MA_param_indices[i]
            ARMA_params_idx = slice(AR_params_idx.start,
                                    MA_params_idx.stop)
            ARMA_params = constrained[ARMA_params_idx]
            if ARMA_params:
                ARMA_params = unconstrain_stationary_univariate(ARMA_params)
                unconstrained[ARMA_params_idx] = ARMA_params
        return unconstrained
コード例 #9
0
ファイル: test_tools.py プロジェクト: yl565/statsmodels
 def test_cases(self):
     for constrained, unconstrained in self.cases:
         result = tools.unconstrain_stationary_univariate(constrained)
         assert_allclose(result, unconstrained)
コード例 #10
0
ファイル: test_tools.py プロジェクト: zhuangqingbin/AutoOM
 def test_cases(self):
     for constrained, unconstrained in self.cases:
         result = tools.unconstrain_stationary_univariate(constrained)
         assert_allclose(result, unconstrained)
コード例 #11
0
ファイル: sv.py プロジェクト: zzyjay/tsa-notebooks
 def untransform_params(self, params):
     return np.r_[unconstrain_stationary_univariate(params[:1]),
                  params[1]**0.5, params[2:]]
コード例 #12
0
 def untransform_params(self, params):
     phi = unconstrain_stationary_univariate(params[0:1])
     theta = unconstrain_stationary_univariate(params[1:2])
     sigma2 = params[2]**0.5
     return np.r_[phi, theta, sigma2]
コード例 #13
0
 def untransform_params(self, params):
     beta = unconstrain_stationary_univariate(params[0:1])
     # beta = params[0]
     sigma = params[1]**0.5
     return np.r_[beta, sigma]
コード例 #14
0
ファイル: sv.py プロジェクト: markcol/tsa-notebooks
 def untransform_params(self, params):
     return np.r_[unconstrain_stationary_univariate(params[:1]),
                  params[1]**0.5, params[2:]]
コード例 #15
0
 def untransform_params(self, constrained):
     return np.array([
         unconstrain_stationary_univariate(constrained[:1]),
         constrained[1]**0.5])