• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python text.progprint_xrange函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyhsmm.util.text.progprint_xrange函数的典型用法代码示例。如果您正苦于以下问题:Python progprint_xrange函数的具体用法?Python progprint_xrange怎么用?Python progprint_xrange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了progprint_xrange函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: fit

	def fit(self):
		data = np.squeeze(np.array(self._demonstrations[0])) #np.loadtxt(os.path.join(os.path.dirname(__file__),'example-data.txt'))[:T]
		Nmax = 25

		# and some hyperparameters
		obs_dim = data.shape[1]
		print data.shape
		obs_hypparams = {'mu_0':np.zeros(obs_dim),
                'sigma_0':np.eye(obs_dim),
                'kappa_0':0.25,
                'nu_0':obs_dim+2}
		dur_hypparams = {'alpha_0':2*30,
                 'beta_0':2}

		obs_distns = [pyhsmm.distributions.Gaussian(**obs_hypparams) for state in range(Nmax)]
		dur_distns = [pyhsmm.distributions.PoissonDuration(**dur_hypparams) for state in range(Nmax)]

		posteriormodel = pyhsmm.models.WeakLimitHDPHSMM(
        	alpha=6.,gamma=6., # these can matter; see concentration-resampling.py
        	init_state_concentration=6., # pretty inconsequential
        	obs_distns=obs_distns,
        	dur_distns=dur_distns)
		
		for d in self._demonstrations:
			posteriormodel.add_data(np.squeeze(np.array(d)),trunc=60) # duration truncation speeds things up when it's possible

		for idx in progprint_xrange(50):
			posteriormodel.resample_model()

		new_segments = []
		for i in range(0, len(self._demonstrations)):
			new_segments.append(self.findTransitions(posteriormodel.states_list[i].stateseq))

		self.segmentation = new_segments
		self.model = posteriormodel
开发者ID:BerkeleyAutomation,项目名称:tsc,代码行数:35,代码来源:bayes.py


示例2: fit_model

def fit_model(data, N_iters, args={}):
    # Now fit the model with a model using all the data

    default_args = dict(N=N,
                        K_max=K,
                        alpha=alpha,
                        gamma=gamma,
                        alpha_obs=alpha_obs,
                        beta_obs=beta_obs,
                        init_state_concentration=1.0)
    default_args.update(args)
    model = PoissonHDPHMM(**default_args)
    model.add_data(data)

    def _evaluate(model):
        ll = model.log_likelihood()
        return ll, K_used(model)

    def _step(model):
        model.resample_model()
        return _evaluate(model)

    results = [_step(model) for _ in progprint_xrange(N_iters)]
    lls = np.array([r[0] for r in results])
    Ks = np.array([r[1] for r in results])
    return lls, Ks
开发者ID:DyutiB,项目名称:pyhsmm_spiketrains,代码行数:26,代码来源:num_states_vs_hypers.py


示例3: train_sticky_hdp_hmm

def train_sticky_hdp_hmm(data_sets, nmax, niter, nsamples):
    """

    :param data_sets: a list of ndarrays.
    :param nmax:
    :param niter:
    :param nsamples:
    :return:
    """
    interval = niter / nsamples
    obs_dim = data_sets[0].shape[-1]
    obs_hypparams = {'mu_0': np.zeros(obs_dim),
                     'sigma_0': np.eye(obs_dim),
                     'kappa_0': 0.25,
                     'nu_0': obs_dim + 2}

    ### HDP-HMM without the sticky bias

    obs_distns = [pyhsmm.distributions.Gaussian(**obs_hypparams) for state in range(nmax)]
    posteriormodel = pyhsmm.models.WeakLimitStickyHDPHMM(kappa=50., alpha=6., gamma=6., init_state_concentration=1.,
                                                         obs_distns=obs_distns)
    for d in data_sets:
        posteriormodel.add_data(d)

    models = []
    last = None
    for idx in progprint_xrange(niter):
        posteriormodel.resample_model()
        if idx % interval == 0:
            models.append(copy.deepcopy(posteriormodel))
        last = posteriormodel
    models[nsamples - 1] = posteriormodel
    return models
开发者ID:keryil,项目名称:leaparticulatorqt,代码行数:33,代码来源:pyhsmm_wrappers.py


示例4: hsmm_segmenter

def hsmm_segmenter(factors, width=MEDIAN_WIDTH):
    obs = pre.normalize(factors, axis=1)
    obs_dim = obs.shape[1]
    obs_len = obs.shape[0]
    obs_hypparams = {
        'mu_0': np.mean(obs, axis=0),
        'sigma_0': np.cov(obs, rowvar=0),
        'kappa_0': 0.25,
        'nu_0': obs_dim + 2}

    dur_hypparams = {'alpha_0': 48,
                     'beta_0': 2}

    obs_distns = [distributions.Gaussian(**obs_hypparams) for state in xrange(Nmax)]
    dur_distns = [distributions.PoissonDuration(**dur_hypparams) for state in range(Nmax)]

    posteriormodel = pyhsmm.models.WeakLimitHDPHSMM(
        alpha_a_0=1., alpha_b_0=1./4,
        gamma_a_0=1., gamma_b_0=1./4,
        init_state_concentration=1.,  # pretty inconsequential
        obs_distns=obs_distns,
        dur_distns=dur_distns)

    posteriormodel.add_data(factors, trunc=int(obs_len / 3))

    for idx in textutil.progprint_xrange(150):
        posteriormodel.resample_model()

    labels = posteriormodel.stateseqs
    boundaries, labels = find_boundaries(labels, width)
    best_n_types = len(np.unique(labels))

    if len(boundaries) < best_n_types + 1:
        best_n_types = len(boundaries) - 1

    best_labels = segment_labeling(factors, boundaries, c_method='kmeans', k=best_n_types)
    best_boundaries = np.array(boundaries)

    return best_boundaries, best_labels
开发者ID:wangsix,项目名称:segment,代码行数:39,代码来源:segment.py


示例5: range

##################

Nmax = 10
affine = True
nlags = 2
model = m.ARWeakLimitStickyHDPHMM(
    alpha=4.,gamma=4.,kappa=50.,
    init_state_distn='uniform',
    obs_distns=[
        d.AutoRegression(
            nu_0=2.5,
            S_0=2.5*np.eye(2),
            M_0=np.zeros((2,2*nlags+affine)),
            K_0=10*np.eye(2*nlags+affine),
            affine=affine)
        for state in range(Nmax)],
)

model.add_data(data)

###############
#  inference  #
###############

fig = model.make_figure()
model.plot(fig=fig,draw=False)
for _ in progprint_xrange(300):
    model.resample_model()
    model.plot(fig=fig,update=True)

开发者ID:mattjj,项目名称:next.ml,代码行数:29,代码来源:arhmm.py


示例6: range

obs_hypparams = {'mu_0':np.zeros(obs_dim),
                'sigma_0':np.eye(obs_dim),
                'kappa_0':0.25,
                'nu_0':obs_dim+2}

obs_distns = [pyhsmm.distributions.Gaussian(**obs_hypparams) for state in range(N)]

# Build the HMM model that will represent the fitmodel
fitmodel = pyhsmm.models.HMM(
        alpha=50.,init_state_concentration=50., # these are only used for initialization
        obs_distns=obs_distns)
fitmodel.add_data(data)

print('Gibbs sampling for initialization')

for idx in progprint_xrange(25):
    fitmodel.resample_model()

plt.figure()
fitmodel.plot()
plt.gcf().suptitle('Gibbs-sampled initialization')

print('EM')

likes = fitmodel.EM_fit()

plt.figure()
fitmodel.plot()
plt.gcf().suptitle('EM fit')

plt.figure()
开发者ID:chiaolun,项目名称:pyhsmm,代码行数:31,代码来源:hmm-EM.py


示例7: xrange

        A=np.eye(D),sigma=0.1*np.eye(D), # TODO remove special case
        nu_0=5,S_0=np.eye(D),M_0=np.zeros((D,P)),K_0=np.eye(P))
    for _ in xrange(Nmax)]

init_dynamics_distns = [
    Gaussian(nu_0=5,sigma_0=np.eye(P),mu_0=np.zeros(P),kappa_0=1.)
    for _ in xrange(Nmax)]

model = WeakLimitStickyHDPHMMSLDS(
    dynamics_distns=dynamics_distns,
    emission_distns=emission_distns,
    init_dynamics_distns=init_dynamics_distns,
    kappa=50.,alpha=5.,gamma=5.,init_state_concentration=1.)


##################
#  run sampling  #
##################

def resample():
    model.resample_model()
    return model.stateseqs[0].copy()


model.add_data(data)
samples = [resample() for _ in progprint_xrange(1000)]

plt.matshow(np.vstack(samples+[np.tile(labels,(10,1))]))

plt.show()
开发者ID:fivejjs,项目名称:pyhsmm-slds,代码行数:30,代码来源:demo.py


示例8: zip

temp = np.concatenate(((0,),truemodel.states_list[0].durations.cumsum()))
changepoints = zip(temp[:-1],temp[1:])
changepoints[-1] = (changepoints[-1][0],T) # because last duration might be censored



#########################
#  posterior inference  #
#########################

Nmax = 25

obs_distns = [pyhsmm.distributions.Gaussian(**obs_hypparams) for state in range(Nmax)]
dur_distns = [pyhsmm.distributions.GeometricDuration(**dur_hypparams) for state in range(Nmax)]

posteriormodel = pyhsmm.models.GeoHSMMPossibleChangepoints(
        alpha=6.,
        init_state_concentration=6.,
        obs_distns=obs_distns,
        dur_distns=dur_distns)
posteriormodel.add_data(data,changepoints=changepoints)

for idx in progprint_xrange(50):
    posteriormodel.resample_model()

plt.figure()
posteriormodel.plot()

plt.show()
开发者ID:52nlp,项目名称:pyhsmm,代码行数:29,代码来源:hsmm-geo.py


示例9: xrange

plt.figure()
model.plot()
plt.gcf().suptitle('subHSMM sampled model after {} iterations'.format(ITERATIONS))
plt.savefig('plots/' + testcase + '/subhmm.png')
plt.close()
s = model.states_list[0] 
"""

### HDP-HMM without the sticky bias

obs_distns = [pyhsmm.distributions.Gaussian(**obs_hypparams) for state in xrange(Nmax)]
posteriormodel = pyhsmm.models.WeakLimitHDPHMM(alpha=6.,gamma=6.,init_state_concentration=1.,
                                   obs_distns=obs_distns)
posteriormodel.add_data(data)

for idx in progprint_xrange(ITERATIONS):
    posteriormodel.resample_model()

posteriormodel.plot()
plt.gcf().suptitle('HDP-HMM sampled model after {} iterations'.format(ITERATIONS))
plt.savefig('plots/' + testcase + '/hdp-hmm.png')
plt.close() 

# Some more hypparams

obs_hypparams = {'mu_0':np.zeros(obs_dim),
                'sigma_0':np.eye(obs_dim),
                'kappa_0':0.3,
                'nu_0':obs_dim+5}
dur_hypparams = {'alpha_0':2,
                 'beta_0':2}
开发者ID:suryabhupa,项目名称:subgoal-inf,代码行数:31,代码来源:infer.py


示例10: xrange

    mu_0=np.zeros(obs_dim), sigma_0=np.eye(obs_dim),
    kappa_0=0.25, nu_0=obs_dim+2)

obs_distns = \
    [pyhsmm.distributions.Gaussian(**obs_hypparams) for state in xrange(Nmax)]
model = pyhsmm.models.WeakLimitStickyHDPHMM(
    kappa=50.,alpha=6.,gamma=6.,init_state_concentration=1.,
    obs_distns=obs_distns)
model.add_data(data)


# run inference!
fig = model.make_figure()
model.plot(fig=fig,draw=False)

for _ in progprint_xrange(250):
    model.resample_model()
    model.plot(fig=fig,update=True)



# from moviepy.video.io.bindings import mplfig_to_npimage
# from moviepy.editor import VideoClip

# fig = model.make_figure()
# model.plot(fig=fig,draw=False)

# def make_frame_mpl(t):
#     model.resample_model()
#     model.plot(fig=fig,update=True,draw=False)
#     return mplfig_to_npimage(fig)
开发者ID:mattjj,项目名称:next.ml,代码行数:31,代码来源:hmm.py


示例11: LibraryMM

    alpha_0=components_per_gmm,
    weights=row)
    for row in init_weights]

##############
#  build MM  #
##############

model = LibraryMM(
        alpha_0=6.,
        components=meta_components)

model.add_data(data)

##################
#  infer things  #
##################

for i in progprint_xrange(50):
    model.resample_model()

plt.figure()
truemodel.plot()
plt.gcf().suptitle('truth')

plt.figure()
model.plot()
plt.gcf().suptitle('inferred')

plt.show()
开发者ID:dattalab,项目名称:pyhsmm-library-models,代码行数:30,代码来源:library-gmm-synthetic.py


示例12: range

    weights=row)
    for row in init_weights]

################
#  build HSMM  #
################

dur_distns = [NegativeBinomialIntegerRVariantDuration(np.r_[0.,0,0,1,1,1,1,1],alpha_0=5.,beta_0=5.)
        for state in range(library_size)]

model = LibraryHSMMIntNegBinVariant(
        init_state_concentration=10.,
        alpha=6.,gamma=6.,
        obs_distns=obs_distns,
        dur_distns=dur_distns)

model.add_data(data)

#####################
#  sample and save  #
#####################

models = [model.resample_and_copy() for itr in progprint_xrange(100)]

with open('models.pickle','w') as outfile:
    cPickle.dump(models,outfile,protocol=-1)

with open('model.pickle','w') as outfile:
    cPickle.dump(models[0],outfile,protocol=-1)

开发者ID:dattalab,项目名称:pyhsmm-library-models,代码行数:29,代码来源:sample-pickling-size.py


示例13: range

        for state in range(library_size)]

model = LibraryHSMMIntNegBinVariant(
        init_state_concentration=10.,
        alpha=6.,gamma=6.,
        obs_distns=obs_distns,
        dur_distns=dur_distns)

for data in training_datas:
    model.add_data(data,left_censoring=True)
    # model.add_data_parallel(data,left_censoring=True)

##################
#  infer things  #
##################

train_likes = []
test_likes = []

for i in progprint_xrange(5):
    model.resample_model()
    # model.resample_model_parallel()
    train_likes.append(model.log_likelihood())
    # test_likes.append(model.log_likelihood(test_data,left_censoring=True))

newmodel = model.unfreeze()

for i in progprint_xrange(5):
    newmodel.resample_model()

开发者ID:dattalab,项目名称:pyhsmm-library-models,代码行数:29,代码来源:unfreeze.py


示例14: range

            np.r_[0,0,0,0,0,1.,1.,1.], # discrete distribution uniform over {6,7,8}
            alpha_0=9,beta_0=1, # average geometric success probability 1/(9+1)
            ) for state in range(Nmax)]

model  = pyhsmm.models.HSMMIntNegBinVariant(
        init_state_concentration=10.,
        alpha=6.,gamma=6.,
        obs_distns=obs_distns,
        dur_distns=dur_distns)
model.add_data(data,left_censoring=True)

##############
#  resample  #
##############

for itr in progprint_xrange(10):
    model.resample_model()

################
#  viterbi EM  #
################

model.Viterbi_EM_fit()

##########
#  plot  #
##########

plt.figure()
model.plot()
开发者ID:123mitnik,项目名称:pyhsmm,代码行数:30,代码来源:intnegbinvariant.py


示例15: range

        for state in range(library_size)]

model = LibraryHSMMIntNegBinVariant(
        init_state_concentration=10.,
        alpha=6.,gamma=6.,
        obs_distns=obs_distns,
        dur_distns=dur_distns)

for data in training_datas:
    model.add_data(data,left_censoring=True)

##################
#  infer things  #
##################

samples1 = [model.resample_and_copy() for i in progprint_xrange(1)]
samples2 = [model.resample_and_copy() for i in progprint_xrange(10)]
samples3 = [model.resample_and_copy() for i in progprint_xrange(100)]
# samples4 = [model.resample_and_copy() for i in progprint_xrange(1000)]

import cPickle
with open('samples1','w') as outfile:
    cPickle.dump(samples1,outfile,protocol=-1)

with open('samples2','w') as outfile:
    cPickle.dump(samples2,outfile,protocol=-1)

with open('samples3','w') as outfile:
    cPickle.dump(samples3,outfile,protocol=-1)

# with open('samples4','w') as outfile:
开发者ID:dattalab,项目名称:pyhsmm-library-models,代码行数:31,代码来源:saving-samples.py


示例16: range

################

dur_distns = [NegativeBinomialIntegerRVariantDuration(np.r_[0.,0,0,1,1,1,1,1],alpha_0=5.,beta_0=5.)
        for state in range(Nmax)]

model = LibraryHSMMIntNegBinVariant(
        init_state_concentration=10.,
        alpha=6.,gamma=6.,
        obs_distns=obs_distns,
        dur_distns=dur_distns)

for data in datas:
    model.add_data_parallel(data,left_censoring=True)

##################
#  infer things  #
##################

for i in progprint_xrange(25):
    model.resample_model_parallel()

# plt.figure()
# truemodel.plot()
# plt.gcf().suptitle('truth')

# plt.figure()
# model.plot()
# plt.gcf().suptitle('inferred')

# plt.show()
开发者ID:dattalab,项目名称:pyhsmm-library-models,代码行数:30,代码来源:parallel-test.py


示例17: progprint_xrange

obs_distns = [
        library_models.FrozenMixtureDistribution(
            components=component_library,
            a_0=1.0,b_0=1./5,weights=weights, # for initialization only
        ) for weights in init_weights]

hmm = library_models.LibraryHMM(
        init_state_concentration=10.,
        alpha_a_0=1.0,alpha_b_0=1./10,
        gamma_a_0=1,gamma_b_0=1,
        obs_distns=obs_distns)
hmm.add_data(training_data)

##########################
#  Gather model samples  #
##########################

for itr in progprint_xrange(num_iter):
    hmm.resample_model()

hmms = [hmm.resample_and_copy() for itr in progprint_xrange(1)]

##########
#  Save  #
##########

with open('/scratch/hmm_results.pickle','w') as outfile:
    cPickle.dump(hmms,outfile,protocol=-1)

开发者ID:dattalab,项目名称:pyhsmm-library-models,代码行数:28,代码来源:fit_hmm.py


示例18: len

    gamma_a_0=0.5,
    gamma_b_0=3.0,
    init_state_concentration=6.0,
    obs_distns=[
        d.MNIW(len(dmu) + 2, 5 * np.diag(np.diag(dcov)), np.zeros((len(dmu), 2 * len(dmu))), 10 * np.eye(2 * len(dmu)))
        for state in range(Nmax)
    ],
    # dur_distns=[pyhsmm.basic.distributions.GeometricDuration(100,2000) for state in range(Nmax)],
    # dur_distns=[pyhsmm.basic.distributions.PoissonDuration(3*20,3) for state in range(Nmax)],
    dur_distns=[
        pyhsmm.basic.distributions.NegativeBinomialDuration(10 * 10.0, 1.0 / 10.0, 3 * 10.0, 1 * 10.0)
        for state in range(Nmax)
    ],
)

for i, t in enumerate(tracks):
    model.add_data_parallel(i)

########################
#  try some inference  #
########################
plt.figure()
for itr in progprint_xrange(200):
    if itr % 5 == 0:
        plt.gcf().clf()
        model.plot()
        plt.ion()
        plt.draw()
        plt.ioff()
    model.resample_model_parallel()
开发者ID:dattalab,项目名称:pyparticles,代码行数:30,代码来源:mouse_test.py


示例19: range

Kmax = 10                           # number of latent discrete states
D_latent = 2                        # latent linear dynamics' dimension
D_obs = 2                           # data dimension

Cs = [np.eye(D_obs) for _ in range(Kmax)]                   # Shared emission matrices
sigma_obss = [0.05 * np.eye(D_obs) for _ in range(Kmax)]    # Emission noise covariances

model = DefaultSLDS(
    K=Kmax, D_obs=D_obs, D_latent=D_latent,
    Cs=Cs, sigma_obss=sigma_obss)

model.add_data(data)
model.resample_states()

for _ in progprint_xrange(10):
    model.resample_model()
model.states_list[0]._init_mf_from_gibbs()


####################
#  run mean field  #
####################

vlbs = []
for _ in progprint_xrange(50):
    vlbs.append(model.meanfield_coordinate_descent_step())

plt.figure()
plt.plot(vlbs)
plt.xlabel("Iteration")
开发者ID:mattjj,项目名称:pyhsmm-slds,代码行数:30,代码来源:meanfield.py


示例20: collect_stats

    component.add_data(data=observations)
    components.append(component)



# Data structure to collect results
results = []#pd.DataFrame(columns=['Log-Likelihood', 'Accuracy', 'Precision', 'Recall', 'F1'])

# Collect stats into the dataframe
stats = collect_stats(components, real_states, observations, testing, weights, np.ones((1, testing.shape[1])), Model)
results.append(list(stats))


# This is Gibbs sampling
for itr in progprint_xrange(ITER):
    # In each resamle, we are going to fix all the chains except one, then resample
    # that chain given all the other fixed ones. After doing this, a single
    # resample of the factorial model is done

    # Resample the variances
    states = np.matrix(np.zeros((COMP+1, observations.shape[0])))
    states[-1, :] = 1

    for i, component in enumerate(components):
        states[i, :] = component.states_list[0].stateseq

    # Now compute the means
    means = np.matrix(weights)*states
    # Squared summed error
    sse = np.power(observations - means.T, 2).sum(axis=0)
开发者ID:enoriega,项目名称:factorial-hmm,代码行数:30,代码来源:factorial_hsmm_run.py



注:本文中的pyhsmm.util.text.progprint_xrange函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python core.Cluster类代码示例发布时间:2022-05-25
下一篇:
Python cmd.YHSM_Cmd类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap