隐马尔可夫模型中的参数绑定实质上是将一个隐马尔可夫模型的多个逻辑参数映射到几个物理参数上,以减少计算和约束。
因此,如果参数(状态、GMMs、平均向量、协方差矩阵、过渡矩阵、流权重向量、持续时间参数向量.)是表示HMM的对象的字段,这些字段将映射到几个物理副本。例如,HMM集中的任意两种状态都可以具有相同的输出概率分布。
我需要有一个HMM的语法表示和它们之间的参数绑定,并解析它们并从它们构造HMM对象。
使用语言的特性(如果可能的话)绑定这些参数C++的好方法是什么?
编辑
原始指针绝对不是一种选择。我正在研究C++指针类型,比如shared_ptr,但如果可能的话,我也想避免它们。而且,C++引用似乎会限制功能。
发布于 2014-03-03 12:19:32
您可以对参数使用某种句柄,即:
#include <cstdio>
#include <boost/math/distributions/uniform.hpp>
template< class T>
class Handle {
T* rep_;
int* pcount_;
public:
T* operator->() { return rep_;}
Handle( T* rep) : rep_( rep), pcount_( new int(1)) {}
Handle( const Handle& r) : rep_( r.rep_), pcount_( r.pcount_) {
(*pcount_)++;
}
Handle& operator=( const Handle* r) {
if ( rep_ == r->rep_) return *this;
if ( --(*pcount_) == 0) {
delete rep_;
delete pcount_;
}
rep_ = r.rep_;
pcount_ = r.pcount_;
(*pcount_)++;
return *this;
}
~Handle() {
if ( --(*pcount_) == 0) {
delete rep_;
delete pcount_;
printf( "~Handle()");
}
}
};这样的句柄可以自由地传递,它们都可以共享单个表示:
void f1( Handle<boost::math::uniform_distribution<int> > b) {
Handle<boost::math::uniform_distribution<int> > a = b;
}
Handle<boost::math::uniform_distribution<int> > f2() {
Handle<boost::math::uniform_distribution<int> > h(
new boost::math::uniform_distribution<int>);
return h;
}
/*
*
*/
int main(int argc, char** argv) {
Handle<boost::math::uniform_distribution<int> > h = f2();
f1( h);
Handle<boost::math::uniform_distribution<int> > k = h;
return 0;
}~句柄
成功运行(总时间:62 RUN )
https://stackoverflow.com/questions/22145812
复制相似问题