コード例 #1
0
 def suggest_from_prior(self, trials, results, N):
     logger.info('suggest_from_prior')
     if not hasattr(self, '_prior_sampler'):
         self._prior_sampler = theano.function([self.s_N],
                                               self.s_prior.flatten(),
                                               mode=self.mode)
     rvals = self._prior_sampler(N)
     return IdxsValsList.fromflattened(rvals)
コード例 #2
0
ファイル: theano_gp.py プロジェクト: cyip/hyperopt
 def suggest_from_prior(self, trials, results, N):
     logger.info('suggest_from_prior')
     if not hasattr(self, '_prior_sampler'):
         self._prior_sampler = theano.function(
                 [self.s_N],
                 self.s_prior.flatten(),
                 mode=self.mode)
     rvals = self._prior_sampler(N)
     return IdxsValsList.fromflattened(rvals)
コード例 #3
0
ファイル: theano_gm.py プロジェクト: ardila/hyperopt
 def suggest_from_prior(self, N):
     try:
         prior_sampler = self._prior_sampler
     except AttributeError:
         prior_sampler = self._prior_sampler = theano.function(
                 [self.helper_locals['n_to_draw']],
                 self.helper_locals['s_prior'].flatten(),
                 mode=self.mode)
     rvals = prior_sampler(N)
     return IdxsValsList.fromflattened(rvals)
コード例 #4
0
ファイル: theano_gm.py プロジェクト: wqren/hyperopt
 def suggest_from_prior(self, N):
     try:
         prior_sampler = self._prior_sampler
     except AttributeError:
         prior_sampler = self._prior_sampler = theano.function(
             [self.helper_locals['n_to_draw']],
             self.helper_locals['s_prior'].flatten(),
             mode=self.mode)
     rvals = prior_sampler(N)
     return IdxsValsList.fromflattened(rvals)
コード例 #5
0
ファイル: theano_gm.py プロジェクト: ardila/hyperopt
    def suggest_from_model(self, ivls, N):
        helper = self._suggest_from_model_fn

        ylist = numpy.asarray(sorted(ivls['losses']['ok'].vals), dtype='float')
        y_thresh_idx = int(self.gamma * len(ylist))
        y_thresh = ylist[y_thresh_idx : y_thresh_idx + 2].mean()

        logger.info('GM_BanditAlgo splitting results at y_thresh = %f'
                % y_thresh)
        logger.info('GM_BanditAlgo keeping %i results as good'
                % y_thresh_idx)
        logger.info('GM_BanditAlgo keeping %i results as bad'
                % (len(ylist) - y_thresh_idx))
        logger.info('GM_BanditAlgo good scores: %s'
                % str(ylist[:y_thresh_idx]))

        x_all = ivls['x_IVLs']['ok'].as_list()
        y_all_iv = ivls['losses']['ok'].as_list()

        assert y_all_iv.idxset() == x_all.idxset(), (y_all_iv.idxset(),
                x_all.idxset())

        for pseudo_bad_status in 'new', 'running':
            logger.info('GM_BanditAlgo assigning bad scores to %i new jobs'
                    % len(ivls['losses'][pseudo_bad_status].idxs))
            x_all.stack(ivls['x_IVLs'][pseudo_bad_status])
            y_all_iv.stack(IdxsVals(
                ivls['losses'][pseudo_bad_status].idxs,
                [y_thresh + 1] * len(ivls['losses'][pseudo_bad_status].idxs)))
            assert y_all_iv.idxset() == x_all.idxset(), (y_all_iv.idxset(),
                    x_all.idxset())

        # renumber the configurations in x_all to be 0 .. (n_train - 1)
        idmap = y_all_iv.reindex()
        idmap = x_all.reindex(idmap)

        assert y_all_iv.idxset() == x_all.idxset(), (y_all_iv.idxset(),
                x_all.idxset())

        assert numpy.all(y_all_iv.idxs == numpy.arange(len(y_all_iv.idxs))), (
                y_all_iv.idxs)

        y_all = y_all_iv.as_numpy(vdtype=theano.config.floatX).vals
        x_all = x_all.as_numpy_floatX()

        logger.info('GM_BanditAlgo drawing %i candidates'
                % self.n_EI_candidates)

        helper_rval = helper(self.n_EI_candidates, N,
            y_thresh, y_all, *x_all.flatten())
        assert len(helper_rval) == 6 * len(x_all)

        keep_flat = helper_rval[:2 * len(x_all)]
        Gobs_flat = helper_rval[2 * len(x_all): 4 * len(x_all)]
        Bobs_flat = helper_rval[4 * len(x_all):]
        assert len(keep_flat) == len(Gobs_flat) == len(Bobs_flat)

        Gobs = IdxsValsList.fromflattened(Gobs_flat)
        Bobs = IdxsValsList.fromflattened(Bobs_flat)

        # guard against book-keeping error
        # ensure that all observations were counted as either good or bad
        gis = Gobs.idxset()
        bis = Bobs.idxset()
        xis = x_all.idxset()
        assert len(xis) == len(y_all)
        assert gis.union(bis) == xis
        assert gis.intersection(bis) == set()

        rval = IdxsValsList.fromflattened(keep_flat)
        # relabel the return values to be elements 0 ... N - 1
        rval.reindex()
        return rval
コード例 #6
0
ファイル: theano_gm.py プロジェクト: wqren/hyperopt
    def suggest_from_model(self, ivls, N):
        helper = self._suggest_from_model_fn

        ylist = numpy.asarray(sorted(ivls['losses']['ok'].vals), dtype='float')
        y_thresh_idx = int(self.gamma * len(ylist))
        y_thresh = ylist[y_thresh_idx:y_thresh_idx + 2].mean()

        logger.info('GM_BanditAlgo splitting results at y_thresh = %f' %
                    y_thresh)
        logger.info('GM_BanditAlgo keeping %i results as good' % y_thresh_idx)
        logger.info('GM_BanditAlgo keeping %i results as bad' %
                    (len(ylist) - y_thresh_idx))
        logger.info('GM_BanditAlgo good scores: %s' %
                    str(ylist[:y_thresh_idx]))

        x_all = ivls['x_IVLs']['ok'].as_list()
        y_all_iv = ivls['losses']['ok'].as_list()

        assert y_all_iv.idxset() == x_all.idxset(), (y_all_iv.idxset(),
                                                     x_all.idxset())

        for pseudo_bad_status in 'new', 'running':
            logger.info('GM_BanditAlgo assigning bad scores to %i new jobs' %
                        len(ivls['losses'][pseudo_bad_status].idxs))
            x_all.stack(ivls['x_IVLs'][pseudo_bad_status])
            y_all_iv.stack(
                IdxsVals(ivls['losses'][pseudo_bad_status].idxs,
                         [y_thresh + 1] *
                         len(ivls['losses'][pseudo_bad_status].idxs)))
            assert y_all_iv.idxset() == x_all.idxset(), (y_all_iv.idxset(),
                                                         x_all.idxset())

        # renumber the configurations in x_all to be 0 .. (n_train - 1)
        idmap = y_all_iv.reindex()
        idmap = x_all.reindex(idmap)

        assert y_all_iv.idxset() == x_all.idxset(), (y_all_iv.idxset(),
                                                     x_all.idxset())

        assert numpy.all(
            y_all_iv.idxs == numpy.arange(len(y_all_iv.idxs))), (y_all_iv.idxs)

        y_all = y_all_iv.as_numpy(vdtype=theano.config.floatX).vals
        x_all = x_all.as_numpy_floatX()

        logger.info('GM_BanditAlgo drawing %i candidates' %
                    self.n_EI_candidates)

        helper_rval = helper(self.n_EI_candidates, N, y_thresh, y_all,
                             *x_all.flatten())
        assert len(helper_rval) == 6 * len(x_all)

        keep_flat = helper_rval[:2 * len(x_all)]
        Gobs_flat = helper_rval[2 * len(x_all):4 * len(x_all)]
        Bobs_flat = helper_rval[4 * len(x_all):]
        assert len(keep_flat) == len(Gobs_flat) == len(Bobs_flat)

        Gobs = IdxsValsList.fromflattened(Gobs_flat)
        Bobs = IdxsValsList.fromflattened(Bobs_flat)

        # guard against book-keeping error
        # ensure that all observations were counted as either good or bad
        gis = Gobs.idxset()
        bis = Bobs.idxset()
        xis = x_all.idxset()
        assert len(xis) == len(y_all)
        assert gis.union(bis) == xis
        assert gis.intersection(bis) == set()

        rval = IdxsValsList.fromflattened(keep_flat)
        # relabel the return values to be elements 0 ... N - 1
        rval.reindex()
        return rval