当前位置: 首页>>代码示例>>Python>>正文


Python ConfigSpace.Configuration方法代码示例

本文整理汇总了Python中ConfigSpace.Configuration方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigSpace.Configuration方法的具体用法?Python ConfigSpace.Configuration怎么用?Python ConfigSpace.Configuration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConfigSpace的用法示例。


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

示例1: objective_function

# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import Configuration [as 别名]
def objective_function(self, config, budget=100, **kwargs):

        assert 0 < budget <= 100  # check whether budget is in the correct bounds

        i = self.rng.randint(4)

        if type(config) == ConfigSpace.Configuration:
            k = json.dumps(config.get_dictionary(), sort_keys=True)
        else:
            k = json.dumps(config, sort_keys=True)

        valid = self.data[k]["valid_mse"][i]
        runtime = self.data[k]["runtime"][i]

        time_per_epoch = runtime / 100  # divide by the maximum number of epochs

        rt = time_per_epoch * budget

        self.X.append(config)
        self.y.append(valid[budget - 1])
        self.c.append(rt)

        return valid[budget - 1], rt 
开发者ID:automl,项目名称:nas_benchmarks,代码行数:25,代码来源:fcnet_benchmark.py

示例2: objective_function_learning_curve

# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import Configuration [as 别名]
def objective_function_learning_curve(self, config, budget=100):

        assert 0 < budget <= 100  # check whether budget is in the correct bounds

        index = self.rng.randint(4)

        if type(config) == ConfigSpace.Configuration:
            k = json.dumps(config.get_dictionary(), sort_keys=True)
        else:
            k = json.dumps(config, sort_keys=True)

        lc = [self.data[k]["valid_mse"][index][i] for i in range(budget)]
        runtime = self.data[k]["runtime"][index]

        time_per_epoch = runtime / 100 # divide by the maximum number of epochs

        rt = [time_per_epoch * (i + 1) for i in range(budget)]

        self.X.append(config)
        self.y.append(lc[-1])
        self.c.append(rt[-1])

        return lc, rt 
开发者ID:automl,项目名称:nas_benchmarks,代码行数:25,代码来源:fcnet_benchmark.py

示例3: objective_function_deterministic

# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import Configuration [as 别名]
def objective_function_deterministic(self, config, budget=100, index=0, **kwargs):

        assert 0 < budget <= 100  # check whether budget is in the correct bounds

        if type(config) == ConfigSpace.Configuration:
            k = json.dumps(config.get_dictionary(), sort_keys=True)
        else:
            k = json.dumps(config, sort_keys=True)

        valid = self.data[k]["valid_mse"][index]
        runtime = self.data[k]["runtime"][index]

        time_per_epoch = runtime / 100 # divide by the maximum number of epochs

        rt = time_per_epoch * budget

        self.X.append(config)
        self.y.append(valid[budget - 1])
        self.c.append(rt)

        return valid[budget - 1], rt 
开发者ID:automl,项目名称:nas_benchmarks,代码行数:23,代码来源:fcnet_benchmark.py

示例4: compute

# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import Configuration [as 别名]
def compute(self, config, budget, **kwargs):

		if self.config_as_array:
			c = CS.Configuration(self.configspace, values=config)
		else:
			c = config
		
		kwargs = {self.budget_name: self.budget_preprocessor(budget)}
		res = self.benchmark.objective_function(c, **kwargs)
		if self.measure_test_loss:
			del kwargs[self.budget_name]
			res['test_loss'] = self.benchmark.objective_function_test(c, **kwargs)['function_value']
		return({
			'loss': res['function_value'],
			'info': res
		}) 
开发者ID:automl,项目名称:HpBandSter,代码行数:18,代码来源:hpolibbenchmark.py

示例5: update

# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import Configuration [as 别名]
def update(self, config: CS.Configuration, reward: float, resource: int):
        """
        Registers new datapoint at config, with reward and resource.
        Note that in general, config should previously have been registered as
        pending (register_pending). If so, it is switched from pending
        to labeled. If not, it is considered directly labeled.

        :param config:
        :param reward:
        :param resource:
        """
        config_ext = self.configspace_ext.get(config, resource)
        crit_val = self.map_reward(reward)
        self.state_transformer.label_candidate(CandidateEvaluation(
            candidate=config_ext, metrics=dictionarize_objective(crit_val)))
        if self.debug_log is not None:
            config_id = self.debug_log.config_id(config_ext)
            msg = "Update for config_id {}: reward = {}, crit_val = {}".format(
                config_id, reward, crit_val)
            logger.info(msg) 
开发者ID:awslabs,项目名称:autogluon,代码行数:22,代码来源:gp_multifidelity_searcher.py

示例6: cleanup_pending

# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import Configuration [as 别名]
def cleanup_pending(self, config: CS.Configuration):
        """
        Removes all pending candidates whose configuration (i.e., lacking the
        resource attribute) is equal to config.
        This should be called after an evaluation terminates. For various
        reasons (e.g., termination due to convergence), pending candidates
        for this evaluation may still be present.
        It is also called for a failed evaluation.

        :param config: See above
        """
        config_dct = config.get_dictionary()

        def filter_pred(x: PendingEvaluation) -> bool:
            x_dct = self.configspace_ext.remove_resource(
                x.candidate, as_dict=True)
            return (x_dct != config_dct)

        self.state_transformer.filter_pending_evaluations(filter_pred) 
开发者ID:awslabs,项目名称:autogluon,代码行数:21,代码来源:gp_multifidelity_searcher.py

示例7: draw_random_candidate

# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import Configuration [as 别名]
def draw_random_candidate(
        blacklisted_candidates: Set[CS.Configuration],
        configspace_ext: ExtendedConfiguration,
        random_state: np.random.RandomState,
        target_resource: int) -> (CS.Configuration, CS.Configuration):
    config, config_ext = None, None
    for _ in range(GET_CONFIG_RANDOM_RETRIES):
        _config = configspace_ext.hp_ranges.random_candidate(random_state)
        # Test whether this config has already been considered
        _config_ext = configspace_ext.remap_resource(
            _config, target_resource)
        if _config_ext not in blacklisted_candidates:
            config = _config
            config_ext = _config_ext
            break
    if config is None:
        raise AssertionError(
            "Failed to sample a configuration not already chosen "
            "before. Maybe there are no free configurations left? "
            "The blacklist size is {}".format(len(blacklisted_candidates)))
    return config, config_ext 
开发者ID:awslabs,项目名称:autogluon,代码行数:23,代码来源:gp_multifidelity_searcher.py

示例8: decode_state

# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import Configuration [as 别名]
def decode_state(enc_state: dict, hp_ranges: HyperparameterRanges_CS) \
        -> TuningJobState:
    assert isinstance(hp_ranges, HyperparameterRanges_CS), \
        "Must have hp_ranges of HyperparameterRanges_CS type"
    config_space = hp_ranges.config_space

    def to_cs(x):
        return CS.Configuration(config_space, values=x)

    candidate_evaluations = [
        CandidateEvaluation(to_cs(x['candidate']), x['metrics'])
        for x in enc_state['candidate_evaluations']]
    failed_candidates = [to_cs(x) for x in enc_state['failed_candidates']]
    pending_evaluations = [
        PendingEvaluation(to_cs(x)) for x in enc_state['pending_evaluations']]
    return TuningJobState(
        hp_ranges=hp_ranges,
        candidate_evaluations=candidate_evaluations,
        failed_candidates=failed_candidates,
        pending_evaluations=pending_evaluations) 
开发者ID:awslabs,项目名称:autogluon,代码行数:22,代码来源:gp_fifo_searcher.py

示例9: from_ndarray

# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import Configuration [as 别名]
def from_ndarray(self, cand_ndarray: np.ndarray) -> Candidate:
        assert cand_ndarray.size == self._ndarray_size, \
            "Internal vector [{}] must have size {}".format(
                cand_ndarray, self._ndarray_size)
        cand_ndarray = cand_ndarray.reshape((-1,))
        assert cand_ndarray.min() >= 0. and cand_ndarray.max() <= 1., \
            "Internal vector [{}] must have entries in [0, 1]".format(
                cand_ndarray)
        # Deal with categoricals by using argmax
        srcvec = np.zeros(self.__len__(), dtype=cand_ndarray.dtype)
        srcvec.put(
            self.numer_src, cand_ndarray.take(self.numer_trg, mode='clip'),
            mode='clip')
        for srcpos, trgpos, card in zip(
                self.categ_src, self.categ_trg, self.categ_card):
            maxpos = cand_ndarray[trgpos:(trgpos + card)].argmax()
            srcvec[srcpos] = maxpos
        # Rest is dealt with by CS.Configuration
        return CS.Configuration(self.config_space, vector=srcvec) 
开发者ID:awslabs,项目名称:autogluon,代码行数:21,代码来源:hp_ranges.py

示例10: objective_function_test

# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import Configuration [as 别名]
def objective_function_test(self, config, **kwargs):

        if type(config) == ConfigSpace.Configuration:
            k = json.dumps(config.get_dictionary(), sort_keys=True)
        else:
            k = json.dumps(config, sort_keys=True)

        test = np.mean(self.data[k]["final_test_error"])
        runtime = np.mean(self.data[k]["runtime"])

        return test, runtime 
开发者ID:automl,项目名称:nas_benchmarks,代码行数:13,代码来源:fcnet_benchmark.py

示例11: compute_reward

# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import Configuration [as 别名]
def compute_reward(self, sample):
        config = ConfigSpace.Configuration(b.get_configuration_space(), vector=sample)
        y, c = self.bench.objective_function(config)
        fitness = 1 - float(y)
        return fitness 
开发者ID:automl,项目名称:nas_benchmarks,代码行数:7,代码来源:run_rl.py

示例12: __init__

# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import Configuration [as 别名]
def __init__(self, configspace, top_n_percent=10, update_after_n_points=50,
				 min_points_in_model = None,
				 *kwargs):
		"""
			Fits for each given budget a kernel density estimator on the best N percent of the
			evaluated configurations on this budget.


			Parameters:
			-----------
			configspace: ConfigSpace
				Configuration space object
			top_n_percent: int
				Determines the percentile of configurations that will be used as training data
				for the kernel density estimator, e.g if set to 10 the 10% best configurations will be considered
				for training.
			update_after_n_points: int
				Specifies after how many new observed points the kernel density will be retrained.
			min_points_in_model: int
				minimum number of datapoints needed to fit a model

		"""
		super(KernelDensityEstimator, self).__init__(**kwargs)

		self.top_n_percent = top_n_percent
		self.update_after_n_points = update_after_n_points
		self.configspace = configspace
		
		self.min_points_in_model = min_points_in_model
		if min_points_in_model is None:
			self.min_points_in_model = len(self.configspace.get_hyperparameters())+1


		# TODO: so far we only consider continuous configuration spaces
		self.var_type = "c" * len(self.configspace.get_hyperparameters())
		self.configs = dict()
		self.losses = dict()
		self.kde_models = dict() 
开发者ID:automl,项目名称:HpBandSter,代码行数:40,代码来源:kde.py

示例13: get_config

# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import Configuration [as 别名]
def get_config(self, budget):
		"""
			Function to sample a new configuration

			This function is called inside Hyperband to query a new configuration


			Parameters:
			-----------
			budget: float
				the budget for which this configuration is scheduled

			returns: config
				should return a valid configuration

		"""
		# No observations available for this budget sample from the prior
		if len(self.kde_models.keys()) == 0:
			return self.configspace.sample_configuration().get_dictionary()
		# If we haven't seen anything with this budget, we sample from the kde trained on the highest budget
		if budget not in self.kde_models.keys():
			budget = sorted(self.kde_models.keys())[-1]
		# TODO: This only works in continuous space and with gaussian kernels
		kde = self.kde_models[budget]
		idx = np.random.randint(0, len(self.kde_models[budget].data))

		vector = [sps.truncnorm.rvs(-m/bw,(1-m)/bw, loc=m, scale=bw) for m,bw in zip(self.kde_models[budget].data[idx], kde.bw)]
		
		if np.any(np.array(vector)>1) or np.any(np.array(vector)<0):
			raise RuntimeError("truncated normal sampling problems!")
		
		sample = ConfigSpace.Configuration(self.configspace, vector=vector)
		return sample.get_dictionary(), {} 
开发者ID:automl,项目名称:HpBandSter,代码行数:35,代码来源:kde.py

示例14: get_config

# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import Configuration [as 别名]
def get_config(self, budget):
        """
            function to sample a new configuration

            This function is called inside Hyperband to query a new configuration


            Parameters:
            -----------
            budget: float
                the budget for which this configuration is scheduled

            returns: config
                should return a valid configuration

        """
        self.lock.acquire()
        if not self.is_trained:
            c = self.config_space.sample_configuration().get_array()
        else:
            candidates = np.array([self.config_space.sample_configuration().get_array()
                                   for _ in range(self.n_candidates)])

            # We are only interested on the asymptotic value
            projected_candidates = np.concatenate((candidates, np.ones([self.n_candidates, 1])), axis=1)

            # Compute the upper confidence bound of the function at the asymptote
            m, v = self.model.predict(projected_candidates)

            ucb_values = m + self.delta * np.sqrt(v)
            print(ucb_values)
            # Sample a configuration based on the ucb values
            p = np.ones(self.n_candidates) * (ucb_values / np.sum(ucb_values))
            idx = np.random.choice(self.n_candidates, 1, False, p)

            c = candidates[idx][0]

        config = ConfigSpace.Configuration(self.config_space, vector=c)

        self.lock.release()
        return config.get_dictionary(), {} 
开发者ID:automl,项目名称:HpBandSter,代码行数:43,代码来源:lcnet.py

示例15: get_fANOVA_data

# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import Configuration [as 别名]
def get_fANOVA_data(self, config_space, budgets=None):

		import numpy as np
		import ConfigSpace as CS

		id2conf = self.get_id2config_mapping()

		if budgets is None:
			budgets = self.HB_config['budgets']

		if len(budgets)>1:
			config_space.add_hyperparameter(CS.UniformFloatHyperparameter('budget', min(budgets), max(budgets), log=True))
		
		hp_names = list(map( lambda hp: hp.name, config_space.get_hyperparameters()))

		all_runs = self.get_all_runs(only_largest_budget=False)


		all_runs=list(filter( lambda r: r.budget in budgets, all_runs))

		X = []
		y = []

		for r in all_runs:
			if r.loss is None: continue
			config = id2conf[r.config_id]['config']
			if len(budgets)>1:
				config['budget'] = r.budget

			config = CS.Configuration(config_space, config)

			X.append([config[n] for n in hp_names])
			y.append(r.loss)

		return(np.array(X), np.array(y), config_space) 
开发者ID:automl,项目名称:nasbench-1shot1,代码行数:37,代码来源:result.py


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