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

Python pyll.rec_eval函数代码示例

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

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



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

示例1: test_vectorize_multipath

def test_vectorize_multipath():
    N = as_apply(15)

    p0 = hp_uniform('p0', 0, 1)
    loss = hp_choice('p1', [1, p0, -p0]) ** 2
    expr_idxs = scope.range(N)
    vh = VectorizeHelper(loss, expr_idxs, build=True)

    vloss = vh.v_expr
    print vloss

    full_output = as_apply([vloss,
        vh.idxs_by_label(),
        vh.vals_by_label()])

    new_vc = recursive_set_rng_kwarg(
            full_output,
            as_apply(np.random.RandomState(1)),
            )

    losses, idxs, vals = rec_eval(new_vc)
    print 'losses', losses
    print 'idxs p0', idxs['p0']
    print 'vals p0', vals['p0']
    print 'idxs p1', idxs['p1']
    print 'vals p1', vals['p1']
    p0dct = dict(zip(idxs['p0'], vals['p0']))
    p1dct = dict(zip(idxs['p1'], vals['p1']))
    for ii, li in enumerate(losses):
        print ii, li
        if p1dct[ii] != 0:
            assert li == p0dct[ii] ** 2
        else:
            assert li == 1
开发者ID:ardila,项目名称:hyperopt,代码行数:34,代码来源:test_vectorize.py


示例2: test_vectorize_simple

def test_vectorize_simple():
    N = as_apply(15)

    p0 = hp_uniform('p0', 0, 1)
    loss = p0 ** 2
    print loss
    expr_idxs = scope.range(N)
    vh = VectorizeHelper(loss, expr_idxs, build=True)
    vloss = vh.v_expr

    full_output = as_apply([vloss,
        vh.idxs_by_label(),
        vh.vals_by_label()])
    fo2 = replace_repeat_stochastic(full_output)

    new_vc = recursive_set_rng_kwarg(
            fo2,
            as_apply(np.random.RandomState(1)),
            )

    #print new_vc
    losses, idxs, vals = rec_eval(new_vc)
    print 'losses', losses
    print 'idxs p0', idxs['p0']
    print 'vals p0', vals['p0']
    p0dct = dict(zip(idxs['p0'], vals['p0']))
    for ii, li in enumerate(losses):
        assert p0dct[ii] ** 2 == li
开发者ID:ardila,项目名称:hyperopt,代码行数:28,代码来源:test_vectorize.py


示例3: get_performance

def get_performance(slm, decisions, preproc, comparison,
                    namebase=None, progkey='result_w_cleanup',
                    return_multi=False, ctrl=None):
    if decisions is None:
        decisions = np.zeros((1, 3200))
    else:
        decisions = np.asarray(decisions)
    assert decisions.shape == (1, 3200)
    if namebase is None:
        namebase = 'memmap_' + str(np.random.randint(1e8))
    image_features = scope.slm_memmap(
            desc=slm,
            X=scope.get_images('float32', preproc=preproc),
            name=namebase + '_img_feat')
    if return_multi:
        comps = ['mult', 'sqrtabsdiff']
    else:
        comps = [comparison]
    cmp_progs = []
    for comp in comps:
        sresult = screening_program(
                    slm_desc=slm,
                    preproc=preproc,
                    comparison=comp,
                    namebase=namebase,
                    decisions=decisions,
                    image_features=image_features,
                    ctrl=ctrl)[1][progkey]
        cmp_progs.append([comp, sresult])
    cmp_results = pyll.rec_eval(cmp_progs)
    if return_multi:
        return cmp_results
    else:
        return cmp_results[0][1]
开发者ID:yamins81,项目名称:eccv12,代码行数:34,代码来源:lfw.py


示例4: suggest

    def suggest(self, new_ids, trials):
        """
        new_ids - a list of unique identifiers (not necessarily ints!)
                  for the suggestions that this function should return.

        All lists have the same length.
        """
        # XXX: this used to be the implementation for the Random class and the
        # base class.  But then I was doing an experiment with Random() a
        # different seed every time and I was surprised to see it generating
        # the same thing all the time!  In response, I gave the Random
        # subclass its own simpler and more random implementation of suggest
        # that does not re-seed self.rng based on the new_ids. That leaves
        # this strange implementation here in the base class, and I'm not sure
        # whether to delete it. -JB June 19 2012
        #
        # -- install new_ids as program arguments
        rval = []
        for new_id in new_ids:
            # the results are not computed all at once so that we can
            # seed the generator based on each new_id
            sh1 = hashlib.sha1()
            sh1.update(str(new_id))
            self.rng.seed(int(int(sh1.hexdigest(), base=16) % (2 ** 31)))

            # -- sample new specs, idxs, vals
            idxs, vals = pyll.rec_eval(self.s_idxs_vals, memo={self.s_new_ids: [new_id]})
            # print 'BandigAlgo.suggest IDXS', idxs
            # print 'BandigAlgo.suggest VALS', vals
            new_result = self.bandit.new_result()
            new_misc = dict(tid=new_id, cmd=self.cmd, workdir=self.workdir)
            miscs_update_idxs_vals([new_misc], idxs, vals)
            rval.extend(trials.new_trial_docs([new_id], [None], [new_result], [new_misc]))
        return rval
开发者ID:RONNCC,项目名称:hyperopt,代码行数:34,代码来源:base.py


示例5: test_qlognormal_never_0

def test_qlognormal_never_0():
    rng = np.random.RandomState(234)
    s = scope.qlognormal(-5, 3, 0.1)
    recursive_set_rng_kwarg(s, rng)
    results = [rec_eval(s) for i in range(100)]
    assert min(results) == 0.1
    assert max(results) != 0.1
开发者ID:yamins81,项目名称:pyll,代码行数:7,代码来源:test_stochastic.py


示例6: work

        def work(self):
            bandit = self.bandit
            random_algo = Random(bandit)
            # build an experiment of 10 trials
            trials = Trials()
            exp = Experiment(trials, random_algo)
            #print random_algo.s_specs_idxs_vals
            exp.run(10)
            ids = trials.tids
            assert len(ids) == 10
            tpe_algo = TreeParzenEstimator(bandit)
            #print pyll.as_apply(tpe_algo.post_idxs)
            #print pyll.as_apply(tpe_algo.post_vals)
            argmemo = {}

            print trials.miscs
            idxs, vals = miscs_to_idxs_vals(trials.miscs)
            argmemo[tpe_algo.observed['idxs']] = idxs
            argmemo[tpe_algo.observed['vals']] = vals
            argmemo[tpe_algo.observed_loss['idxs']] = trials.tids
            argmemo[tpe_algo.observed_loss['vals']] = trials.losses()
            stuff = pyll.rec_eval([tpe_algo.post_below['idxs'],
                        tpe_algo.post_below['vals']],
                        memo=argmemo)
            print stuff
开发者ID:ardila,项目名称:hyperopt,代码行数:25,代码来源:test_tpe.py


示例7: evaluate

 def evaluate(self, config, ctrl):
     memo = self.memo_from_config(config)
     memo[self.pyll_ctrl] = ctrl
     if self.init_pyll_memo:
         memo = self.init_pyll_memo(memo, config=config, ctrl=ctrl)
     if self.rng is not None and not self.installed_rng:
         # -- N.B. this modifies the expr graph in-place
         #    XXX this feels wrong
         self.expr = recursive_set_rng_kwarg(self.expr,
             pyll.as_apply(self.rng))
         self.installed_rng = True
     try:
         # -- the "work" of evaluating `config` can be written
         #    either into the pyll part (self.expr)
         #    or the normal Python part (self.fn)
         pyll_rval = pyll.rec_eval(self.expr, memo=memo)
         rval = self.fn(pyll_rval)
     except Exception, e:
         n_match = 0
         for match, match_pair in self.exceptions:
             if match(e):
                 rval = match_pair(e)
                 logger.info('Caught fn exception %s' % str(rval))
                 n_match += 1
                 break
         if n_match == 0:
             raise
开发者ID:npinto,项目名称:hyperopt,代码行数:27,代码来源:fmin.py


示例8: test_recursive_set_rng_kwarg

def test_recursive_set_rng_kwarg():
    uniform = scope.uniform
    a = as_apply([uniform(0, 1), uniform(2, 3)])
    rng = np.random.RandomState(234)
    recursive_set_rng_kwarg(a, rng)
    print a
    val_a = rec_eval(a)
    assert 0 < val_a[0] < 1
    assert 2 < val_a[1] < 3
开发者ID:dicarlolab,项目名称:pyll,代码行数:9,代码来源:test_stochastic.py


示例9: test_clone

def test_clone():
    config = config0()
    config2 = clone(config)

    nodeset = set(dfs(config))
    assert not any(n in nodeset for n in dfs(config2))

    foo = recursive_set_rng_kwarg(
                config,
                scope.rng_from_seed(5))
    r = rec_eval(foo)
    print r
    r2 = rec_eval(
            recursive_set_rng_kwarg(
                config2,
                scope.rng_from_seed(5)))

    print r2
    assert r == r2
开发者ID:ardila,项目名称:hyperopt,代码行数:19,代码来源:test_vectorize.py


示例10: suggest_batch

def suggest_batch(new_ids, domain, trials, seed):

    rng = np.random.RandomState(seed)
    # -- sample new specs, idxs, vals
    idxs, vals = pyll.rec_eval(
        domain.s_idxs_vals,
        memo={
            domain.s_new_ids: new_ids,
            domain.s_rng: rng,
        })
    return idxs, vals
开发者ID:AiTeamUSTC,项目名称:GPE,代码行数:11,代码来源:rand.py


示例11: test_screening_prog_for_smoke

def test_screening_prog_for_smoke():
    # smoke test
    prog = toyproblem.screening_prog(ctrl=Ctrl(None), **config_tiny)
    sprog = str(prog)
    #print sprog
    rval = pyll.rec_eval(prog)
    #print rval
    assert 'loss' in rval
    assert 'decisions' in rval
    assert len(rval['splits']) == 2
    assert rval['splits'][0] != rval['splits'][1]
开发者ID:yamins81,项目名称:eccv12,代码行数:11,代码来源:test_toyproblem.py


示例12: suggest

def suggest(new_ids, domain, trials, seed=123):

    rval = []
    for new_id in new_ids:
        # -- sample new specs, idxs, vals
        idxs, vals = pyll.rec_eval(domain.s_idxs_vals,
                memo={domain.s_new_ids: [new_id]})
        new_result = domain.new_result()
        new_misc = dict(tid=new_id, cmd=domain.cmd, workdir=domain.workdir)
        miscs_update_idxs_vals([new_misc], idxs, vals)
        rval.extend(trials.new_trial_docs([new_id],
                [None], [new_result], [new_misc]))
    return rval
开发者ID:npinto,项目名称:hyperopt,代码行数:13,代码来源:rand.py


示例13: evaluate

    def evaluate(self, config, ctrl, attach_attachments=True):
        memo = self.memo_from_config(config)
        self.use_obj_for_literal_in_memo(ctrl, base.Ctrl, memo)
        if self.rng is not None and not self.installed_rng:
            # -- N.B. this modifies the expr graph in-place
            #    XXX this feels wrong
            self.expr = recursive_set_rng_kwarg(self.expr,
                pyll.as_apply(self.rng))
            self.installed_rng = True
        if self.pass_expr_memo_ctrl:
            rval = self.fn(
                    expr=self.expr,
                    memo=memo,
                    ctrl=ctrl,
                    *self.args)
        else:
            # -- the "work" of evaluating `config` can be written
            #    either into the pyll part (self.expr)
            #    or the normal Python part (self.fn)
            pyll_rval = pyll.rec_eval(self.expr, memo=memo,
                    print_node_on_error=self.rec_eval_print_node_on_error)
            rval = self.fn(pyll_rval, *self.args)

        if isinstance(rval, (float, int, np.number)):
            dict_rval = {'loss': rval}
        elif isinstance(rval, (dict,)):
            dict_rval = rval
            if 'loss' not in dict_rval:
                raise ValueError('dictionary must have "loss" key',
                        dict_rval.keys())
        else:
            raise TypeError('invalid return type (neither number nor dict)', rval)

        if dict_rval['loss'] is not None:
            # -- fail if cannot be cast to float
            dict_rval['loss'] = float(dict_rval['loss'])

        dict_rval.setdefault('status', base.STATUS_OK)
        if dict_rval['status'] not in base.STATUS_STRINGS:
            raise ValueError('invalid status string', dict_rval['status'])

        if attach_attachments:
            attachments = dict_rval.pop('attachments', {})
            for key, val in attachments.items():
                ctrl.attachments[key] = val

        # -- don't do this here because SON-compatibility is only a requirement
        #    for trials destined for a mongodb. In-memory rvals can contain
        #    anything.
        #return base.SONify(dict_rval)
        return dict_rval
开发者ID:bizso09,项目名称:hyperopt,代码行数:51,代码来源:fmin.py


示例14: logp

 def logp(apply_node):
     val = memo_cpy[apply_node]
     if val is pyll.base.GarbageCollected:
         # -- XXX: confirm this happens because the hyperparam is unused.
         return 0
     if 'uniform' in apply_node.name:
         low = apply_node.arg['low'].obj
         high = apply_node.arg['high'].obj
         if 'q' in apply_node.name:
             q = apply_node.arg['q'].obj
         if apply_node.name == 'uniform':
             return rdists.uniform_gen(a=low, b=high).logpdf(
                 val, loc=low, scale=(high - low))
         elif apply_node.name == 'quniform':
             return rdists.quniform_gen(
                 low=low, high=high, q=q).logpmf(val)
         elif apply_node.name == 'loguniform':
             return rdists.loguniform_gen(
                 low=low, high=high).logpdf(val)
         elif apply_node.name == 'qloguniform':
             return rdists.qloguniform_gen(
                 low=low, high=high, q=q).logpmf(val)
         else:
             raise NotImplementedError(apply_node.name) 
     elif 'normal' in apply_node.name:
         mu = apply_node.arg['mu'].obj
         sigma = apply_node.arg['sigma'].obj
         if 'q' in apply_node.name:
             q = apply_node.arg['q'].obj
         if apply_node.name == 'normal':
             return scipy.stats.norm(
                 loc=mu, scale=sigma).logpdf(val)
         elif apply_node.name == 'qnormal':
             return rdists.qnormal_gen(
                 mu=mu, sigma=sigma, q=q).logpmf(val)
         elif apply_node.name == 'lognormal':
             return rdists.lognorm_gen(
                 mu=mu, sigma=sigma).logpdf(val)
         elif apply_node.name == 'qlognormal':
             return rdists.qlognormal_gen(
                 mu=mu, sigma=sigma, q=q).logpmf(val)
         else:
             raise NotImplementedError(apply_node.name) 
     elif apply_node.name == 'randint':
         return -math.log(apply_node.arg['upper'].obj)
     elif apply_node.name == 'categorical':
         assert val == int(val), val
         p = pyll.rec_eval(apply_node.arg['p'])
         return math.log(p[int(val)])
     else:
         raise NotImplementedError(apply_node.name)
开发者ID:dwf,项目名称:hyperopt,代码行数:51,代码来源:tree.py


示例15: suggest

def suggest(new_ids, domain, trials, seed=123):
    logger.info('generating trials for new_ids: %s' % str(new_ids))

    rval = []
    for new_id in new_ids:
        # -- hack - domain should be read-only here :/
        #    in fact domain should not have its own seed or rng
        domain.rng.seed(seed + new_id)
        # -- sample new specs, idxs, vals
        idxs, vals = pyll.rec_eval(domain.s_idxs_vals,
                memo={domain.s_new_ids: [new_id]})
        new_result = domain.new_result()
        new_misc = dict(tid=new_id, cmd=domain.cmd, workdir=domain.workdir)
        miscs_update_idxs_vals([new_misc], idxs, vals)
        rval.extend(trials.new_trial_docs([new_id],
                [None], [new_result], [new_misc]))
    return rval
开发者ID:claesenm,项目名称:optunity-benchmark,代码行数:17,代码来源:rand.py


示例16: space_eval

def space_eval(space, hp_assignment):
    """Compute a point in a search space from a hyperparameter assignment.

    Parameters:
    -----------
    space - a pyll graph involving hp nodes (see `pyll_utils`).

    hp_assignment - a dictionary mapping hp node labels to values.
    """
    nodes = pyll.toposort(space)
    memo = {}
    for node in nodes:
        if node.name == 'hyperopt_param':
            label = node.arg['label'].eval()
            if label in hp_assignment:
                memo[node] = hp_assignment[label]
    rval = pyll.rec_eval(space, memo=memo)
    return rval
开发者ID:twiecki,项目名称:hyperopt,代码行数:18,代码来源:fmin.py


示例17: evaluate_async

    def evaluate_async(self, config, ctrl, attach_attachments=True,):
        '''
        this is the first part of async evaluation for ipython parallel engines (see ipy.py)

        This breaks evaluate into two parts to allow for the apply_async call
        to only pass the objective function and arguments.
        '''
        memo = self.memo_from_config(config)
        use_obj_for_literal_in_memo(self.expr, ctrl, Ctrl, memo)
        if self.pass_expr_memo_ctrl:
            rval = self.fn(expr=self.expr, memo=memo, ctrl=ctrl)
        else:
            # -- the "work" of evaluating `config` can be written
            #    either into the pyll part (self.expr)
            #    or the normal Python part (self.fn)
            pyll_rval = pyll.rec_eval(
                self.expr,
                memo=memo,
                print_node_on_error=self.rec_eval_print_node_on_error)
            return (self.fn,pyll_rval)
开发者ID:appcoreopc,项目名称:hyperopt,代码行数:20,代码来源:base.py


示例18: suggest

def suggest(new_ids, domain, trials, seed):
    #logger.debug("in suggest with seed: %s" % (str(seed)))
    #logger.debug('generating trials for new_ids: %s' % str(new_ids))

    rng = np.random.RandomState(seed)
    rval = []
    for ii, new_id in enumerate(new_ids):
        # -- sample new specs, idxs, vals
        idxs, vals = pyll.rec_eval(
            domain.s_idxs_vals,
            memo={
                domain.s_new_ids: [new_id],
                domain.s_rng: rng,
            })
        new_result = domain.new_result()
        new_misc = dict(tid=new_id, cmd=domain.cmd, workdir=domain.workdir)
        miscs_update_idxs_vals([new_misc], idxs, vals)
        rval.extend(trials.new_trial_docs([new_id],
                    [None], [new_result], [new_misc]))
    return rval
开发者ID:10sun,项目名称:hyperopt,代码行数:20,代码来源:rand.py


示例19: evaluate

 def evaluate(self, config, ctrl):
     """Return a result document
     """
     memo = self.memo_from_config(config)
     self.use_obj_for_literal_in_memo(ctrl, Ctrl, memo)
     if self.rng is not None and not self.installed_rng:
         # -- N.B. this modifies the expr graph in-place
         #    XXX this feels wrong
         self.expr = recursive_set_rng_kwarg(self.expr, pyll.as_apply(self.rng))
         self.installed_rng = True
     try:
         r_dct = pyll.rec_eval(self.expr, memo=memo)
     except Exception, e:
         n_match = 0
         for match, match_pair in self.exceptions:
             if match(e):
                 r_dct = match_pair(e)
                 n_match += 1
                 break
         if n_match == 0:
             raise
开发者ID:RONNCC,项目名称:hyperopt,代码行数:21,代码来源:base.py


示例20: evaluate

    def evaluate(self, config, ctrl, attach_attachments=True):
        memo = self.memo_from_config(config)
        use_obj_for_literal_in_memo(self.expr, ctrl, Ctrl, memo)
        if self.pass_expr_memo_ctrl:
            rval = self.fn(expr=self.expr, memo=memo, ctrl=ctrl)
        else:
            # -- the "work" of evaluating `config` can be written
            #    either into the pyll part (self.expr)
            #    or the normal Python part (self.fn)
            pyll_rval = pyll.rec_eval(
                self.expr,
                memo=memo,
                print_node_on_error=self.rec_eval_print_node_on_error)
            rval = self.fn(pyll_rval)

        if isinstance(rval, (float, int, np.number)):
            dict_rval = {'loss': float(rval), 'status': STATUS_OK}
        else:
            dict_rval = dict(rval)
            status = dict_rval['status']
            if status not in STATUS_STRINGS:
                raise InvalidResultStatus(dict_rval)

            if status == STATUS_OK:
                # -- make sure that the loss is present and valid
                try:
                    dict_rval['loss'] = float(dict_rval['loss'])
                except (TypeError, KeyError):
                    raise InvalidLoss(dict_rval)

        if attach_attachments:
            attachments = dict_rval.pop('attachments', {})
            for key, val in attachments.items():
                ctrl.attachments[key] = val

        # -- don't do this here because SON-compatibility is only a requirement
        #    for trials destined for a mongodb. In-memory rvals can contain
        #    anything.
        #return base.SONify(dict_rval)
        return dict_rval
开发者ID:sloth2012,项目名称:hyperopt,代码行数:40,代码来源:base.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python scope.adaptive_parzen_normal函数代码示例发布时间:2022-05-25
下一篇:
Python pyll.dfs函数代码示例发布时间: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