gpp_domain_test

Contents:

gpp_domain_test.hpp

Tests for gpp_domain.hpp: classes to represent different domains and utilities for operating on them.

namespace optimal_learning

Macro to allow restrict as a keyword for C++ compilation and CUDA/nvcc compilation. See related entry in gpp_common.hpp for more details.

gpp_domain_test.cpp

This file contains functions for testing the functions and classes in gpp_domain.hpp.

It has several templated test functions (on DomainTestFixture) for:

  • CheckPointInDomain: specify a domain, point list, and truth values. checks that points are/are not inside
  • GeneratePointInDomain: generates some random points, checks that they are inside the domain
  • GenerateUniformPointsInDomain: generates uniformly distributed points, checks that they are inside the domain TODO(GH-128): Test whether computed point distribution is actually uniform
  • LimitUpdate: starting from points within the domain, checks that:
    • updates to another point in the domain remain unchanged
    • updates to a point outside the domain are limited such that the new endpoint is in the domain

These are all wrapper’d in RunDomainTests<>(), which is templated on DomainTestFixture. A similar batch of tests exists for RepeatedDomain and is accessed through RunRepeatedDomainTests<>(), which is also templated on DomainTestFixture.

To use these tests, define a DomainTestFixture struct with the following fields (and values for them):

struct SomeDomainTestFixture final {
  using DomainType = SomeDomain;  // the domain class we want to test

  // use with CheckPointInsideTest
  int kDimCheckPointInside;  // number of dimensions for CheckPointInside test
  vector<double> kDomainBoundsCheckPointInside;  // arg1 to SomeDomain(arg1, dim) constructor
  vector<double> kPointsCheckPointsInside;  // points at which to check inside-ness
  int kNumPointsCheckPointInside;  // number of points to check
  vector<bool> kTruthCheckPointsInside;  // truth for whether each point is inside/outside

  // use with GeneratePointInDomainTest, GenerateUniformPointsInDomainTest, LimitUpdateTest
  int kDimPointGeneration;  // number of dimensions for random point generation
  // ranges for lower, upper bounds of tensor product domain components for random point generation (if needed)
  boost::uniform_real<double> kUniformDoubleDomainLowerBound;
  boost::uniform_real<double> kUniformDoubleDomainUpperBound;
};

Each test function accepts a “const DomainTestFixture&” input from which we access the aforementioned parameters.

See below for examples.

Variables

constexpr int kStep

On the kStep-th call to GenerateUniformPointsInDomain, that function generates num_points / 2 points instead of num_points.

int num_calls

number of times GenerateUniformPointsInDomain has been called

double counter

number of coordinates generated

const int kDimCheckPointInside

Dimension to use with CheckPointInsideTest.

const std::vector< ClosedInterval > kDomainBoundsCheckPointInside

Domain bounds (min, max pairs)

const std::vector< double > kPointsCheckPointInside

points to test PointsCheckPointInside with; truth values in kTruthCheckPointInside

const std::vector< bool > kTruthCheckPointInside

Truth for whether each point of kPointsCheckPointInside is inside/outside the domain.

const int kNumPointsCheckPointInside

number of points to check

const int kDimPointGeneration

dimension of points to use in GeneratePointInDomainTest

const boost::uniform_real < double > kUniformDoubleDomainLowerBound

range to draw interval ower bounds from

const boost::uniform_real < double > kUniformDoubleDomainUpperBound

range to draw interval upper bounds from

namespace optimal_learning

Macro to allow restrict as a keyword for C++ compilation and CUDA/nvcc compilation. See related entry in gpp_common.hpp for more details.

Functions

int DomainTests()

Tests the functionality of the various domain classes in gpp_domain.hpp; e.g., update limiting, in/out tests, random point generation, etc.

Returns:
number of test failures: 0 if all domain functions are working properly