Skip to content

Instantly share code, notes, and snippets.

@pqcfox
Created August 8, 2020 03:08
Show Gist options
  • Save pqcfox/ec8b0922ee1cdabbc913b2cdc5ab5d29 to your computer and use it in GitHub Desktop.
Save pqcfox/ec8b0922ee1cdabbc913b2cdc5ab5d29 to your computer and use it in GitHub Desktop.
A quick script to plot the density of points when placing points in [-1, 1] greedily to maximize distance from previous points.
import numpy as np
from scipy import optimize
from tqdm import tqdm
from matplotlib import pyplot as plt
NUM_POINTS = 1000
STEP = 0.001
BIN_SIZE = 0.05
grid = np.reshape(np.arange(-1, 1 + STEP, STEP), (-1, 1))
points = [-1]
for _ in tqdm(range(NUM_POINTS)):
ps = np.reshape(points, (1, -1))
dists = np.abs(ps - grid)
prods = np.prod(dists, axis=1)
max_ind = np.argmax(prods)
points.append(grid[max_ind, 0])
bins = np.arange(-1, 1+BIN_SIZE, BIN_SIZE)
plt.hist(points, bins=bins)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment