void LoadHMM(HMM<distribution::DiscreteDistribution>& hmm, util::SaveRestoreUtility& sr) { std::string type; size_t states; sr.LoadParameter(type, "hmm_type"); if (type != "discrete") { Rcpp::Rcout << "Cannot load non-discrete HMM (of type " << type << ") as " << "discrete HMM!" << std::endl; } sr.LoadParameter(states, "hmm_states"); // Load transition matrix. sr.LoadParameter(hmm.Transition(), "hmm_transition"); // Now each emission distribution. hmm.Emission().resize(states); for (size_t i = 0; i < states; ++i) { std::stringstream s; s << "hmm_emission_distribution_" << i; sr.LoadParameter(hmm.Emission()[i].Probabilities(), s.str()); } hmm.Dimensionality() = 1; }
void LoadHMM(HMM<distribution::GaussianDistribution>& hmm, util::SaveRestoreUtility& sr) { std::string type; size_t states; sr.LoadParameter(type, "hmm_type"); if (type != "gaussian") { Rcpp::Rcout << "Cannot load non-Gaussian HMM (of type " << type << ") as " << "a Gaussian HMM!" << std::endl; } sr.LoadParameter(states, "hmm_states"); // Load transition matrix. sr.LoadParameter(hmm.Transition(), "hmm_transition"); // Now each emission distribution. hmm.Emission().resize(states); for (size_t i = 0; i < states; ++i) { std::stringstream s; s << "hmm_emission_mean_" << i; sr.LoadParameter(hmm.Emission()[i].Mean(), s.str()); s.str(""); s << "hmm_emission_covariance_" << i; sr.LoadParameter(hmm.Emission()[i].Covariance(), s.str()); } hmm.Dimensionality() = hmm.Emission()[0].Mean().n_elem; }
void LoadHMM(HMM<gmm::GMM<> >& hmm, util::SaveRestoreUtility& sr) { std::string type; size_t states; sr.LoadParameter(type, "hmm_type"); if (type != "gmm") { Rcpp::Rcout << "Cannot load non-GMM HMM (of type " << type << ") as " << "a Gaussian Mixture Model HMM!" << std::endl; } sr.LoadParameter(states, "hmm_states"); // Load transition matrix. sr.LoadParameter(hmm.Transition(), "hmm_transition"); // Now each emission distribution. hmm.Emission().resize(states, gmm::GMM<>(1, 1)); for (size_t i = 0; i < states; ++i) { std::stringstream s; s << "hmm_emission_" << i << "_gaussians"; size_t gaussians; sr.LoadParameter(gaussians, s.str()); s.str(""); // Extract dimensionality. arma::vec meanzero; s << "hmm_emission_" << i << "_gaussian_0_mean"; sr.LoadParameter(meanzero, s.str()); size_t dimensionality = meanzero.n_elem; // Initialize GMM correctly. hmm.Emission()[i].Gaussians() = gaussians; hmm.Emission()[i].Dimensionality() = dimensionality; for (size_t g = 0; g < gaussians; ++g) { s.str(""); s << "hmm_emission_" << i << "_gaussian_" << g << "_mean"; sr.LoadParameter(hmm.Emission()[i].Means()[g], s.str()); s.str(""); s << "hmm_emission_" << i << "_gaussian_" << g << "_covariance"; sr.LoadParameter(hmm.Emission()[i].Covariances()[g], s.str()); } s.str(""); s << "hmm_emission_" << i << "_weights"; sr.LoadParameter(hmm.Emission()[i].Weights(), s.str()); } hmm.Dimensionality() = hmm.Emission()[0].Dimensionality(); }
void Load(const util::SaveRestoreUtility& n) { n.LoadParameter(probabilities, "probabilities"); }
/** * Load from SaveRestoreUtility. */ void GaussianDistribution::Load(const util::SaveRestoreUtility& sr) { sr.LoadParameter(mean, "mean"); sr.LoadParameter(covariance, "covariance"); }