matab工具audiotool函数gaussmix注释版

    xiaoxiao2021-03-25  21

    这个是我目前看到的比较完整的高斯,我还不会用。注释的可能有误或者不够专业。先放在这里。里面可能涉及到其他audiotool工具里面的函数,所以没办法单独使用。需要去下载完整的库

    voicebox--wav文件

    http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.zip

    function [m,v,w,g,f,pp,gg]=gaussmix_note(x,c,l,m0,v0,w0,wx) %GAUSSMIX fits a gaussian mixture pdf to a set of data observations [m,v,w,g,f]=(x,c,l,m0,v0,w0,wx) %CHINESE note by Xu__Jiayu %对于观测数据集的适应高斯混合分布密度函数 %使用样例Usage: % (1) [m,v,w]=gaussmix(x,[],[],k);创建k个高斯混合,diag对角协方差 % create GMM with k mixtures and diagonal covariances % (2) [m,v,w]=gaussmix(x,[],[],k,'v');创建k个高斯混合 ,方阵协方差(行列相等) % create GMM with k mixtures and full covariances % % Inputs: n data values, k mixtures, p parameters, l loops %% % X(n,p)待观测数据,n行,每行有p的属性 Input data vectors, one per row. %% % c(1) 归一化的最小方差([]默认为1/n^2) Minimum variance of normalized data (Use [] to take default value of 1/n^2) %% % L 整数部分为迭代次数上限,小数部分为近似然估计阈值(类似精确度),默认100.0001 The integer portion of l gives a maximum loop count. The fractional portion gives % an optional stopping threshold. Iteration will cease if the increase in % log likelihood density per data point is less than this value. Thus l=10.001 will % stop after 10 iterations or when the increase in log likelihood falls below % 0.001. % As a special case, if L=0, then the first three outputs are omitted. % Use [] to take default value of 100.0001 %% % M0 使用样例中的k,创建的k个高斯混合(或者传入的是已经分类好的数据的质心矩阵) % Number of mixtures required (or initial mixture means - see below) %% % V0 模式设置 Initialization mode: % ******************** 'm'|'f'|'p'三选一,默认'f' % 'm' MO传入的是已经分类好的数据的质心M0 contains the initial centres % 'f'[默认]k个高斯混合质心从数据中抽取k个 Initialize with K randomly selected data points [default] % 'p'随机分区抽取质心 Initialize with centroids and variances of random partitions % ******************** 'k'|'h'二选一,默认'h' % 'k'利用kmeans算法聚类分类 k-means algorithm ('kf' and 'kp' determine initialization) % 'h'[默认]调合均值算法聚类分类 k-harmonic means algorithm ('hf' and 'hp' determine initialization) [default] % ********************'s'对数据不进行标准差=(sqrt(方差))缩放 do not scale data during initialization to have equal variances % ********************'v'方阵协方差(行列相等),当[]或没有设置为diag对角协方差full covariance matrices, % ********************v0不为字符串,为方差矩阵 % Mode 'hf' [the default] generally gives the best results but 'f' is faster and often OK %% % W0(k,1) 初始化k个混合高斯的权重,权重和需要归一化 Initial mixture weights, one per mixture. The weights should sum to unity. %% % WX(n,1) 观测数据的权重 Data point weights %% % Alternatively, initial values for M0, V0 and W0 can be given explicitly: % % M0(k,p) k个混合高斯的质心,每行代表一个 Initial mixture means, one row per mixture. % V0(k,p) k个混合高斯的方差(对角方差),每行代表一个 Initial mixture variances, one row per mixture. % or V0(p,p,k) k个混合高斯的的方差(方阵方差),每个矩阵代表一个 one full-covariance matrix per mixture % W0(k,1) 初始化k个混合高斯的权重,权重和需要归一化 Initial mixture weights, one per mixture. The weights should sum to unity. % WX(n,1) 观测数据的权重 Data point weights %% % Outputs: (Note that M, V and W are omitted if L==0) % % M(k,p) k个混合高斯的均值,每行一个 Mixture means, one row per mixture. (omitted if L==0) % V(k,p) k个混合高斯的方差,每行一个 Mixture variances, one row per mixture. (omitted if L==0) % or V(p,p,k)k个混合高斯的方差,每个矩阵一个 if full covariance matrices in use (i.e. either 'v' option or V0(p,p,k) specified) % W(k,1) k个混合高斯的权重,权重加和需要归一 Mixture weights, one per mixture. The weights will sum to unity. (omitted if L==0) % G 输入数据点的平均对数概率,拟合过程中归一化标准化确实部分。exp(g)Average log probability of the input data points. % F 表明拟合情况好坏,值越高效果越好(线性判断LDA也叫Linear Discriminant) Fisher's Discriminant measures how well the data divides into classes. % It is the ratio of the between-mixture variance to the average mixture variance: a % high value means the classes (mixtures) are well separated. % PP(n,1) 每个观测点的对数概率Log probability of each data point % GG(l+1,1) 从一开始到迭代结束的平均对数概率Average log probabilities at the beginning of each iteration and at the end %% % 这个拟合程序使用了很多初始化方法去创建初始的高斯的质心。并且使用EM(估算极大化)算法来改进高斯。 % 因为EM算法是一成不变的,初始化程序使用了随机数,当你对同一个数据使用了很多次将不会得到确切的答案 % The fitting procedure uses one of several initialization methods to create an initial guess % for the mixture centres and then uses the EM (expectation-maximization) algorithm to refine % the guess. Although the EM algorithm is deterministic, the initialization procedures use % random numbers and so the routine will not give identical answers if you call it multiple % times with the same input data. % Bugs/Suggestions % (1) Allow processing in chunks by outputting/reinputting an array of sufficient statistics % (2) Other initialization options: % 'l' LBG algorithm % 'm' Move-means (dog-rabbit) algorithm % (3) Allow updating of weights-only, not means/variances % Copyright (C) Mike Brookes 2000-2009 % Version: $Id: gaussmix.m 7784 2016-04-15 11:09:50Z dmb $ % % VOICEBOX is a MATLAB toolbox for speech processing. % Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This program is free software; you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation; either version 2 of the License, or % (at your option) any later version. % % This program is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You can obtain a copy of the GNU General Public License from % http://www.gnu.org/copyleft/gpl.html or by writing to % Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% [n,p]=size(x);%获取样本点/观测点 有n个,每个有p个属性 wn=ones(n,1);%初始化每个观测点的权重均为1,列数组,n个1 mx0=sum(x,1)/n;%初始化观测点p个属性的均值,行向量,p个均值 % calculate mean and variance of input data in each dimension vx0=sum(x.^2,1)/n-mx0.^2;%初始化观测点p个属性的方差,行向量,p个方差 sx0=sqrt(vx0);%初始化观测点p个属性的标准差,行向量,p个标准差 sx0(sx0==0)=1; %防止除以0值 % do not divide by zero when scaling scaled=0; % data is not yet scaled memsize=voicebox('memsize'); % set memory size to use %% if isempty(c)%归一化最小方差设置 c=1/n^2; else c=c(1); % just to prevent legacy code failing end fulliv=0; % initial variance is not full %% if isempty(l)%迭代次数或精度设置 l=100+1e-4; % max loop count + stopping threshold end %% %没有聚类分类v0且没有聚类质心m0且没有聚类权重w0 或者 v0是聚类分类而不是聚类方差 if nargin<5 || isempty(v0) || ischar(v0) % no initial values specified for m0, v0, w0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % No initialvalues given, so we must use k-means or equivalent %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if nargin<6 if nargin<5 || isempty(v0)% v0='hf'; %默认采用k调和平均和对待观测数据聚类分析算法,默认数据点随机取k个点作为聚类质心 % default initialization mode: hf end wx=wn; %初始化观测点权重默认ones(n,1) % no data point weights else wx=w0(:); %初始化为输入参数中的观测点权重 % data point weights end %%%%%% if any(v0=='m') k=size(m0,1);%m0传入的值质心,计算需要几个高斯混合 else k=m0;%传入的是数值,取需要随机取的高斯个数 end %%%%%% fv=any(v0=='v');%如果k个高斯方差为方阵形式,那么fv为true==1 % full covariance matrices requested %%
    转载请注明原文地址: https://ju.6miu.com/read-50417.html

    最新回复(0)