• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python numpy.fill_diagonal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.fill_diagonal函数的典型用法代码示例。如果您正苦于以下问题:Python fill_diagonal函数的具体用法?Python fill_diagonal怎么用?Python fill_diagonal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: cholesky

def cholesky(A, y, sigma, transpose=None):
    """Solve the least-squares system using the Cholesky decomposition."""
    m, n = A.shape
    if transpose is None:
        # transpose if matrix is fat, but not if we have sigmas for each neuron
        transpose = m < n and sigma.size == 1

    if transpose:
        # substitution: x = A'*xbar, G*xbar = b where G = A*A' + lambda*I
        G = np.dot(A, A.T)
        b = y
    else:
        # multiplication by A': G*x = A'*b where G = A'*A + lambda*I
        G = np.dot(A.T, A)
        b = np.dot(A.T, y)

    # add L2 regularization term 'lambda' = m * sigma**2
    np.fill_diagonal(G, G.diagonal() + m * sigma**2)

    try:
        import scipy.linalg
        factor = scipy.linalg.cho_factor(G, overwrite_a=True)
        x = scipy.linalg.cho_solve(factor, b)
    except ImportError:
        L = np.linalg.cholesky(G)
        L = np.linalg.inv(L.T)
        x = np.dot(L, np.dot(L.T, b))

    x = np.dot(A.T, x) if transpose else x
    info = {'rmses': npext.rms(y - np.dot(A, x), axis=0)}
    return x, info
开发者ID:epaxon,项目名称:nengo,代码行数:31,代码来源:solvers.py


示例2: calc_lik_bin

	def calc_lik_bin(j,L):
		i = recursive[j]
		Q = Q_list[Q_index[i]]
		r_vec=r_vec_list[Q_index[i]]
		t=delta_t[i] 
		r_ind= r_vec_indexes[i]
		sign=  sign_list[i]
		rho_vec= np.prod(abs(sign-r_vec[r_ind]),axis=1)
		# Pt = np.ones((4,4))
		# Pt= linalg.expm(Q.T *(t))
		w, vl = scipy.linalg.eig(Q,left=True, right=False)
		# w = eigenvalues
		# vl = eigenvectors
		vl_inv = np.linalg.inv(vl)
		
		
		d= exp(w*t) 
		m1 = np.zeros((4,4))
		np.fill_diagonal(m1,d)
		Pt1 = np.dot(vl,m1)
		Pt = np.dot(Pt1,vl_inv)
		#print vl, m1, vl_inv
		
		PvDes_temp = L[j,:]
		condLik_temp= np.dot(PvDes_temp,Pt)
		PvDes= condLik_temp *rho_vec
		L[j+1,:]= PvDes
开发者ID:tobiashofmann88,项目名称:PyRate,代码行数:27,代码来源:des_mcmc_lib.py


示例3: test_gradient

def test_gradient():
    # Test gradient of Kullback-Leibler divergence.
    random_state = check_random_state(0)

    n_samples = 50
    n_features = 2
    n_components = 2
    alpha = 1.0

    distances = random_state.randn(n_samples, n_features).astype(np.float32)
    distances = np.abs(distances.dot(distances.T))
    np.fill_diagonal(distances, 0.0)
    X_embedded = random_state.randn(n_samples, n_components).astype(np.float32)

    P = _joint_probabilities(distances, desired_perplexity=25.0,
                             verbose=0)

    def fun(params):
        return _kl_divergence(params, P, alpha, n_samples, n_components)[0]

    def grad(params):
        return _kl_divergence(params, P, alpha, n_samples, n_components)[1]

    assert_almost_equal(check_grad(fun, grad, X_embedded.ravel()), 0.0,
                        decimal=5)
开发者ID:BasilBeirouti,项目名称:scikit-learn,代码行数:25,代码来源:test_t_sne.py


示例4: random_cov

def random_cov(d, diff=None):
    """Generate random covariance matrix.
    
    Generates a random covariance matrix, or two dependent covariance matrices
    if the argument `diff` is given.
    
    """
    S = 0.8*np.random.randn(d,d)
    copy_triu_to_tril(S)
    np.fill_diagonal(S,0)
    mineig = linalg.eigvalsh(S, eigvals=(0,0))[0]
    drand = 0.8*np.random.randn(d)
    if mineig < 0:
        S += np.diag(np.exp(drand)-mineig)
    else:
        S += np.diag(np.exp(drand))
    if not diff:
        return S.T
    S2 = S * np.random.randint(2, size=(d,d))*np.exp(diff*np.random.randn(d,d))
    copy_triu_to_tril(S2)
    np.fill_diagonal(S2,0)
    mineig = linalg.eigvalsh(S2, eigvals=(0,0))[0]
    drand += diff*np.random.randn(d)
    if mineig < 0:
        S2 += np.diag(np.exp(drand)-mineig)
    else:
        S2 += np.diag(np.exp(drand))
    return S.T, S2.T
开发者ID:gelman,项目名称:ep-stan,代码行数:28,代码来源:test_olse.py


示例5: expm

def expm(A, n_factors=None, normalize=False):
    """Simple matrix exponential to replace Scipy's matrix exponential

    This just uses a recursive (factored) version of the Taylor series,
    and is not as good as Scipy (which uses Pade approximants). The hard
    part with this implementation is choosing the length of the Taylor
    series. A longer series is generally needed for a matrix with a larger
    eigenvalues, but I'm not exactly sure how these relate. I'm using
    a heuristic based on the matrix norm, since this is kind-of related
    to the size of eigenvalues, though for larger norms the function
    becomes inaccurate no matter the length of the series.

    This function is mostly intended for use in `filter_design`, where
    the matrices should be small, both in dimensions and norm.
    """
    if A.ndim != 2 or A.shape[0] != A.shape[1]:
        raise ValueError("Argument must be a square matrix")

    a = np.linalg.norm(A)
    if normalize:
        a = int(a)
        A = A / float(a)

    if n_factors is None:
        n_factors = 20 if normalize else max(20, int(a))

    Y = np.zeros_like(A)
    for i in range(n_factors, 0, -1):
        Y = np.dot(A / float(i), Y)
        np.fill_diagonal(Y, Y.diagonal() + 1)  # add identity matrix

    return np.linalg.matrix_power(Y, a) if normalize else Y
开发者ID:epaxon,项目名称:nengo,代码行数:32,代码来源:numpy.py


示例6: resample_mu_and_Sig

    def resample_mu_and_Sig(self, A, W):
        """
        Resample p given observations of the weights
        """
        Abool = A.astype(np.bool)

        for c1 in xrange(self.C):
            for c2 in xrange(self.C):
                mask = self._get_mask(Abool, c1, c2)
                self._gaussians[c1][c2].resample(W[mask])

        # Resample self connection
        if self.special_case_self_conns:
            mask = np.eye(self.N, dtype=np.bool) & Abool
            self._self_gaussian.resample(W[mask])

        # Resample covariance
        A_offdiag = Abool.copy()
        np.fill_diagonal(A_offdiag, False)
        W_cent = (W - self.Mu)[A_offdiag]
        self._cov_model.resample(W_cent)

        # Update gaussians
        for c1 in xrange(self.C):
            for c2 in xrange(self.C):
                self._gaussians[c1][c2].sigma = self._cov_model.sigma
开发者ID:slinderman,项目名称:graphistician,代码行数:26,代码来源:weights.py


示例7: recruitment

def recruitment(MA,systemByNode):
    '''
    RECRUITMENT      Recruitment coefficient
    R = RECRUITMENT(MA,systemByNode) calculates the recruitment coefficient
    for each node of the network. The recruitment coefficient of a region
    corresponds to the average probability that this region is in the same
    network community as other regions from its own system.
    Inputs:     MA,     Module Allegiance matrix, where element (i,j)
                       represents the probability that nodes i and j
                       belong to the same community
               systemByNode,	vector or cell array containing the system
                       assignment for each node
    Outputs:    R,              recruitment coefficient for each node
    _______________________________________________
    Marcelo G Mattar (08/21/2014)
    '''

    # Initialize output

    R = np.zeros(shape=(systemByNode.size,1), dtype = np.double);


    # Make sure the diagonal of the module allegiance is all nan

    MA = np.double(MA)
    np.fill_diagonal(MA, np.nan)

    # Calculate the recruitment for each node

    for i in range(systemByNode.size):
        thisSystem = systemByNode[i]
        R[i] = np.nanmean(MA[i,systemByNode==thisSystem])
    return R
开发者ID:nangongwubu,项目名称:Python-Version-for-Network-Community-Architecture-Toobox,代码行数:33,代码来源:ncat.py


示例8: _get_abs_corr_mat

    def _get_abs_corr_mat(self, X_filled, tolerance=1e-6):
        """Get absolute correlation matrix between features.

        Parameters
        ----------
        X_filled : ndarray, shape (n_samples, n_features)
            Input data with the most recent imputations.

        tolerance : float, optional (default=1e-6)
            ``abs_corr_mat`` can have nans, which will be replaced
            with ``tolerance``.

        Returns
        -------
        abs_corr_mat : ndarray, shape (n_features, n_features)
            Absolute correlation matrix of ``X`` at the beginning of the
            current round. The diagonal has been zeroed out and each feature's
            absolute correlations with all others have been normalized to sum
            to 1.
        """
        n_features = X_filled.shape[1]
        if (self.n_nearest_features is None or
                self.n_nearest_features >= n_features):
            return None
        abs_corr_mat = np.abs(np.corrcoef(X_filled.T))
        # np.corrcoef is not defined for features with zero std
        abs_corr_mat[np.isnan(abs_corr_mat)] = tolerance
        # ensures exploration, i.e. at least some probability of sampling
        np.clip(abs_corr_mat, tolerance, None, out=abs_corr_mat)
        # features are not their own neighbors
        np.fill_diagonal(abs_corr_mat, 0)
        # needs to sum to 1 for np.random.choice sampling
        abs_corr_mat = normalize(abs_corr_mat, norm='l1', axis=0, copy=False)
        return abs_corr_mat
开发者ID:SuryodayBasak,项目名称:scikit-learn,代码行数:34,代码来源:impute.py


示例9: test_wcs_dropping

def test_wcs_dropping():
    wcs = WCS(naxis=4)
    wcs.wcs.pc = np.zeros([4, 4])
    np.fill_diagonal(wcs.wcs.pc, np.arange(1, 5))
    pc = wcs.wcs.pc  # for later use below

    dropped = wcs.dropaxis(0)
    assert np.all(dropped.wcs.get_pc().diagonal() == np.array([2, 3, 4]))
    dropped = wcs.dropaxis(1)
    assert np.all(dropped.wcs.get_pc().diagonal() == np.array([1, 3, 4]))
    dropped = wcs.dropaxis(2)
    assert np.all(dropped.wcs.get_pc().diagonal() == np.array([1, 2, 4]))
    dropped = wcs.dropaxis(3)
    assert np.all(dropped.wcs.get_pc().diagonal() == np.array([1, 2, 3]))

    wcs = WCS(naxis=4)
    wcs.wcs.cd = pc

    dropped = wcs.dropaxis(0)
    assert np.all(dropped.wcs.get_pc().diagonal() == np.array([2, 3, 4]))
    dropped = wcs.dropaxis(1)
    assert np.all(dropped.wcs.get_pc().diagonal() == np.array([1, 3, 4]))
    dropped = wcs.dropaxis(2)
    assert np.all(dropped.wcs.get_pc().diagonal() == np.array([1, 2, 4]))
    dropped = wcs.dropaxis(3)
    assert np.all(dropped.wcs.get_pc().diagonal() == np.array([1, 2, 3]))
开发者ID:StuartLittlefair,项目名称:astropy,代码行数:26,代码来源:test_utils.py


示例10: knn_initialize

def knn_initialize(
        X,
        missing_mask,
        verbose=False,
        min_dist=1e-6,
        max_dist_multiplier=1e6):
    """
    Fill X with NaN values if necessary, construct the n_samples x n_samples
    distance matrix and set the self-distance of each row to infinity.

    Returns contents of X laid out in row-major, the distance matrix,
    and an "effective infinity" which is larger than any entry of the
    distance matrix.
    """
    X_row_major = X.copy("C")
    if missing_mask.sum() != np.isnan(X_row_major).sum():
        # if the missing values have already been zero-filled need
        # to put NaN's back in the data matrix for the distances function
        X_row_major[missing_mask] = np.nan
    D = all_pairs_normalized_distances(X_row_major)
    D_finite_flat = D[np.isfinite(D)]
    if len(D_finite_flat) > 0:
        max_dist = max_dist_multiplier * max(1, D_finite_flat.max())
    else:
        max_dist = max_dist_multiplier
    # set diagonal of distance matrix to a large value since we don't want
    # points considering themselves as neighbors
    np.fill_diagonal(D, max_dist)
    D[D < min_dist] = min_dist  # prevents 0s
    D[D > max_dist] = max_dist  # prevents infinities
    return X_row_major, D, max_dist
开发者ID:hammerlab,项目名称:knnimpute,代码行数:31,代码来源:common.py


示例11: test_mean

def test_mean():
    """tests various ways to compute mean - collapsing different combination of axes"""
    data = np.arange(100).reshape(10,10)
    ts_1 = TimeSeriesX.create(data, None, dims=['x','y'], coords={'x':np.arange(10)*2,
                                                                'y':np.arange(10),
                                                                    'samplerate': 1})
    grand_mean = ts_1.mean()

    assert grand_mean == 49.5

    x_mean  = ts_1.mean(dim='x')
    assert (x_mean == np.arange(45,55,1, dtype=np.float)).all()
    # checking axes
    assert(ts_1.y == x_mean.y).all()

    y_mean = ts_1.mean(dim='y')
    assert (y_mean == np.arange(4.5,95,10, dtype=np.float)).all()
    # checking axes
    assert (y_mean.x == ts_1.x).all()

    # test mean NaN
    data_2 = np.arange(100, dtype=np.float).reshape(10,10)
    np.fill_diagonal(data_2,np.NaN)
    # data_2[9,9] = 99


    ts_2 = TimeSeriesX.create(data_2, None, dims=['x','y'], coords={'x':np.arange(10)*2,
                                                                'y':np.arange(10),
                                                                    'samplerate': 1})

    grand_mean = ts_2.mean(skipna=True)
    assert grand_mean == 49.5
开发者ID:ctw,项目名称:ptsa_new,代码行数:32,代码来源:test_timeseriesx.py


示例12: build_kernels

    def build_kernels(self):
        """ Build the synaptic connectivity matrices """
        n = self.n
        # Compute all the possible distances
        dist = [self.build_distances(n, 0.917, 0.0, 1.0),
                self.build_distances(n, 0.083, 0.0, 1.0),
                self.build_distances(n, 0.912, 0.83, 1.0)]

        # Create a temporary vector containing gaussians
        g = np.empty((len(self.K), n, n))
        for j in range(len(self.K)):
            for i in range(n):
                # g[j, i] = self.K[j] * self.gaussian(dist[i], self.S[j])
                g[j, i] = self.K[j] * self.g(dist[j][i], self.S[j])
            g[j, self.m:self.k] = 0.0

        # GPe to STN connections
        W12 = np.zeros((n, n))
        W12[:self.m, self.k:] = g[0, self.k:, self.k:]

        # STN to GPe connections
        W21 = np.zeros((n, n))
        W21[self.k:, :self.m] = g[1, :self.m, :self.m]

        # GPe to GPe connections
        W22 = np.zeros((n, n))
        W22[self.k:, self.k:] = g[2, self.k:, self.k:]
        np.fill_diagonal(W22, 0.0)

        return W12, W21, W22, dist
开发者ID:rougier,项目名称:neuralfieldDBSmodel,代码行数:30,代码来源:protocolDelays.py


示例13: question_1

def question_1():
    # Adjacency matrix.
    A = numpy.matrix([
        [0, 0, 1, 0, 0, 1, 0, 0],
        [0, 0, 0, 0, 1, 0, 0, 1],
        [1, 0, 0, 1, 0, 1, 0, 0],
        [0, 0, 1, 0, 1, 0, 1, 0],
        [0, 1, 0, 1, 0, 0, 0, 1],
        [1, 0, 1, 0, 0, 0, 1, 0],
        [0, 0, 0, 1, 0, 1, 0, 1],
        [0, 1, 0, 0, 1, 0, 1, 0]
    ])
    rn, cn = A.shape

    # Degree matrix.
    D = numpy.asmatrix(numpy.zeros((rn, cn), int))
    numpy.fill_diagonal(D, sum(A))

    # Laplacian matrix.
    L = D - A

    sum_a = A.sum()
    sum_d = D.sum()
    sum_l = L.sum()
    nonzero_a = numpy.count_nonzero(A)
    nonzero_d = numpy.count_nonzero(D)
    nonzero_l = numpy.count_nonzero(L)

    print('A: sum={} #nonzero={}'.format(sum_a, nonzero_a))
    print('D: sum={} #nonzero={}'.format(sum_d, nonzero_d))
    print('L: sum={} #nonzero={}'.format(sum_l, nonzero_l))
开发者ID:vmous,项目名称:jazzy-moocs,代码行数:31,代码来源:advanced.py


示例14: __call__

 def __call__(self, A, Y, rng=None, E=None):
     # form Gram matrix so we can add regularization
     sigma = self.reg * A.max()
     G = np.dot(A.T, A)
     Y = np.dot(A.T, Y)
     np.fill_diagonal(G, G.diagonal() + sigma)
     return super(NnlsL2, self).__call__(G, Y, rng=rng, E=E)
开发者ID:epaxon,项目名称:nengo,代码行数:7,代码来源:solvers.py


示例15: Gaussian_elim_pp

def Gaussian_elim_pp(A):
    '''
    Perform LU factorization by Gaussian elimination with Partial Pivoting(pp).
    A is unchanged in the process.
    Use the LU = PA expression so L is a lower triangular matrix. Return P, L 
    and U. In the process L also need to be permutated. 
    '''
    n = A.shape[0]
    L = np.zeros((n,n)) # Left diagonal 0 because of the permutation later
    P = np.identity(n)
    U = np.copy(A)
    if n == 1:
        print 'Cannot be used for scalar'
        return     
    for k in xrange(0,n - 1):
        # The original index should be +k
        max_idex = np.argmax(np.abs(U[:,k][k:])) + k
        if max_idex != k:
            row_index = np.arange(n)
            row_index[max_idex], row_index[k] = k, max_idex
            U = U[row_index,:]  # Permutate U for partial pivoting
            L = L[row_index,:]  # Permutate L too
            P = P[row_index,:]  # Form the total permutation matrix          
        if U[k,k] == 0:
            print 'ERROR: pivot is zero'
            continue
        for i in xrange(k + 1,n):
            L[i,k] =  U[i,k] / U[k,k]
            U[i,k] = 0
        for j in xrange(k + 1,n):
            for i in xrange(k + 1, n):
                U[i,j] = U[i,j] - L[i,k] * U[k,j]
    np.fill_diagonal(L,1)       # Fill the diagonal of L in the end 
    return P, L, U
开发者ID:dongyaoli,项目名称:Numerical_Algorithm,代码行数:34,代码来源:Gaussian_Elimination.py


示例16: add_batch

    def add_batch(self, X, T, wc=None):
        """Add a batch of training data to an iterative solution, weighted if neeed.

        The batch is processed as a whole, the training data is splitted in `ELM.add_data()` method.
        With parameters HH_out, HT_out, the output will be put into these matrices instead of model.

        Args:
            X (matrix): input data matrix size (N * `inputs`)
            T (matrix): output data matrix size (N * `outputs`)
            wc (vector): vector of weights for data samples, one weight per sample, size (N * 1)
            HH_out, HT_out (matrix, optional): output matrices to add batch result into, always given together
        """
        H = self._project(X)
        T = T.astype(self.precision)
        if wc is not None:  # apply weights if given
            w = np.array(wc**0.5, dtype=self.precision)[:, None]  # re-shape to column matrix
            H *= w
            T *= w

        if self.HH is None:  # initialize space for self.HH, self.HT
            self.HH = np.zeros((self.L, self.L), dtype=self.precision)
            self.HT = np.zeros((self.L, self.outputs), dtype=self.precision)
            np.fill_diagonal(self.HH, self.norm)

        self.HH += np.dot(H.T, H)
        self.HT += np.dot(H.T, T)
开发者ID:IstanbulBoy,项目名称:hpelm,代码行数:26,代码来源:slfn.py


示例17: condense_matrix

def condense_matrix(matrice, smallest_index, method='upgma'):
    """Matrice condensation in the next iteration

    Smallest index is returned from find_smallest_index.
    For both leaf at i and j a new distance is calculated from the average of the corresponding
    row or the corresponding columns
    We then replace the first index (row and column) by the average vector obtained
    and the second index by an array with large numbers so that
    it is never chosen again with find_smallest_index.
    Now the new regroupement distance value is at the first position! (on row and column)
    """
    first_index, second_index = smallest_index
    # get the rows and make a new vector by updating distance
    rows = np.take(matrice, smallest_index, 1)
    # default we use upgma
    if(method.lower() == 'nj'):
        new_vector = (
            np.sum(rows, 1) - matrice[first_index, second_index]) * 0.5

    else:
        new_vector = np.average(rows, 1)

    # replace info in the row and column for first index with new_vector
    matrice[second_index] = new_vector
    matrice[:, second_index] = new_vector
    np.fill_diagonal(matrice, 0)
    # replace the info in the row and column for the second index with
    # high numbers so that it is ignored
    return remove_ij(matrice, first_index, first_index)
开发者ID:UdeM-LBIT,项目名称:profileNJ,代码行数:29,代码来源:ClusterUtils.py


示例18: testBijector

  def testBijector(self):
    x = np.float32(np.random.randn(3, 4, 4))

    y = x.copy()
    for i in range(x.shape[0]):
      np.fill_diagonal(y[i, :, :], np.exp(np.diag(x[i, :, :])))

    exp = tfb.Exp()
    b = tfb.TransformDiagonal(diag_bijector=exp)

    y_ = self.evaluate(b.forward(x))
    self.assertAllClose(y, y_)

    x_ = self.evaluate(b.inverse(y))
    self.assertAllClose(x, x_)

    fldj = self.evaluate(b.forward_log_det_jacobian(x, event_ndims=2))
    ildj = self.evaluate(b.inverse_log_det_jacobian(y, event_ndims=2))
    self.assertAllEqual(
        fldj,
        self.evaluate(exp.forward_log_det_jacobian(
            np.array([np.diag(x_mat) for x_mat in x]),
            event_ndims=1)))
    self.assertAllEqual(
        ildj,
        self.evaluate(exp.inverse_log_det_jacobian(
            np.array([np.diag(y_mat) for y_mat in y]),
            event_ndims=1)))
开发者ID:asudomoeva,项目名称:probability,代码行数:28,代码来源:transform_diagonal_test.py


示例19: detect_duplicates

def detect_duplicates(file_name, dist_thr=0.1, FOV=(512, 512)):
    """
    Removes duplicate ROIs from file file_name

    Parameters:
    -----------
        file_name:  .zip file with all rois

        dist_thr:   distance threshold for duplicate detection

        FOV:        dimensions of the FOV

    Returns:
    --------
        duplicates  : list of indeces with duplicate entries

        ind_keep    : list of kept indeces

    """
    rois = nf_read_roi_zip(file_name, FOV)
    cm = [scipy.ndimage.center_of_mass(mm) for mm in rois]
    sp_rois = scipy.sparse.csc_matrix(
        np.reshape(rois, (rois.shape[0], np.prod(FOV))).T)
    D = distance_masks([sp_rois, sp_rois], [cm, cm], 10)[0]
    np.fill_diagonal(D, 1)
    indeces = np.where(D < dist_thr)      # pairs of duplicate indeces

    ind = list(np.unique(indeces[1][indeces[1] > indeces[0]]))
    ind_keep = list(set(range(D.shape[0])) - set(ind))
    duplicates = list(np.unique(np.concatenate((indeces[0], indeces[1]))))

    return duplicates, ind_keep
开发者ID:Peichao,项目名称:Constrained_NMF,代码行数:32,代码来源:rois.py


示例20: calculate_couplings_levine

def calculate_couplings_levine(dt: float, w_jk: Matrix,
                               w_kj: Matrix) -> Matrix:
    """
    Compute the non-adiabatic coupling according to:
    `Evaluation of the Time-Derivative Coupling for Accurate Electronic
    State Transition Probabilities from Numerical Simulations`.
    Garrett A. Meek and Benjamin G. Levine.
    dx.doi.org/10.1021/jz5009449 | J. Phys. Chem. Lett. 2014, 5, 2351−2356
    """
    # Orthonormalize the Overlap matrices
    w_jk = np.linalg.qr(w_jk)[0]
    w_kj = np.linalg.qr(w_kj)[0]

    # Diagonal matrix
    w_jj = np.diag(np.diag(w_jk))
    w_kk = np.diag(np.diag(w_kj))

    # remove the values from the diagonal
    np.fill_diagonal(w_jk, 0)
    np.fill_diagonal(w_kj, 0)

    # Components A + B
    acos_w_jj = np.arccos(w_jj)
    asin_w_jk = np.arcsin(w_jk)

    a = acos_w_jj - asin_w_jk
    b = acos_w_jj + asin_w_jk
    A = - np.sin(np.sinc(a))
    B = np.sin(np.sinc(b))

    # Components C + D
    acos_w_kk = np.arccos(w_kk)
    asin_w_kj = np.arcsin(w_kj)

    c = acos_w_kk - asin_w_kj
    d = acos_w_kk + asin_w_kj
    C = np.sin(np.sinc(c))
    D = np.sin(np.sinc(d))

    # Components E
    w_lj = np.sqrt(1 - (w_jj ** 2) - (w_kj ** 2))
    w_lk = -(w_jk * w_jj + w_kk * w_kj) / w_lj
    asin_w_lj = np.arcsin(w_lj)
    asin_w_lk = np.arcsin(w_lk)
    asin_w_lj2 = asin_w_lj ** 2
    asin_w_lk2 = asin_w_lk ** 2

    t1 = w_lj * w_lk * asin_w_lj
    x1 = np.sqrt((1 - w_lj ** 2) * (1 - w_lk ** 2)) - 1
    t2 = x1 * asin_w_lk
    t = t1 + t2
    E_nonzero = 2 * asin_w_lj * t / (asin_w_lj2 - asin_w_lk2)

    # Check whether w_lj is different of zero
    E1 = np.where(np.abs(w_lj) > 1e-8, E_nonzero, np.zeros(A.shape))

    E = np.where(np.isclose(asin_w_lj2, asin_w_lk2), w_lj ** 2, E1)

    cte = 1 / (2 * dt)
    return cte * (np.arccos(w_jj) * (A + B) + np.arcsin(w_kj) * (C + D) + E)
开发者ID:felipeZ,项目名称:nonAdiabaticCoupling,代码行数:60,代码来源:nonAdiabaticCoupling.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numpy.find函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.fft函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap