Beispiel #1
0
    def extract_result(self):
        x_min, _ = stochastic_optimization(self.target_model.predict_mean,
                                           self.target_model.bounds,
                                           seed=self.seed)

        batch_min = arr2d_to_batch(x_min, self.parameter_names)
        outputs = arr2d_to_batch(self.target_model.X, self.parameter_names)
        outputs[self.target_name] = self.target_model.Y

        return OptimizationResult(x_min=batch_min,
                                  outputs=outputs,
                                  **self._extract_result_kwargs())
    def prepare_new_batch(self, batch_index):
        """Prepare values for a new batch.

        Parameters
        ----------
        batch_index : int
            next batch_index to be submitted

        Returns
        -------
        batch : dict or None
            Keys should match to node names in the model. These values will override any
            default values or operations in those nodes.

        """
        t = self._get_acquisition_index(batch_index)

        # Check if we still should take initial points from the prior
        if t < 0:
            return

        # Take the next batch from the acquisition_batch
        acquisition = self.state['acquisition']
        if len(acquisition) == 0:
            acquisition = self.acquisition_method.acquire(self.acq_batch_size, t=t)

        batch = arr2d_to_batch(acquisition[:self.batch_size], self.parameter_names)
        self.state['acquisition'] = acquisition[self.batch_size:]

        return batch
    def prepare_new_batch(self, batch_index):
        """Prepare values for a new batch.

        Parameters
        ----------
        batch_index : int
            next batch_index to be submitted

        Returns
        -------
        batch : dict or None
            Keys should match to node names in the model. These values will override any
            default values or operations in those nodes.

        """
        if self.state['round'] == 0:
            # Use the actual prior
            return

        # Sample from the proposal, condition on actual prior
        params = GMDistribution.rvs(*self._gm_params, size=self.batch_size,
                                    prior_logpdf=self._prior.logpdf,
                                    random_state=self._round_random_state)

        batch = arr2d_to_batch(params, self.parameter_names)
        return batch
Beispiel #4
0
    def prepare_new_batch(self, batch_index):
        if self.state['round'] == 0:
            # Use the actual prior
            return

        # Sample from the proposal
        params = GMDistribution.rvs(*self._gm_params, size=self.batch_size,
                                    random_state=self._round_random_state)

        batch = arr2d_to_batch(params, self.parameter_names)
        return batch
Beispiel #5
0
    def prepare_new_batch(self, batch_index):
        t = self._get_acquisition_index(batch_index)

        # Check if we still should take initial points from the prior
        if t < 0: return

        # Take the next batch from the acquisition_batch
        acquisition = self.state['acquisition']
        if len(acquisition) == 0:
            acquisition = self.acquisition_method.acquire(self.acq_batch_size, t=t)

        batch = arr2d_to_batch(acquisition[:self.batch_size], self.parameter_names)
        self.state['acquisition'] = acquisition[self.batch_size:]

        return batch
Beispiel #6
0
    def prepare_new_batch(self, batch_index):
        """Prepare values for a new batch.

        Parameters
        ----------
        batch_index: int

        Returns
        -------
        batch: dict

        """
        t = batch_index - self.n_initial_evidence
        if t < 0:  # Sample parameter values from the model priors
            return

        # Acquire parameter values from the acquisition function
        acquisition = self.acquisition_method.acquire(self.batch_size, t)
        return arr2d_to_batch(acquisition, self.parameter_names)