How to use the adaptive.priority_queue.Queue function in adaptive

To help you get started, we’ve selected a few adaptive examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-adaptive / adaptive / adaptive / learner / new_learnerND.py View on Github external
# but which have now been removed to make way for others.
            temp_subdomains = to_add.intersection(old_subdomains)
            # We no longer want to add subdomains that have now been removed,
            # and we want to add the new subdomains.
            to_add -= temp_subdomains
            to_add.update(new_subdomains)
            # We do not want to remove subdomains that were produced on a
            # prior iteration of this loop, as these will not be in the queue.
            to_remove.update(old_subdomains - temp_subdomains)

        for subdomain in to_remove:
            self.queue.remove(subdomain)
            del self.losses[subdomain]

        if need_loss_update:
            self.queue = Queue(
                (subdomain, self.priority(subdomain))
                for subdomain in itertools.chain(self.queue.items(), to_add)
            )
        else:
            # Insert the newly created subdomains into the queue.
            for subdomain in to_add:
                self.queue.insert(subdomain, priority=self.priority(subdomain))

            # If the loss function depends on data in neighboring subdomains then
            # we must recompute the priorities of all neighboring subdomains of
            # the subdomains we just added.
            if self.loss_function.n_neighbors > 0:
                subdomains_to_update = set()
                for subdomain in to_add:
                    subdomains_to_update.update(
                        self.domain.neighbors(subdomain, self.loss_function.n_neighbors)
github python-adaptive / adaptive / adaptive / learner / new_learnerND.py View on Github external
self.losses = dict()

        # We must wait until the boundary points have been evaluated before we can
        # set these attributes.
        self._initialized = False
        # The dimension of the output space.
        self.vdim = None
        # The maximum and minimum values of 'f' seen thus far.
        self.codomain_bounds = None
        # The difference between the maximum and minimum of 'f' at the last
        # time all the losses were recomputed.
        self.codomain_scale_at_last_update = None

        # A priority queue of subdomains, which is used to determine where to add
        # points.
        self.queue = Queue()
        for subdomain in self.domain.subdomains():
            self.queue.insert(subdomain, priority=self.priority(subdomain))
github python-adaptive / adaptive / adaptive / learner / new_learnerND.py View on Github external
except TypeError:  # Trying to take the length of a number
            self.vdim = 1

        # Generate new subdomains using any evaluated points, skipping the boundary
        # points (these are already vertices in the domain) and discarding any points
        # that are outside the domain.
        xs = list(x for x in self.data.keys() if x not in self.boundary_points)
        if xs:
            xs = np.array(xs)
            xs = xs[self.domain.encloses(xs)]
            for x in xs:
                self.domain.split_at(x)

        # Recompute all the losses from scratch
        self.losses = dict()
        self.queue = Queue(
            (subdomain, self.priority(subdomain))
            for subdomain in self.domain.subdomains()
        )