当前位置:网站首页>GMM Gaussian mixture model
GMM Gaussian mixture model
2022-06-13 02:17:00 【Researcher-Du】
Recent research on classic papers :GrabCut, The Gaussian mixture model GMM, Specially study . The following code snippet comes from :https://blog.csdn.net/u012436149/article/details/53557008
# -*- coding: utf-8 -*-
# for multi-Gaussian
__author__ = "KeithYin"
import numpy as np
def gaussian(x,mu,sigma):
temp = -np.square(x-mu)/(2*sigma)
return np.exp(temp)/(np.sqrt(2.0*np.pi*sigma)) # sigma = sigma^2
def e_step(data, phais, mus, sigmas):
Qs = []
for i in xrange(len(data)):
q = [phai*gaussian(data[i],mu,sigma) for phai,mu,sigma in zip(phais,mus,sigmas)]
Qs.append(q)
Qs = np.array(Qs)
Qs = Qs / np.sum(Qs,axis=1).reshape(-1,1)
return Qs
def m_step(data, phais, mus, sigmas, Qs):
data = np.array(data)
gama_j = np.sum(Qs,axis=0)
new_phais = gama_j/len(data)
print "new_phai:",
print new_phais
mu_temp = np.sum(Qs*(data.reshape(-1,1)),axis=0)
new_mus =mu_temp/gama_j
X_i_mu_j = np.square(np.array([data]).reshape(-1,1)-np.array([mus]))
new_sigmas = np.sum(Qs*X_i_mu_j,axis=0)/gama_j
return new_phais,new_mus,new_sigmas
def EM(data,k=1):
# Set the average
phais = [1.0/k for i in xrange(k)] # Coefficients of each Gaussian model
mus = [i for i in xrange(k)] # The initial mean of Gaussian mixture
sigmas = [1 for i in xrange(k)] # Initial standard deviation of Gaussian mixture
# Begin to learn
for i in xrange(100):
Qs = e_step(data,phais,mus,sigmas)
phais, mus, sigmas= m_step(data,phais,mus,sigmas,Qs)
print phais,mus,sigmas
if __name__ == "__main__":
s1 = np.random.normal(19,1,10000)
s2 = np.random.normal(1,1,10000)
s3 = np.concatenate((s1,s2),axis=0)
EM(s3,2)
Reference material :
https://zhuanlan.zhihu.com/p/30483076
https://zhuanlan.zhihu.com/p/67107370
边栏推荐
- The new wild prospect of JD instant retailing from the perspective of "hour shopping"
- What did Hello travel do right for 500million users in five years?
- Paper reading - jukebox: a generic model for music
- 1、 Set up Django automation platform (realize one click SQL execution)
- Uniapp preview function
- 拍拍贷母公司信也季报图解:营收24亿 净利5.3亿同比降10%
- js获取元素
- [the third day of actual combat of smart lock project based on stm32f401ret6 in 10 days] communication foundation and understanding serial port
- swiper 横向轮播 grid
- 华为设备配置虚拟专用网FRR
猜你喜欢
ROS learning-7 error in custom message or service reference header file
Paper reading - joint beat and downbeat tracking with recurrent neural networks
分享三个关于CMDB的小故事
Share three stories about CMDB
Configuring virtual private network FRR for Huawei equipment
SQLserver2008 拒绝了对对象 '****' (数据库 '****',架构 'dbo')的 SELECT 权限
Understanding and thinking about multi-core consistency
回顾ITIL各版本历程,找到企业运维发展的关键点
Barrykay electronics rushes to the scientific innovation board: it is planned to raise 360million yuan. Mr. and Mrs. Wang Binhua are the major shareholders
C language compressed string is saved to binary file, and the compressed string is read from binary file and decompressed.
随机推荐
Introduction to armv8/armv9 - learning this article is enough
Barrykay electronics rushes to the scientific innovation board: it is planned to raise 360million yuan. Mr. and Mrs. Wang Binhua are the major shareholders
1000粉丝啦~
[work notes] xr872 codec driver migration and application program example (with chip debugging method)
The execution results of i+=2 and i++ i++ under synchronized are different
Huawei equipment is configured with IP and virtual private network hybrid FRR
Armv8-m (Cortex-M) TrustZone summary and introduction
Application and routine of C language typedef struct
传感器:MQ-5燃气模块测量燃气值(底部附代码)
STM32 IIC protocol controls pca9685 steering gear drive board
ROS learning -5 how function packs with the same name work (workspace coverage)
Parameter measurement method of brushless motor
Image table solid line and dashed line detection
Test questions basic exercise 01 string
How to learn to understand Matplotlib instead of simple code reuse
华为设备配置双反射器优化虚拟专用网骨干层
【 unity】 Problems Encountered in Packaging webgl Project and their resolution Records
0- blog notes guide directory (all)
Anti crawling strategy (IP proxy, setting random sleep time, bilbili video information crawling, obtaining real URLs, processing special characters, processing timestamp, and multithreading)
Solution of depth learning for 3D anisotropic images