In [1]:
# Code attribution: Yiyin Shen, Tyler Caraza-Harter
# Imports
import numpy
import matplotlib.pyplot as plt
In [2]:
# Generate random points in a circle (this is NOT correct)
rng = numpy.random.default_rng(seed = 42)
r = rng.random(1000)
t = rng.uniform(0, 2 * numpy.pi, 1000)
fig, ax = plt.subplots()
ax.scatter(r * numpy.sin(t), r * numpy.cos(t))
ax.set_aspect("equal", "box")
In [3]:
# Try again (this is also NOT correct)
x = rng.uniform(-1, 1, 1000)
y = rng.uniform(-1, 1, 1000) * numpy.sqrt(1 - x * x)
fig, ax = plt.subplots()
ax.scatter(x, y)
ax.set_aspect("equal", "box")
In [4]:
# Try again, again
r = rng.random(1000)
t = rng.uniform(0, 2 * numpy.pi, 1000)
fig, ax = plt.subplots()
ax.scatter(numpy.sqrt(r) * numpy.sin(t), numpy.sqrt(r) * numpy.cos(t))
ax.set_aspect("equal", "box")
In [5]:
# Generate random points in a simplex (sum of numbers equals to 1) (this is NOT correct)
x = rng.random((1000, 3))
x = x / numpy.sum(x, axis = 1).reshape(-1, 1)
fig = plt.figure()
ax = fig.add_subplot(projection = '3d')
ax.scatter(x[:, 0], x[:, 1], x[:, 2], depthshade = False)
ax.view_init(45, 45)
In [6]:
# Try again (this is also NOT correct)
x = rng.random((1000, 3))
x[:, 1] = numpy.minimum(x[:, 1], 1 - x[:, 0])
x[:, 2] = numpy.maximum(1 - x[:, 0] - x[:, 1], 0)
fig = plt.figure()
ax = fig.add_subplot(projection = '3d')
ax.scatter(x[:, 0], x[:, 1], x[:, 2], depthshade = False)
ax.view_init(45, 45)
In [7]:
# Try again, again
x = numpy.log(rng.random((1000, 3)))
x = x / numpy.sum(x, axis = 1).reshape(-1, 1)
fig = plt.figure()
ax = fig.add_subplot(projection = '3d')
ax.scatter(x[:, 0], x[:, 1], x[:, 2], depthshade = False)
ax.view_init(45, 45)