Created
August 8, 2020 03:08
-
-
Save pqcfox/bae4723add37b69427e81d7a49fb31ae 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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