MLE1.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:MachineLearningProjects 作者: geallen 项目源码 文件源码
def gaussian_2d(x, y, mx, my, cov):
    ''' x and y are the 2D coordinates to calculate the function value
        mx and my are the mean parameters in x and y axes
        cov is the 2x2 variance-covariance matrix'''
    ret = 0

    # ^^ YOUR CODE HERE ^^
    sigmax = np.sqrt(cov[0][0])
    sigmay = np.sqrt(cov[1][1])
    p = cov[0][1] / (np.sqrt(cov[0][0]) * np.sqrt(cov[1][1]))
    ret = (1 / (2 * np.pi * sigmax * sigmay * np.sqrt( 1 - np.power(p,2)))) * np.exp((( -1 / ( 2 * ( 1 - np.power(p,2)))) * ( ((np.power((x - mx), 2)) / (np.power(sigmax,2))) + ((np.power((y - my), 2)) / ( np.power(sigmay, 2))) - (( 2 * p * (x - mx) * (y - my)) / (sigmax * sigmay)))))

    return ret

## Finally, we compute the Gaussian function outputs for each entry in our mesh and plot the surface for each class.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号