void SaveHMM(const HMM<gmm::GMM<> >& hmm, util::SaveRestoreUtility& sr) { std::string type = "gmm"; size_t states = hmm.Transition().n_rows; sr.SaveParameter(type, "hmm_type"); sr.SaveParameter(states, "hmm_states"); sr.SaveParameter(hmm.Transition(), "hmm_transition"); // Now the emissions. for (size_t i = 0; i < states; ++i) { // Generate name. std::stringstream s; s << "hmm_emission_" << i << "_gaussians"; sr.SaveParameter(hmm.Emission()[i].Gaussians(), s.str()); s.str(""); s << "hmm_emission_" << i << "_weights"; sr.SaveParameter(hmm.Emission()[i].Weights(), s.str()); for (size_t g = 0; g < hmm.Emission()[i].Gaussians(); ++g) { s.str(""); s << "hmm_emission_" << i << "_gaussian_" << g << "_mean"; sr.SaveParameter(hmm.Emission()[i].Means()[g], s.str()); s.str(""); s << "hmm_emission_" << i << "_gaussian_" << g << "_covariance"; sr.SaveParameter(hmm.Emission()[i].Covariances()[g], s.str()); } } }
void SaveHMM(const HMM<distribution::DiscreteDistribution>& hmm, util::SaveRestoreUtility& sr) { std::string type = "discrete"; size_t states = hmm.Transition().n_rows; sr.SaveParameter(type, "hmm_type"); sr.SaveParameter(states, "hmm_states"); sr.SaveParameter(hmm.Transition(), "hmm_transition"); // Now the emissions. for (size_t i = 0; i < states; ++i) { // Generate name. std::stringstream s; s << "hmm_emission_distribution_" << i; sr.SaveParameter(hmm.Emission()[i].Probabilities(), s.str()); } }
void SaveHMM(const HMM<distribution::GaussianDistribution>& hmm, util::SaveRestoreUtility& sr) { std::string type = "gaussian"; size_t states = hmm.Transition().n_rows; sr.SaveParameter(type, "hmm_type"); sr.SaveParameter(states, "hmm_states"); sr.SaveParameter(hmm.Transition(), "hmm_transition"); // Now the emissions. for (size_t i = 0; i < states; ++i) { // Generate name. std::stringstream s; s << "hmm_emission_mean_" << i; sr.SaveParameter(hmm.Emission()[i].Mean(), s.str()); s.str(""); s << "hmm_emission_covariance_" << i; sr.SaveParameter(hmm.Emission()[i].Covariance(), s.str()); } }
/** * Save to SaveRestoreUtility. */ void DiscreteDistribution::Save(util::SaveRestoreUtility& n) const { n.SaveParameter(probabilities, "probabilities"); n.SaveParameter(Type(), "type"); }
/*& * Save to SaveRestoreUtility. */ void GaussianDistribution::Save(util::SaveRestoreUtility& sr) const { sr.SaveParameter(Type(), "type"); sr.SaveParameter(mean, "mean"); sr.SaveParameter(covariance, "covariance"); }