Exemple #1
0
    def run(self, r, niters=10000):
        """Run the specified mixturemodel kernel for `niters`, in a single
        thread.

        Parameters
        ----------
        r : random state
        niters : int

        """
        validator.validate_type(r, rng, param_name='r')
        validator.validate_positive(niters, param_name='niters')
        inds = xrange(len(self._defn.domains()))
        models = [bind(self._latent, i, self._views) for i in inds]
        for _ in xrange(niters):
            for name, config in self._kernel_config:
                if name == 'assign':
                    for idx in config.keys():
                        gibbs.assign(models[idx], r)
                elif name == 'assign_resample':
                    for idx, v in config.iteritems():
                        gibbs.assign_resample(models[idx], v['m'], r)
                elif name == 'slice_cluster_hp':
                    for idx, v in config.iteritems():
                        slice.hp(models[idx], r, cparam=v['cparam'])
                elif name == 'grid_relation_hp':
                    gibbs.hp(models[0], config, r)
                elif name == 'slice_relation_hp':
                    slice.hp(models[0], r, hparams=config['hparams'])
                elif name == 'theta':
                    slice.theta(models[0], r, tparams=config['tparams'])
                else:
                    assert False, "should not be reached"
Exemple #2
0
    def run(self, r, niters=10000):
        """Run the specified mixturemodel kernel for `niters`, in a single
        thread.

        Parameters
        ----------
        r : random state
        niters : int

        """
        validator.validate_type(r, rng, param_name='r')
        validator.validate_positive(niters, param_name='niters')
        model = bind(self._latent, self._view)
        for _ in xrange(niters):
            for name, config in self._kernel_config:
                if name == 'assign':
                    gibbs.assign(model, r)
                elif name == 'assign_resample':
                    gibbs.assign_resample(model, config['m'], r)
                elif name == 'grid_feature_hp':
                    gibbs.hp(model, config, r)
                elif name == 'slice_feature_hp':
                    slice.hp(model, r, hparams=config['hparams'])
                elif name == 'slice_cluster_hp':
                    slice.hp(model, r, cparam=config['cparam'])
                elif name == 'theta':
                    slice.theta(model, r, tparams=config['tparams'])
                else:
                    assert False, "should not be reach"
 def kernel(s, r):
     assign_resample(s, 10, r)
     theta(s, r, tparams=params)
 def sample_fn():
     theta(bs, r, tparams=params)
     return s.get_suffstats(0, 0)['p']
Exemple #5
0
 def kernel(s, r):
     assign_resample(s, 10, r)
     theta(s, r, tparams=params)
 def sample_fn():
     theta(bs, r, tparams=params)
     return s.get_suffstats(0, [0, 0])['p']