def generate_dataset(d, k, mode, nframes): """Generate a dataset useful for EM anf GMM testing. returns: data : ndarray data from the true model. tgm : GM the true model (randomly generated) gm0 : GM the initial model gm : GM the trained model """ # Generate a model w, mu, va = GM.gen_param(d, k, mode, spread=2.0) tgm = GM.fromvalues(w, mu, va) # Generate data from the model data = tgm.sample(nframes) # Run EM on the model, by running the initialization separetely. gmm = GMM(GM(d, k, mode), 'test') gmm.init_random(data) gm0 = copy.copy(gmm.gm) gmm = GMM(copy.copy(gmm.gm), 'test') em = EM() em.train(data, gmm) return data, tgm, gm0, gmm.gm