当前位置: 首页>>代码示例>>C++>>正文


C++ HMM::getTransition方法代码示例

本文整理汇总了C++中HMM::getTransition方法的典型用法代码示例。如果您正苦于以下问题:C++ HMM::getTransition方法的具体用法?C++ HMM::getTransition怎么用?C++ HMM::getTransition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HMM的用法示例。


在下文中一共展示了HMM::getTransition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mexFunction


//.........这里部分代码省略.........
		}
		else {
			mexErrMsgIdAndTxt(
				"MATLAB:Fit:HMM:invalidConfigParameter",
				"Invalid configuration parameter."
			);
		}
	}

	std::vector<InitialEmissionProbability*> initStates(0);
	for (unsigned int i = 0; i < statesCount; i += 1){
		initStates.push_back(new GaussState(gauss[i], gauss[statesCount + i]));
	}
	
	// check for NaN at the start
	dataStart = 0;
	for (unsigned int i = 0; i < dataPointCount; i += 1){
		if (!mxIsNaN(data[i])){
			dataStart = i;
			break;
		}
	}
	// check for NaN at the end
	for (dataEnd = dataStart; dataEnd < dataPointCount; dataEnd += 1){
		if (mxIsNaN(data[dataEnd])){
			break;
		}
	}

	HMM model (data + dataStart, dataEnd - dataStart, initStates, configuration);

	// delete state pointers
	initStates.clear();

	for (unsigned int i = 0; i < statesCount; i += 1){
		for (unsigned int j = 0; j < statesCount; j += 1){
			model.setTransition(transition[i + statesCount * j], i, j);
		}
	}
	model.autoSetSelfTransition();
	model.run(iterationCount);

	std::vector<unsigned int> states (dataEnd - dataStart, 0);

	model.viterbi(states);

	for (unsigned int i = 0; i < dataSize[0] * dataSize[1]; i += 1){
		if (i < dataStart || i >= dataEnd){
			statesOut[i] = mxGetNaN();
		}
		else {
			statesOut[i] = (double) states[i - dataStart] + 1;
		}
	}
	
	if (nlhs > 1){
		/* Create matrix for the transition output. */
		plhs[1] = mxCreateDoubleMatrix(statesCount, statesCount, mxREAL);
		double *transitionOut = mxGetPr(plhs[1]);
		for (unsigned int from = 0; from < statesCount; from += 1){
			for (unsigned int to = 0; to < statesCount; to += 1){
				transitionOut[from + to * statesCount] = model.getTransition(from, to);
			}
		}
		
		if (nlhs > 2){
			/* Create matrix for the emission output. */
			plhs[2] = mxCreateDoubleMatrix(statesCount, configuration.binningCount, mxREAL);
			double *emissionOut = mxGetPr(plhs[2]);
			for (unsigned int state = 0; state < statesCount; state += 1){
				for (unsigned int bin = 0; bin < configuration.binningCount; bin += 1){
					emissionOut[state + bin * statesCount] = model.getEmissionPropability(state, bin);
				}
			}
            
            if (nlhs > 3){
                /* Create vector for the emission binning centers. */
                array1D range(2, 0);
                model.getBinningRange(range);
                double binStart = range[0];
                double binDiff = range[1] - range[0];
                
                plhs[3] = mxCreateDoubleMatrix(1, configuration.binningCount, mxREAL);
                double *binningCenters = mxGetPr(plhs[3]);
                for (unsigned int bin = 0; bin < configuration.binningCount; bin += 1){
                    binningCenters[bin] = binStart +
						binDiff * (
							(0.5 + (double) bin) /
							(double) configuration.binningCount
						);
                }
                
                if (nlhs > 4){
                    /* Create matrix for the iteration count output. */
                    plhs[4] = mxCreateDoubleScalar((double) iterationCount);
                }
            }
		}
	}
}
开发者ID:mschickinger,项目名称:hiddenMarkovModel,代码行数:101,代码来源:HMM_cpp.cpp


注:本文中的HMM::getTransition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。