Example #1
0
    def test_latin_hypercube_equally_spaced(self):
        """Test that generate_latin_hypercube_points returns properly spaced points.

        Sampling from a latin hypercube results in a set of points that in each dimension are drawn
        uniformly from sub-intervals of the domain this tests that every sub-interval in each dimension
        contains exactly one point.

        """
        for domain in self.domains_to_test:
            for num_points in self.num_points_to_test:
                domain_bounds = domain._domain_bounds
                points = generate_latin_hypercube_points(
                    num_points, domain_bounds)

                for dim in xrange(domain.dim):
                    # This size of each slice
                    sub_domain_width = domain_bounds[dim].length / float(
                        num_points)
                    # Sort in dim dimension
                    points = sorted(points, key=lambda points: points[dim])
                    for i, point in enumerate(points):
                        # This point must fall somewhere within the slice
                        min_val = domain_bounds[dim].min + sub_domain_width * i
                        max_val = min_val + sub_domain_width
                        assert min_val <= point[dim] <= max_val
Example #2
0
    def test_latin_hypercube_within_domain(self):
        """Test that generate_latin_hypercube_points returns points within the domain."""
        for domain in self.domains_to_test:
            for num_points in self.num_points_to_test:
                points = generate_latin_hypercube_points(num_points, domain._domain_bounds)

                for point in points:
                    assert domain.check_point_inside(point) is True
Example #3
0
    def test_latin_hypercube_within_domain(self):
        """Test that generate_latin_hypercube_points returns points within the domain."""
        for domain in self.domains_to_test:
            for num_points in self.num_points_to_test:
                points = generate_latin_hypercube_points(num_points, domain._domain_bounds)

                for point in points:
                    assert domain.check_point_inside(point) is True
Example #4
0
    def generate_uniform_random_points_in_domain(self, num_points, random_source=None):
        r"""Generate ``num_points`` on a latin-hypercube (i.e., like a checkerboard).

        See python.geometry_utils.generate_latin_hypercube_points for more details.

        :param num_points: max number of points to generate
        :type num_points: int >= 0
        :param random_source: random source producing uniform random numbers (e.g., numpy.random.uniform) (UNUSED)
        :type random_source: callable yielding uniform random numbers in [0,1]
        :return: uniform random sampling of points from the domain
        :rtype: array of float64 with shape (num_points, dim)

        """
        # TODO(GH-56): Allow users to pass in a random source.
        return generate_latin_hypercube_points(num_points, self._domain_bounds)
Example #5
0
    def test_latin_hypercube_equally_spaced(self):
        """Test that generate_latin_hypercube_points returns properly spaced points.

        Sampling from a latin hypercube results in a set of points that in each dimension are drawn
        uniformly from sub-intervals of the domain this tests that every sub-interval in each dimension
        contains exactly one point.

        """
        for domain in self.domains_to_test:
            for num_points in self.num_points_to_test:
                domain_bounds = domain._domain_bounds
                points = generate_latin_hypercube_points(num_points, domain_bounds)

                for dim in xrange(domain.dim):
                    # This size of each slice
                    sub_domain_width = domain_bounds[dim].length / float(num_points)
                    # Sort in dim dimension
                    points = sorted(points, key=lambda points: points[dim])
                    for i, point in enumerate(points):
                        # This point must fall somewhere within the slice
                        min_val = domain_bounds[dim].min + sub_domain_width * i
                        max_val = min_val + sub_domain_width
                        assert min_val <= point[dim] <= max_val