1 Star 0 Fork 0

luxiaoxun/KMeans-GMM-HMM

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
GMM.h 1.95 KB
一键复制 编辑 原始数据 按行查看 历史
luxiaoxun 提交于 2014-11-02 16:05 . Hmm implementation
/***************************************************************************
Module Name:
Gaussian Mixture Model with Diagonal Covariance Matrix
History:
2003/11/01 Fei Wang
2013 luxiaoxun
***************************************************************************/
#pragma once
#include <fstream>
class GMM
{
public:
GMM(int dimNum = 1, int mixNum = 1);
~GMM();
void Copy(GMM* gmm);
void SetMaxIterNum(int i) { m_maxIterNum = i; }
void SetEndError(double f) { m_endError = f; }
int GetDimNum() { return m_dimNum; }
int GetMixNum() { return m_mixNum; }
int GetMaxIterNum() { return m_maxIterNum; }
double GetEndError() { return m_endError; }
double& Prior(int i) { return m_priors[i]; }
double* Mean(int i) { return m_means[i]; }
double* Variance(int i) { return m_vars[i]; }
void setPrior(int i,double val) { m_priors[i]=val; }
void setMean(int i,double *val) { for(int j=0;j<m_dimNum;j++) m_means[i][j]=val[j]; }
void setVariance(int i,double *val) { for(int j=0;j<m_dimNum;j++) m_vars[i][j]=val[j]; }
double GetProbability(const double* sample);
/* SampleFile: <size><dim><data>...*/
void Init(const char* sampleFileName);
void Train(const char* sampleFileName);
void Init(double *data, int N);
void Train(double *data, int N);
void DumpSampleFile(const char* fileName);
friend std::ostream& operator<<(std::ostream& out, GMM& gmm);
friend std::istream& operator>>(std::istream& in, GMM& gmm);
private:
int m_dimNum; // 样本维数
int m_mixNum; // Gaussian数目
double* m_priors; // Gaussian权重
double** m_means; // Gaussian均值
double** m_vars; // Gaussian方差
// A minimum variance is required. Now, it is the overall variance * 0.01.
double* m_minVars;
int m_maxIterNum; // The stopping criterion regarding the number of iterations
double m_endError; // The stopping criterion regarding the error
private:
// Return the "j"th pdf, p(x|j).
double GetProbability(const double* x, int j);
void Allocate();
void Dispose();
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/luxiaoxun001/KMeans-GMM-HMM.git
git@gitee.com:luxiaoxun001/KMeans-GMM-HMM.git
luxiaoxun001
KMeans-GMM-HMM
KMeans-GMM-HMM
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385