示例#1
0
    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
    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)
    def transform_params(self, unconstrained):
        """
        Transform unconstrained parameters used by the optimizer to constrained
        parameters used in likelihood evaluation

        Parameters
        ----------
        unconstrained : array_like
            Array of unconstrained parameters used by the optimizer, to be
            transformed.

        Returns
        -------
        constrained : array_like
            Array of constrained parameters which may be used in likelihood
            evalation.
        """
        # Inherited parameters
        constrained = super(MarkovAutoregression, self).transform_params(
            unconstrained)

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

        return constrained
    def transform_params(self, unconstrained):
        """
        Transform unconstrained parameters used by the optimizer to constrained
        parameters used in likelihood evaluation

        Parameters
        ----------
        unconstrained : array_like
            Array of unconstrained parameters used by the optimizer, to be
            transformed.

        Returns
        -------
        constrained : array_like
            Array of constrained parameters which may be used in likelihood
            evalation.
        """
        # Inherited parameters
        constrained = super(MarkovAutoregression, self).transform_params(
            unconstrained)

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

        return constrained
	def transform_params(self, unconstrained):
		# Perform the typical DFM transformation (w/o the new parameters).
		constrained = super(ExtendedDFM, self).transform_params(unconstrained[:-3])

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

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

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

        # 返回所有参数
        return np.r_[constrained, unconstrained[-3:]]
    def transform_params(self, unconstrained):
        # Perform the typical DFM transformation (w/o the new parameters)
        constrained = super(ExtendedDFM,
                            self).transform_params(unconstrained[:-3])

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

        # Return all the parameters
        return np.r_[constrained, unconstrained[-3:]]
    def transform_params(self, unconstrained):
        """
        Transform unconstrained parameters used by the optimizer to constrained
        parameters used in likelihood evaluation.

        Used primarily to enforce stationarity of the autoregressive lag
        polynomial, invertibility of the moving average lag polynomial, and
        positive variance parameters.

        Parameters
        ----------
        unconstrained : array_like
            Unconstrained parameters used by the optimizer.

        Returns
        -------
        constrained : ndarray
            Constrained parameters used in likelihood evaluation.
        """
        unconstrained = np.array(unconstrained, ndmin=1)
        constrained = unconstrained
        # Transform the covariance params to be positive
        constrained[0] = unconstrained[0]**2
        for i in self.state_cov_param_indices:
            constrained[i] = unconstrained[i]**2
        # 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 = unconstrained[ARMA_params_idx]
            if ARMA_params:
                ARMA_params = constrain_stationary_univariate(ARMA_params)
                constrained[ARMA_params_idx] = ARMA_params
        return constrained
示例#9
0
 def test_cases(self):
     for unconstrained, constrained in self.cases:
         result = tools.constrain_stationary_univariate(unconstrained)
         assert_equal(result, constrained)
示例#10
0
 def test_cases(self):
     for unconstrained, constrained in self.cases:
         result = tools.constrain_stationary_univariate(unconstrained)
         assert_equal(result, constrained)
示例#11
0
 def transform_params(self, params):
     return np.r_[constrain_stationary_univariate(params[:1]), params[1]**2,
                  params[2:]]
示例#12
0
 def transform_params(self, params):
     phi = constrain_stationary_univariate(params[0:1])
     theta = constrain_stationary_univariate(params[1:2])
     sigma2 = params[2]**2
     return np.r_[phi, theta, sigma2]
示例#13
0
 def transform_params(self, params):
     beta = constrain_stationary_univariate(params[0:1])
     # beta = params[0]
     sigma_2 = params[1]**2
     return np.r_[beta, sigma_2]
示例#14
0
 def transform_params(self, params):
     return np.r_[constrain_stationary_univariate(params[:1]),
                  params[1]**2, params[2:]]
示例#15
0
 def transform_params(self, unconstrained):
     return np.array([
         constrain_stationary_univariate(unconstrained[:1]),
         unconstrained[1]**2])