def create_job(kwargs): # model arguments nb_states = kwargs.pop('nb_states') trans_type = kwargs.pop('trans_type') obs_prior = kwargs.pop('obs_prior') # em arguments obs = kwargs.pop('obs') act = kwargs.pop('act') prec = kwargs.pop('prec') nb_iter = kwargs.pop('nb_iter') train_obs, train_act = zip( *random.sample(list(zip(obs, act)), int(0.8 * len(obs)))) dm_obs = train_obs[0].shape[-1] dm_act = train_act[0].shape[-1] rarhmm = rARHMM(nb_states, dm_obs, dm_act, trans_type=trans_type, obs_prior=obs_prior, trans_kwargs=trans_kwargs) rarhmm.initialize(train_obs, train_act) lls = rarhmm.em(train_obs, train_act, nb_iter=nb_iter, prec=prec, verbose=False) return rarhmm, lls[-1]
import matplotlib.pyplot as plt from hips.plotting.colormaps import gradient_cmap import seaborn as sns sns.set_style("white") sns.set_context("talk") color_names = [ "windows blue", "red", "amber", "faded green", "dusty purple", "orange" ] colors = sns.xkcd_palette(color_names) cmap = gradient_cmap(colors) true_rarhmm = rARHMM(nb_states=3, dm_obs=2, trans_type='recurrent') # trajectory lengths T = [1250, 1150, 1025] true_z, x = true_rarhmm.sample(horizon=T) true_ll = true_rarhmm.log_probability(x) obs_prior = {'mu0': 0., 'sigma0': 1e12, 'nu0': 2, 'psi0': 1.} trans_kwargs = {'degree': 3} rarhmm = rARHMM(nb_states=3, dm_obs=2, trans_type='poly', obs_prior=obs_prior, trans_kwargs=trans_kwargs) rarhmm.initialize(x)
'mean': np.array([0., 0., 0.]), 'std': np.array([np.pi, 8., 2.5]) } } trans_mstep_kwargs = {'nb_iter': 100} # 'batch_size': 1024, 'lr': 1e-3} # trans_type = 'poly' # trans_kwargs = {'degree': 1, # 'norm': {'mean': np.array([0., 0., 0.]), # 'std': np.array([np.pi, 8., 2.5])}} # trans_mstep_kwargs = {'nb_iter': 100, 'batch_size': 1024, 'lr': 1e-3} rarhmm = rARHMM(nb_states, dm_obs, dm_act, trans_type=trans_type, obs_prior=obs_prior, trans_prior=trans_prior, trans_kwargs=trans_kwargs) # rarhmm.initialize(obs, act) rarhmm.stochastic_em(obs, act, nb_epochs=250, verbose=True, method='adam', step_size=5e-4) lls = rarhmm.em(obs, act, nb_iter=10,
import matplotlib.pyplot as plt from hips.plotting.colormaps import gradient_cmap import seaborn as sns sns.set_style("white") sns.set_context("talk") color_names = ["windows blue", "red", "amber", "faded green", "dusty purple", "orange"] colors = sns.xkcd_palette(color_names) cmap = gradient_cmap(colors) true_rarhmm = rARHMM(nb_states=3, dm_obs=2, trans_type='neural') # trajectory lengths T = [1250, 1150, 1025] true_z, x = true_rarhmm.sample(horizon=T) true_ll = true_rarhmm.log_norm(x) rarhmm = rARHMM(nb_states=3, dm_obs=2, trans_type='neural') rarhmm.initialize(x) lls = rarhmm.em(x, nb_iter=100, prec=0., verbose=True) print("true_ll=", true_ll, "hmm_ll=", lls[-1]) plt.figure(figsize=(5, 5)) plt.plot(np.ones(len(lls)) * true_ll, '-r')