コード例 #1
0
    def __init__(self, *args, **kwargs):
        Object.__init__(self, *args, **kwargs)
        self.num_generated = 0
        self.param_space = None
        self._params = None
        self._values = None
        self.SUBMITTED_PARAMS = []
        self.RECEIVED_VALUES = []

        # rm all those vars in config that are not needed/used by ScipyWrapper
        for var in ['goal', 'init_guess', 'random_seed']:
            if var in kwargs:
                del kwargs[var]
        self.config = Config(from_dict=kwargs)

        # self.goal is an abstract attribute that needs to be defined by the subclasses of AbstractPlanner
        # Since all planner wrappers are implemented in minimization mode, we flip the measurements if we want to
        # perform a maximization
        if self.goal == 'minimize':
            self.flip_measurements = False
        elif self.goal == 'maximize':
            self.flip_measurements = True
        else:
            message = f'attribute `goal` can only be "minimize" or "maximize". "{self.goal}" is not a valid value'
            Logger.log(message, 'ERROR')
コード例 #2
0
    def __init__(self,
                 planner,
                 emulator=None,
                 surface=None,
                 campaign=Campaign(),
                 database=None):
        """ The Evaluator does higher level operations that Planners and 
        Emulators do not do on their own. For instance, communicating parameters 
        and measurements to each other, keeping track of them ensuring they 
        match, and storing these in a Campaign object. All this can also be done 
        by the user using planner, emulator and campaign objects, which might 
        allow more customization. However, Evaluator provides a convenient 
        higher-level interface for common optimization tasks.

        Args:
            planner (Planner): an instance of a Planner.
            emulator (Emulator): an instance of a trained Emulator.
            surface (Surface): an instance of a Surface
            campaign (Campaign): an instance of a Campaign. By default, a new 
                Campaign instance is created. If this is set to None, no campaign 
                info will be stored.
            database (object): ...
        """
        Object.__init__(**locals())

        if emulator is not None:
            assert surface is None
            self.emulator_type = 'numerical'
        elif surface is not None:
            assert emulator is None
            self.emulator_type = 'analytic'
            self.emulator = surface
        else:
            Logger.log('One of emulator or surface needs to be provided',
                       'FATAL')

#        if isinstance(self.emulator, Emulator):
#            self.emulator_type = 'numerical'
#        elif isinstance(self.emulator, Surface):
#            self.emulator_type = 'analytic'

# provide the planner with the parameter space.
# NOTE: right now, outside of Evaluator, the param_space for a planner
#       needs to be set "manually" by the user
        self.planner.set_param_space(
            self.emulator.param_space
        )  # param space in emulator as it originates from dataset

        if self.campaign is not None:
            self.campaign.set_planner_specs(planner)
            self.campaign.set_emulator_specs(emulator)
コード例 #3
0
	def __init__(self, array=None, dict=None, param_space=None):
		"""
        Args:
            array (array):
            dict (dict): dictionary with parameter names and values.
            param_space (ParameterSpace): ParameterSpace instance. This is typically defined as part of a Dataset and
                is also inherited by Emulator. If a `param_space` is defined, `info_dict` will be checked to ensure the
                provided keys match those in `param_space`, otherwise `info_dict` is accepted as is. Default is None.
        """
		from olympus.campaigns import ParameterSpace
		self.param_space = ParameterSpace()
		Object.__init__(self)

		if array is not None and param_space is not None:
			_ = self.from_array(array=array, param_space=param_space)
		elif dict is not None:
			_ = self.from_dict(info_dict=dict, param_space=param_space)
コード例 #4
0
 def to_dict(self):
     return Object.to_dict(self, exclude=["func"])
コード例 #5
0
 def __init__(self, *args, **kwargs):
     Object.__init__(self, *args, **kwargs)
コード例 #6
0
    def __init__(
        self,
        dataset=None,
        model=None,
        feature_transform="identity",
        target_transform="identity",
    ):
        """Experiment emulator.

        Args:
            dataset (str, Dataset): dataset used to train a model. Either a string, in which case a standard dataset
                is loaded, or a Dataset object. To see the list of available datasets ...
            model (str, Model): the model used to create the emulator. Either a string, in which case a default model
                is loaded, or a Model object. To see the list of available models ...
            feature_transform (str, list): the data transform to be applied to the features. See DataTransformer for the
                available transformations.
            target_transform (str, list): the data transform to be applied to the targets. See DataTransformer for the
                available transformations.
        """

        # ------------------------------------------------------------
        # if dataset and model are strings ==> load emulator from file
        # ------------------------------------------------------------
        if type(dataset) == str and type(model) == str:
            # check dataset string
            _validate_dataset_args(kind=dataset,
                                   data=None,
                                   columns=None,
                                   target_names=None)
            # check model string
            _validate_model_kind(model)
            Logger.log(
                f"Loading emulator using a {model} model for the dataset {dataset}...",
                "INFO",
            )
            self._load(f"{__emulator_path__}/emulator_{dataset}_{model}")

        # -----------------------------------------
        # otherwise, assume it is a custom emulator
        # -----------------------------------------
        else:
            Object.__init__(**locals())

            if dataset is not None:
                self._set_dataset(dataset)
            if model is not None:
                self._set_model(model)

            # other attributes we will use
            self._version = __version__
            self._ghost_model = deepcopy(self.model)
            self.is_trained = False
            self.cross_val_performed = False
            self.cv_scores = None
            self.model_scores = None
            self.emulator_to_save = None
            self.feature_transformer = DataTransformer(
                transformations=self.feature_transform)
            self.target_transformer = DataTransformer(
                transformations=self.target_transform)

        # create tmp dir to store model files
        # also if we are loading a model (the user could call 'train' again)
        self._scratch_dir = TemporaryDirectory(dir=f"{__scratch__}",
                                               prefix="emulator_")
コード例 #7
0
 def __init__(self, *args, **kwargs):
     Object.__init__(self, *args, **kwargs)
     self._create_param_space(self.param_dim)
     self._create_value_space()