def generate_minimax_square(N, seed):
    np.random.seed(seed)
    domain = psdr.BoxDomain(0 * np.zeros(2), np.ones(2))

    # Generate a design
    try:
        X = psdr.minimax_lloyd(domain,
                               N,
                               maxiter=500,
                               xtol=1e-9,
                               verbose=False)

        # Compute the disc diameter to cover the domain
        V = psdr.voronoi_vertex(domain, X)
        D = psdr.cdist(X, V)
        radius = np.max(np.min(D, axis=0))

        # save the file
        design = {
            'author': 'Jeffrey M. Hokanson',
            'notes':
            f'psdr.minimax_lloyd seed={seed}, maxiter=500, xtol = 1e-9',
            'objective': 'minimax',
            'metric': 'l2',
            'domain': 'square',
            'radius': radius,
            'X': X.tolist()
        }
    except:
        design = {'radius': np.inf}

    print(f"M: {N:4d} \t seed {seed:4d} finished")
    return design
示例#2
0
def generate_minimax_square(N = 10, seed = 0):
	domain = psdr.BoxDomain(0*np.zeros(2), np.ones(2))

	# Generate a design
	X = psdr.minimax_lloyd(domain, N, maxiter = 500, xtol = 1e-7, verbose = True)

	#X = domain.sample(N)

	# Compute the disc diameter to cover the domain
	V = psdr.voronoi_vertex(domain, X)
	D = psdr.cdist(X, V)
	radius = np.max(np.min(D, axis= 0))

	# save the file
	design = {
		'author': 'Jeffrey M. Hokanson',
		'objective': 'minimax',
		'metric': 'l2',
		'domain': 'square',
		'radius': radius,
		'X': X.tolist()
	}

	with open('square_%04d.dat' % N, 'w') as f:
		json.dump(design, f)	
def test_minimax_l2_design(fname):
    r""" This checks the design for consistency. 
	It does not check if there is an improvment
	"""

    print(f"Loading design '{fname}'")

    design = get_new_design(fname)

    if design['domain'] == 'square':
        domain = psdr.BoxDomain(np.zeros(2), np.ones(2))
    else:
        raise AssertionError('domain type "%s" not recognized' %
                             design['domain'])

    assert design[
        'metric'] == 'l2', "Expected metric 'l2', got '%s'" % design['metric']
    assert design[
        'objective'] == 'minimax', "Expected objective 'minimax', got '%s'" % design[
            'objective']

    X = np.array(design['X'])
    M = int(re.search(r'_(.*?).json', fname).group(1))

    assert X.shape[
        0] == M, f"Number of points does not match the file name: name suggests {M}, files has {X.shape[0]}"
    assert X.shape[1] == len(
        domain), "Points are in a different dimensional space than the domain"
    assert np.all(domain.isinside(X)), "All points must be inside the domain"

    # Check the objective value
    V = psdr.voronoi_vertex(domain, X)
    D = psdr.cdist(X, V)
    radius = np.max(np.min(D, axis=0))

    print("Measured radius", '%20.15e' % radius)
    print("Reported radius", '%20.15e' % design['radius'])
    assert np.isclose(radius, design['radius'], rtol=1e-10, atol=1e-10)
def score_design(Xhat):
    V = psdr.voronoi_vertex(domain, Xhat, L)
    D = psdr.cdist(Xhat, V, L)
    return np.max(np.min(D, axis=0))
示例#5
0
def check_vertex(dom, Xhat, L = None):
	V = voronoi_vertex(dom, Xhat, L = L )
	check_voronoi(dom, Xhat, V, L = L)
示例#6
0
def test_voronoi_vertex(m = 2, M = 10):
	domain = psdr.BoxDomain(-1*np.ones(m), np.ones(m))
	Xhat = domain.sample_grid(2)
	
	V = psdr.voronoi_vertex(domain, Xhat)