Beispiel #1
0
datas, heldout = hold_out(allseqs, 0.05)
training_size = sum(data.shape[0] for data in datas)
print('...done!')

print('%d total frames' % sum(data.shape[0] for data in alldata))
print('split into %d training and %d test sequences' %
      (len(datas), len(heldout)))

### inference!

Nmax = 20
obs_hypparams = dict(mu_0=np.zeros(2), sigma_0=np.eye(2), kappa_0=0.2, nu_0=5)

hmm = models.HMM(
    obs_distns=[distributions.Gaussian(**obs_hypparams) for i in range(Nmax)],
    alpha=10.,
    init_state_concentration=1.)

scores = []
sgdseq = sgd_passes(tau=0, kappa=0.7, datalist=datas)
for t, (data, rho_t) in progprint(enumerate(sgdseq)):
    hmm.meanfield_sgdstep(data, data.shape[0] / training_size, rho_t)

    if t % 10 == 0:
        scores.append(hmm.log_likelihood(heldout))

plt.figure()
plt.plot(scores)

plt.show()
Beispiel #2
0
        obs_distns=obs_distns, bern_or_weight = 'weight', svi_or_gibbs = 'svi',
        weight_prior_mean = 0, weight_prior_std = 0.1, win_size = win_size,  use_obs_features = use_obs_features)



np.random.seed(infseed)
if sgd_or_mf == 'mf':
    print('feature weights before mean field: ', '\n', HDPHMMSVImodel.feature_weights, '\n')
    for i in range(14):
        HDPHMMSVImodel.add_data(datas[i])
    for i in range(20):
        print(HDPHMMSVImodel.meanfield_coordinate_descent_step(0.5))
    print('feature weights after mean field: ', '\n', HDPHMMSVImodel.feature_weights, '\n')
else:
    scores = []
    sgdseq = sgd_passes(tau=0.8,kappa=0.9,datalist=datas, minibatchsize=4,npasses=30) #4, 3
    for t, (data, rho_t) in progprint(enumerate(sgdseq)):
        HDPHMMSVImodel.meanfield_sgdstep(data, np.array(data).shape[0] / np.float(training_size)  , rho_t)
        score = HDPHMMSVImodel.log_likelihood(heldout)
        # print 'feature weights after mean field: ', HDPHMMSVImodel.feature_weights
        print(score)
        print("")
        if t % 1 == 0:
            scores.append(score)
    # plt.plot(scores)
    # plt.show()



######################################Plotting the states and segments ###########################
Beispiel #3
0
allseqs = np.array_split(alldata,250)
datas, heldout = hold_out(allseqs,0.05)
training_size = sum(data.shape[0] for data in datas)
print '...done!'

print '%d total frames' % sum(data.shape[0] for data in alldata)
print 'split into %d training and %d test sequences' % (len(datas),len(heldout))

### inference!

Nmax = 20
obs_hypparams = dict(mu_0=np.zeros(2),sigma_0=np.eye(2),kappa_0=0.2,nu_0=5)

hmm = models.HMM(
        obs_distns=[distributions.Gaussian(**obs_hypparams) for i in range(Nmax)],
        alpha=10.,init_state_concentration=1.)

scores = []
sgdseq = sgd_passes(tau=0,kappa=0.7,datalist=datas)
for t, (data, rho_t) in progprint(enumerate(sgdseq)):
    hmm.meanfield_sgdstep(data, data.shape[0] / training_size, rho_t)

    if t % 10 == 0:
        scores.append(hmm.log_likelihood(heldout))

plt.figure()
plt.plot(scores)

plt.show()

        obs_distns=obs_distns, bern_or_weight = 'weight', svi_or_gibbs = 'svi',
        weight_prior_mean = 0, weight_prior_std = 0.1, win_size = win_size,  use_obs_features = use_obs_features)



np.random.seed(infseed)
if sgd_or_mf == 'mf':
    print 'feature weights before mean field: ', '\n', HDPHMMSVImodel.feature_weights, '\n'
    for i in range(14):
        HDPHMMSVImodel.add_data(datas[i])
    for i in range(20):
        print HDPHMMSVImodel.meanfield_coordinate_descent_step(0.5)
    print 'feature weights after mean field: ', '\n', HDPHMMSVImodel.feature_weights, '\n'
else:
    scores = []
    sgdseq = sgd_passes(tau=0.8,kappa=0.9,datalist=datas, minibatchsize=4,npasses=30) #4, 3
    for t, (data, rho_t) in progprint(enumerate(sgdseq)):
        HDPHMMSVImodel.meanfield_sgdstep(data, np.array(data).shape[0] / np.float(training_size)  , rho_t)
        score = HDPHMMSVImodel.log_likelihood(heldout)
        # print 'feature weights after mean field: ', HDPHMMSVImodel.feature_weights
        print score
        print ""
        if t % 1 == 0:
            scores.append(score)
    # plt.plot(scores)
    # plt.show()



######################################Plotting the states and segments ###########################