当前位置: 首页>>代码示例>>Python>>正文


Python linalg.toeplitz方法代码示例

本文整理汇总了Python中scipy.linalg.toeplitz方法的典型用法代码示例。如果您正苦于以下问题:Python linalg.toeplitz方法的具体用法?Python linalg.toeplitz怎么用?Python linalg.toeplitz使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.linalg的用法示例。


在下文中一共展示了linalg.toeplitz方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: toepz

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import toeplitz [as 别名]
def toepz(self):
        cormat = np.zeros((self.nkdim, self.nkdim))

        epsilon = (1 - np.max(self.rho)) / (1 + np.max(self.rho)) - .01

        for i in np.arange(self.k):
            t = np.insert(np.power(self.rho[i], np.arange(1, self.nk[i])), 0, 1)
            cor = toeplitz(t)
            if i == 0:
                cormat[0:self.nk[0], 0:self.nk[0]] = cor
            if i != 0:
                cormat[np.sum(self.nk[0:i]):np.sum(self.nk[0:i + 1]),
                np.sum(self.nk[0:i]):np.sum(self.nk[0:i + 1])] = cor

        np.fill_diagonal(cormat, 1 - epsilon)

        cormat = self._generate_noise(cormat, self.nkdim, self.M, epsilon)

        return cormat 
开发者ID:aschleg,项目名称:hypothetical,代码行数:21,代码来源:descriptive.py

示例2: hub

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import toeplitz [as 别名]
def hub(self):
        cormat = np.zeros((self.nkdim, self.nkdim))

        for i in np.arange(self.k):
            cor = toeplitz(self._fill_hub_matrix(self.rho[i, 0], self.rho[i, 1], self.power, self.nk[i]))
            if i == 0:
                cormat[0:self.nk[0], 0:self.nk[0]] = cor
            if i != 0:
                cormat[np.sum(self.nk[0:i]):np.sum(self.nk[0:i + 1]),
                np.sum(self.nk[0:i]):np.sum(self.nk[0:i + 1])] = cor
            tau = (np.max(self.rho[i]) - np.min(self.rho[i])) / (self.nk[i] - 2)

        epsilon = 0.08 #(1 - np.min(rho) - 0.75 * np.min(tau)) - 0.01

        np.fill_diagonal(cormat, 1 - epsilon)

        cormat = self._generate_noise(cormat, self.nkdim, self.M, epsilon)

        return cormat 
开发者ID:aschleg,项目名称:hypothetical,代码行数:21,代码来源:descriptive.py

示例3: corr_ar

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import toeplitz [as 别名]
def corr_ar(k_vars, ar):
    '''create autoregressive correlation matrix

    This might be MA, not AR, process if used for residual process - check

    Parameters
    ----------
    ar : array_like, 1d
        AR lag-polynomial including 1 for lag 0


    '''
    from scipy.linalg import toeplitz
    if len(ar) < k_vars:
        ar_ = np.zeros(k_vars)
        ar_[:len(ar)] = ar
        ar = ar_

    return toeplitz(ar) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:21,代码来源:correlation_structures.py

示例4: corr_arma

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import toeplitz [as 别名]
def corr_arma(k_vars, ar, ma):
    '''create arma correlation matrix

    converts arma to autoregressive lag-polynomial with k_var lags

    ar and arma might need to be switched for generating residual process

    Parameters
    ----------
    ar : array_like, 1d
        AR lag-polynomial including 1 for lag 0
    ma : array_like, 1d
        MA lag-polynomial

    '''
    from scipy.linalg import toeplitz
    from statsmodels.tsa.arima_process import arma2ar

    ar = arma2ar(ar, ma, nobs=k_vars)[:k_vars]  #bug in arma2ar

    return toeplitz(ar) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:23,代码来源:correlation_structures.py

示例5: _params2cov

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import toeplitz [as 别名]
def _params2cov(self, params, nobs):
        '''get autocovariance matrix from ARMA regression parameter

        ar parameters are assumed to have rhs parameterization

        '''
        ar = np.r_[[1], -params[:self.nar]]
        ma = np.r_[[1], params[-self.nma:]]
        #print('ar', ar
        #print('ma', ma
        #print('nobs', nobs
        autocov = arma_acovf(ar, ma, nobs=nobs)
        #print('arma_acovf(%r, %r, nobs=%d)' % (ar, ma, nobs)
        #print(autocov.shape
        #something is strange  fixed in aram_acovf
        autocov = autocov[:nobs]
        sigma = toeplitz(autocov)
        return sigma 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:try_mlecov.py

示例6: setup_class

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import toeplitz [as 别名]
def setup_class(cls):
        from .results.results_regression import LongleyGls

        data = longley.load()
        exog = add_constant(np.column_stack(
            (data.exog[:, 1], data.exog[:, 4])), prepend=False)
        tmp_results = OLS(data.endog, exog).fit()
        rho = np.corrcoef(tmp_results.resid[1:],
                          tmp_results.resid[:-1])[0][1]  # by assumption
        order = toeplitz(np.arange(16))
        sigma = rho**order
        GLS_results = GLS(data.endog, exog, sigma=sigma).fit()
        cls.res1 = GLS_results
        cls.res2 = LongleyGls()
        # attach for test_missing
        cls.sigma = sigma
        cls.exog = exog
        cls.endog = data.endog 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:test_regression.py

示例7: gaussian_emd

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import toeplitz [as 别名]
def gaussian_emd(x, y, sigma=1.0, distance_scaling=1.0):
    ''' Gaussian kernel with squared distance in exponential term replaced by EMD
    Args:
      x, y: 1D pmf of two distributions with the same support
      sigma: standard deviation
    '''
    support_size = max(len(x), len(y))
    d_mat = toeplitz(range(support_size)).astype(np.float)
    distance_mat = d_mat / distance_scaling

    # convert histogram values x and y to float, and make them equal len
    x = x.astype(np.float)
    y = y.astype(np.float)
    if len(x) < len(y):
        x = np.hstack((x, [0.0] * (support_size - len(x))))
    elif len(y) < len(x):
        y = np.hstack((y, [0.0] * (support_size - len(y))))

    emd = pyemd.emd(x, y, distance_mat)
    return np.exp(-emd * emd / (2 * sigma * sigma)) 
开发者ID:JiaxuanYou,项目名称:graph-generation,代码行数:22,代码来源:mmd.py

示例8: test_solve_equivalence

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import toeplitz [as 别名]
def test_solve_equivalence():
    # For toeplitz matrices, solve_toeplitz() should be equivalent to solve().
    random = np.random.RandomState(1234)
    for n in (1, 2, 3, 10):
        c = random.randn(n)
        if random.rand() < 0.5:
            c = c + 1j * random.randn(n)
        r = random.randn(n)
        if random.rand() < 0.5:
            r = r + 1j * random.randn(n)
        y = random.randn(n)
        if random.rand() < 0.5:
            y = y + 1j * random.randn(n)

        # Check equivalence when both the column and row are provided.
        actual = solve_toeplitz((c,r), y)
        desired = solve(toeplitz(c, r=r), y)
        assert_allclose(actual, desired)

        # Check equivalence when the column is provided but not the row.
        actual = solve_toeplitz(c, b=y)
        desired = solve(toeplitz(c), y)
        assert_allclose(actual, desired) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:25,代码来源:test_solve_toeplitz.py

示例9: test_unstable

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import toeplitz [as 别名]
def test_unstable():
    # this is a "Gaussian Toeplitz matrix", as mentioned in Example 2 of
    # I. Gohbert, T. Kailath and V. Olshevsky "Fast Gaussian Elimination with
    # Partial Pivoting for Matrices with Displacement Structure"
    # Mathematics of Computation, 64, 212 (1995), pp 1557-1576
    # which can be unstable for levinson recursion.

    # other fast toeplitz solvers such as GKO or Burg should be better.
    random = np.random.RandomState(1234)
    n = 100
    c = 0.9 ** (np.arange(n)**2)
    y = random.randn(n)

    solution1 = solve_toeplitz(c, b=y)
    solution2 = solve(toeplitz(c), y)

    assert_allclose(solution1, solution2) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:19,代码来源:test_solve_toeplitz.py

示例10: non_toeplitz_covariance

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import toeplitz [as 别名]
def non_toeplitz_covariance(data, window_size):
    """
    Get scaled non- Toeplitz covariance matrix, which may be able to account
    for non-stationary data-errors.

    Parameters
    ----------
    data : :class:`numpy.ndarray`
        of data to estimate non-stationary error matrix for
    window_size : int
        samples to take on running rmse estimation over data

    Returns
    -------
    :class:`numpy.ndarray` (size data, size data)
    """
    toeplitz, stds = toeplitz_covariance(data, window_size)
    return toeplitz * stds[:, num.newaxis] * stds[num.newaxis, :] 
开发者ID:hvasbath,项目名称:beat,代码行数:20,代码来源:covariance.py

示例11: Tmtx_ri

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import toeplitz [as 别名]
def Tmtx_ri(b_ri, K, D, L):
    """
    build convolution matrix associated with b_ri

    Parameters
    ----------
    b_ri: 
        a real-valued vector
    K: 
        number of Diracs
    D1: 
        expansion matrix for the real-part
    D2: 
        expansion matrix for the imaginary-part
    """
    b_ri = np.dot(D, b_ri)
    b_r = b_ri[:L]
    b_i = b_ri[L:]
    Tb_r = linalg.toeplitz(b_r[K:], b_r[K::-1])
    Tb_i = linalg.toeplitz(b_i[K:], b_i[K::-1])
    return np.vstack((np.hstack((Tb_r, -Tb_i)), np.hstack((Tb_i, Tb_r)))) 
开发者ID:LCAV,项目名称:pyroomacoustics,代码行数:23,代码来源:tools_fri_doa_plane.py

示例12: Rmtx_ri

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import toeplitz [as 别名]
def Rmtx_ri(coef_ri, K, D, L):
    ''' Split T matrix in rea/imaginary representation '''
    coef_ri = np.squeeze(coef_ri)
    coef_r = coef_ri[:K + 1]
    coef_i = coef_ri[K + 1:]
    R_r = linalg.toeplitz(np.concatenate((np.array([coef_r[-1]]),
                                          np.zeros(L - K - 1))),
                          np.concatenate((coef_r[::-1],
                                          np.zeros(L - K - 1)))
                          )
    R_i = linalg.toeplitz(np.concatenate((np.array([coef_i[-1]]),
                                          np.zeros(L - K - 1))),
                          np.concatenate((coef_i[::-1],
                                          np.zeros(L - K - 1)))
                          )
    return np.dot(np.vstack((np.hstack((R_r, -R_i)), np.hstack((R_i, R_r)))), D) 
开发者ID:LCAV,项目名称:pyroomacoustics,代码行数:18,代码来源:tools_fri_doa_plane.py

示例13: toeplitz_mul_v

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import toeplitz [as 别名]
def toeplitz_mul_v(toep,v):
    '''multiply a toeplitz matrix A by vector v.

    Args:
        toep (ndarray): representation fo multilevel toeplitz matrix, i.e.
            the first column of A in proper shape.
        v (ndarray): vector to be multiplied. Should be reshaped to the same shape
             as toep. Should be the same reshape order (column first/row first) as circ.
    Returns:
        result of multiplication.
    '''
    
    #xp = cupy.get_array_module(toep)
    circ,tmpv = embed_toep2circ(toep,v)
    res = circ_mul_v(circ,tmpv)
    slices = [slice(None)]*res.ndim
    slices[-1] = slice(0,v.shape[-1])
    slices[-2] = slice(0,v.shape[-2])
    return(res[tuple(slices)]) 
开发者ID:igp-gravity,项目名称:geoist,代码行数:21,代码来源:toeplitz.py

示例14: Tmtx_ri

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import toeplitz [as 别名]
def Tmtx_ri(b_ri, K, D, L):
    """
    build convolution matrix associated with b_ri
    :param b_ri: a real-valued vector
    :param K: number of Diracs
    :param D1: expansion matrix for the real-part
    :param D2: expansion matrix for the imaginary-part
    :return:
    """
    b_ri = np.dot(D, b_ri)
    b_r = b_ri[:L]
    b_i = b_ri[L:]
    Tb_r = linalg.toeplitz(b_r[K:], b_r[K::-1])
    Tb_i = linalg.toeplitz(b_i[K:], b_i[K::-1])
    return np.vstack((np.hstack((Tb_r, -Tb_i)), np.hstack((Tb_i, Tb_r)))) 
开发者ID:LCAV,项目名称:FRIDA,代码行数:17,代码来源:tools_fri_doa_plane.py

示例15: Rmtx_ri

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import toeplitz [as 别名]
def Rmtx_ri(coef_ri, K, D, L):
    coef_ri = np.squeeze(coef_ri)
    coef_r = coef_ri[:K + 1]
    coef_i = coef_ri[K + 1:]
    R_r = linalg.toeplitz(np.concatenate((np.array([coef_r[-1]]),
                                          np.zeros(L - K - 1))),
                          np.concatenate((coef_r[::-1],
                                          np.zeros(L - K - 1)))
                          )
    R_i = linalg.toeplitz(np.concatenate((np.array([coef_i[-1]]),
                                          np.zeros(L - K - 1))),
                          np.concatenate((coef_i[::-1],
                                          np.zeros(L - K - 1)))
                          )
    return np.dot(np.vstack((np.hstack((R_r, -R_i)), np.hstack((R_i, R_r)))), D) 
开发者ID:LCAV,项目名称:FRIDA,代码行数:17,代码来源:tools_fri_doa_plane.py


注:本文中的scipy.linalg.toeplitz方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。