本文整理汇总了C++中MDArray::set_shape方法的典型用法代码示例。如果您正苦于以下问题:C++ MDArray::set_shape方法的具体用法?C++ MDArray::set_shape怎么用?C++ MDArray::set_shape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDArray
的用法示例。
在下文中一共展示了MDArray::set_shape方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(void) {
mocapy_seed((uint)5556574);
// Number of trainining sequences
int N = 100;
// Sequence lengths
int T = 100;
// Gibbs sampling parameters
int MCMC_BURN_IN = 10;
// HMM hidden and observed node sizes
uint H_SIZE=2;
uint O_SIZE=2;
bool init_random=false;
bool useShrinkage=true;
CPD th0_cpd;
th0_cpd.set_shape(2); th0_cpd.set_values(vec(0.1, 0.9));
CPD th1_cpd;
th1_cpd.set_shape(2,2); th1_cpd.set_values( vec(0.95, 0.05, 0.1, 0.9));
MDArray<double> means;
means.set_shape(2,2); means.set_values( vec(0.0,0.0,10.0,10.0) );
// The target DBN (This DBN generates the data)
Node* th0 = NodeFactory::new_discrete_node(H_SIZE, "th0", init_random, th0_cpd);
Node* th1 = NodeFactory::new_discrete_node(H_SIZE, "th1", init_random, th1_cpd);
Node* to0 = NodeFactory::new_gaussian_node(O_SIZE, "to0", false, useShrinkage, means);
DBN tdbn;
tdbn.set_slices(vec(th0, to0), vec(th1, to0));
tdbn.add_intra("th0", "to0");
tdbn.add_inter("th0", "th1");
tdbn.construct();
// The model DBN (this DBN will be trained)
// For mh0, get the CPD from th0 and fix parameters
Node* mh0 = NodeFactory::new_discrete_node(H_SIZE, "mh0", init_random, CPD(), th0, true );
Node* mh1 = NodeFactory::new_discrete_node(H_SIZE, "mh1", init_random);
Node* mo0 = NodeFactory::new_gaussian_node(O_SIZE, "mo0", true, useShrinkage);
DBN mdbn;
mdbn.set_slices(vec(mh0, mo0), vec(mh1, mo0));
mdbn.add_intra("mh0", "mo0");
mdbn.add_inter("mh0", "mh1");
mdbn.construct();
cout << "*** TARGET ***" << endl;
cout << *th0 << endl;
cout << *th1 << endl;
cout << *to0 << endl;
cout << "*** MODEL ***" << endl;
cout << *mh0 << endl;
cout << *mh1 << endl;
cout << *mo0 << endl;
vector<Sequence> seq_list;
vector< MDArray<eMISMASK> > mismask_list;
cout << "Generating data" << endl;
MDArray<eMISMASK> mismask;
mismask.repeat(T, vec(MOCAPY_HIDDEN, MOCAPY_OBSERVED));
// Generate the data
double sum_LL(0);
for (int i=0; i<N; i++) {
pair<Sequence, double> seq_ll = tdbn.sample_sequence(T);
sum_LL += seq_ll.second;
seq_list.push_back(seq_ll.first);
mismask_list.push_back(mismask);
}
cout << "Average LL: " << sum_LL/N << endl;
GibbsRandom mcmc = GibbsRandom(&mdbn);
EMEngine em = EMEngine(&mdbn, &mcmc, &seq_list, &mismask_list);
cout << "Starting EM loop" << endl;
double bestLL=-1000;
uint it_no_improvement(0);
uint i(0);
// Start EM loop
while (it_no_improvement<10) {
em.do_E_step(1, MCMC_BURN_IN, true);
double ll = em.get_loglik();
cout << "LL= " << ll;
if (ll > bestLL) {
cout << " * saving model *" << endl;
mdbn.save("gaussian_hmm.dbn");
bestLL = ll;
//.........这里部分代码省略.........