Пример #1
0
    def __init__(self, lower, upper):
        """
        Initialise the Sampler class.

        .. note::

            Currently only supports rectangular type restrictions on the
            parameter space

        Parameters
        ----------
        lower : array_like
            Lower or minimum bounds for the parameter space
        upper : array_like
            Upper or maximum bounds for the parameter space
        """
        self.lower = np.array(lower)
        self.upper = np.array(upper)
        self.dims = self.upper.shape[0]
        assert (self.lower.ndim == 1) and (self.upper.ndim == 1)
        assert self.lower.shape[0] == self.dims
        self.X = ArrayBuffer()
        self.y = ArrayBuffer()
        self.virtual_flag = ArrayBuffer()
        self.pending_results = {}
        self.n_tasks = None
Пример #2
0
def main():

    d = 20
    n_stack = 10000

    buf = ArrayBuffer()

    st = time.time()
    for i in range(n_stack):
        # buf.append(np.random.random())
        buf.append(np.random.random(d))  # NOQA we dont do anything with a

    ft = time.time()
    print('Efficient buffer took {0:.5f} seconds'.format(ft - st))

    a = buf()

    import IPython
    IPython.embed()
    import sys
    sys.exit()
    print(a)
    exit()

    st = time.time()
    b = np.zeros((0, d))
    for i in range(n_stack):
        b = np.vstack((b, np.random.random(d)))
    ft = time.time()
    print('Repeated Vstack took {0:.5f} seconds'.format(ft - st))

    st = time.time()
    b_buf = []
    for i in range(n_stack):
        b_buf.append(np.random.random(d))
        b = np.array(b_buf)
    ft = time.time()
    print('List buffering and casting took {0:.5f} seconds'.format(ft - st))
Пример #3
0
    def _update(self, uid, y_true):
        """
        Update a job with its observed value.

        Parameters
        ----------
        uid : str
            A hexadecimal ID that identifies the job to be updated
        y_true : float
            The observed value corresponding to the job identified by 'uid'

        Returns
        -------
        int
            Index location in the data lists 'Sampler.X' and
            'Sampler.y' corresponding to the job being updated
        """
        # Make sure the job uid given is valid
        if uid not in self.pending_results:
            warnings.warn('Result was not pending!')
        assert uid in self.pending_results

        # Kill the job and update collected data with true observation
        ind = self.pending_results.pop(uid)

        # If the user has been pushing Nones until now, we will init properly
        if self.n_tasks is None:
            self.n_tasks = len(np.atleast_1d(y_true))
            pending_count = len(self.y)
            self.y = ArrayBuffer()
            for _ in range(pending_count):
                self.y.append(np.zeros(self.n_tasks))

        self.y()[ind] = y_true
        self.virtual_flag()[ind] = False

        return ind