Numpy之高斯分布 multivariate_normal


以下是官方說明文檔鏈接

numpy.random.multivariate_normal

  • 1.函數定義
    numpy.random.multivariate_normal(mean, cov[, size, check_valid, tol])
  • 2.參數解釋
    Parameters:
    mean : 1-D array_like, of length N
    Mean of the N-dimensional distribution.
    cov : 2-D array_like, of shape (N, N)
    Covariance matrix of the distribution. It must be symmetric and positive-semidefinite for proper sampling.
    size : int or tuple of ints, optional
    Given a shape of, for example, (m,n,k), mnk samples are generated, and packed in an m-by-n-by-k arrangement. Because each sample is N-dimensional, the output shape is (m,n,k,N). If no shape is specified, a single (N-D) sample is returned.
    check_valid : { ‘warn’, ‘raise’, ‘ignore’ }, optional
    Behavior when the covariance matrix is not positive semidefinite.
    tol : float, optional
    Tolerance when checking the singular values in covariance matrix.
1 2
mean 表示高斯分布的均值,mean緯度為N,表示N維高斯分布
conv 表示高斯分布的協方差矩陣,一維高斯的協方差矩陣緯度為1X1,二維高斯的協方差矩陣緯度為2X2...
size mean和conv定義了一個高斯分布,這個函數是用定義好的高斯分布里生成若干個值,如果size為 (m,n,k),則會返回一個 (m,n,k)大小的采樣值
check_valid 檢驗協方差矩陣,當矩陣不是半正定時,輸出警告、忽略、raise.....
tol 對協方差矩陣的奇異值進行檢查時的容忍度,應該是在檢驗協方差矩陣時,對奇異值進行判斷的誤差
  • 3.使用
    (1)
    '''
    import numpy as np
    import matplotlib.pyplot as plt
    Y = np.random.multivariate_normal([(0)], [[1]], 1000)
    plt.plot(Y,'ro')
    '''

以上實例表示:采集1000個符合0均值,1協方差的高斯分布的點,
縱軸表示采集到的點的值,橫軸表示點的序號,

可以看出所有點的值大致是符合N(0,1)(正態)分布的,值為0的點概率較大,數量較多,偏離0的點數量少。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM