dora/active_sampling/delaunay_sampler.py
def pick(self):
        """
        Pick the next feature location for the next observation to be taken.

        This uses the recursive Delaunay subdivision algorithm.

        Returns
        -------
        numpy.ndarray
            Location in the parameter space for the next observation to be
            taken
        str
            A random hexadecimal ID to identify the corresponding job
        """
        n = len(self.X)

        # -- note that we are assuming the points in X are not reordered by
        # the scipy Delaunay implementation

        n_corners = 2 ** self.dims
        if n < n_corners + 1:

            # Bootstrap with a regular sampling strategy to get it started
            xq = grid_sample(self.lower, self.upper, n)
            yq_exp = [0.]
        else:

            X = self.X()  # calling returns the value as an array
            y = self.y()
            virtual = self.virtual_flag()

            # Otherwise, recursive subdivide the edges with the Delaunay model
            if not self.triangulation:
                self.triangulation = ScipyDelaunay(X, incremental=True)

            # Weight by hyper-volume
            simplices = [tuple(s) for s in self.triangulation.vertices]
            cache = self.simplex_cache

            def get_value(s):

                # Computes the sample value as:
                #   hyper-volume of simplex * variance of values in simplex
                ind = list(s)
                value = (np.var(y[ind]) + self.explore_priority) * \
                    np.linalg.det((X[ind] - X[ind[0]])[1:])
                if not np.max(virtual[ind]):
                    cache[s] = value
                return value

            # Mostly the simplices won't change from call to call - cache!
            sample_value = [cache[s] if s in cache else get_value(s)
                            for s in simplices]

            # alternatively, a nicely vectorised computation might work here
            # profile and check what the bottleneck is

            # Extract the points in the highest value simplex
            simplex_indices = list(simplices[np.argmax(sample_value)])
            simplex = X[simplex_indices]
            simplex_v = y[simplex_indices]

            # Weight the position in this simplex based on value deviation
            eps = 1e-3
            weight = eps + np.abs(simplex_v - np.mean(simplex_v))
            weight /= np.sum(weight)
            xq = np.sum(weight * simplex, axis=0)  # dot
            yq_exp = np.sum(weight * simplex_v, axis=0)

            self.triangulation.add_points(xq[np.newaxis, :])  # incremental

        uid = Sampler._assign(self, xq, yq_exp)
        return xq, uid

        Pick the next feature location for the next observation to be taken.

        This uses the recursive Delaunay subdivision algorithm.

        Returns
        -------
        numpy.ndarray
            Location in the parameter space for the next observation to be
            taken
        str
            A random hexadecimal ID to identify the corresponding job
        
Pick the next feature location for the next observation to be taken.
This uses the recursive Delaunay subdivision algorithm.

Returns

numpy.ndarray
Location in the parameter space for the next observation to be
taken
str
A random hexadecimal ID to identify the corresponding job
Pick the next feature location for the next observation to be taken . This uses the recursive Delaunay subdivision algorithm . Returns numpy . ndarray Location in the parameter space for the next observation to be taken str A random hexadecimal ID to identify the corresponding job
def pick(self):
        n = len(self.X)
        n_corners = 2 ** self.dims
        if n < n_corners + 1:
            xq = grid_sample(self.lower, self.upper, n)
            yq_exp = [0.]
        else:
            X = self.X()  
            y = self.y()
            virtual = self.virtual_flag()
            if not self.triangulation:
                self.triangulation = ScipyDelaunay(X, incremental=True)
            simplices = [tuple(s) for s in self.triangulation.vertices]
            cache = self.simplex_cache
            def get_value(s):
                ind = list(s)
                value = (np.var(y[ind]) + self.explore_priority) * \
                    np.linalg.det((X[ind] - X[ind[0]])[1:])
                if not np.max(virtual[ind]):
                    cache[s] = value
                return value
            sample_value = [cache[s] if s in cache else get_value(s)
                            for s in simplices]
            simplex_indices = list(simplices[np.argmax(sample_value)])
            simplex = X[simplex_indices]
            simplex_v = y[simplex_indices]
            eps = 1e-3
            weight = eps + np.abs(simplex_v - np.mean(simplex_v))
            weight /= np.sum(weight)
            xq = np.sum(weight * simplex, axis=0)  
            yq_exp = np.sum(weight * simplex_v, axis=0)
            self.triangulation.add_points(xq[np.newaxis, :])  
        uid = Sampler._assign(self, xq, yq_exp)
        return xq, uid
def pick ( self ) : n = len ( self . X ) n_corners = 2 ** self . dims if n < n_corners + 1 : xq = grid_sample ( self . lower , self . upper , n ) yq_exp = [ 0. ] else : X = self . X ( ) y = self . y ( ) virtual = self . virtual_flag ( ) if not self . triangulation : self . triangulation = ScipyDelaunay ( X , incremental = True ) simplices = [ tuple ( s ) for s in self . triangulation . vertices ] cache = self . simplex_cache def get_value ( s ) : ind = list ( s ) value = ( np . var ( y [ ind ] ) + self . explore_priority ) * np . linalg . det ( ( X [ ind ] - X [ ind [ 0 ] ] ) [ 1 : ] ) if not np . max ( virtual [ ind ] ) : cache [ s ] = value return value sample_value = [ cache [ s ] if s in cache else get_value ( s ) for s in simplices ] simplex_indices = list ( simplices [ np . argmax ( sample_value ) ] ) simplex = X [ simplex_indices ] simplex_v = y [ simplex_indices ] eps = 1e-3 weight = eps + np . abs ( simplex_v - np . mean ( simplex_v ) ) weight /= np . sum ( weight ) xq = np . sum ( weight * simplex , axis = 0 ) yq_exp = np . sum ( weight * simplex_v , axis = 0 ) self . triangulation . add_points ( xq [ np . newaxis , : ] ) uid = Sampler . _assign ( self , xq , yq_exp ) return xq , uid
Pick the next feature location for the next observation to be taken.
Pick the next feature location for the next observation to be taken .
"""
        Pick the next feature location for the next observation to be taken.

        This uses the recursive Delaunay subdivision algorithm.

        Returns
        -------
        numpy.ndarray
            Location in the parameter space for the next observation to be
            taken
        str
            A random hexadecimal ID to identify the corresponding job
        """ # -- note that we are assuming the points in X are not reordered by # the scipy Delaunay implementation # Bootstrap with a regular sampling strategy to get it started # calling returns the value as an array # Otherwise, recursive subdivide the edges with the Delaunay model # Weight by hyper-volume # Computes the sample value as: #   hyper-volume of simplex * variance of values in simplex # Mostly the simplices won't change from call to call - cache! # alternatively, a nicely vectorised computation might work here # profile and check what the bottleneck is # Extract the points in the highest value simplex # Weight the position in this simplex based on value deviation # dot # incremental
self