In [1]:
import random
import numpy as np
import plotly.plotly as py
import plotly.graph_objs as go
import plotly.offline as offline
offline.init_notebook_mode(connected=True)
Set the sample size:
In [2]:
sample_size = 1000
In [3]:
def plot_3d_scatter(X, Y, Z, filename):
trace = go.Scatter3d(
x=X,
y=Y,
z=Z,
mode='markers',
marker=dict(
size=4,
#line=dict(
# color='rgba(217, 217, 217, 0.14)',
# width=0.5
#),
opacity=0.5
)
)
data = [trace]
layout = go.Layout(
margin=dict(
l=0,
r=0,
b=0,
t=0
)
)
fig = go.Figure(data=data, layout=layout)
return py.iplot(fig, filename=filename)
In [4]:
X = [random.uniform(0, 1) for i in range(sample_size)]
Y = [random.uniform(0, 1) for i in range(sample_size)]
Z = [random.uniform(0, 1) for i in range(sample_size)]
plot_3d_scatter(X, Y, Z, 'paramspace-uniform')
Out[4]:
Set the step size. I'm using a larger value than in the parameter-space-coverage notebook (0.05 compared to 0.01) so that the quantization effect is more visible in 3 dimensions.
In [5]:
step_size = 0.05
In [6]:
all_points = []
for x in np.arange(0, 1, step_size):
for y in np.arange(0, 1, step_size):
for z in np.arange(0, 1, step_size):
all_points.append((x, y, z))
print("Number of parameter value combinations: {:,}".format(len(all_points)))
sample = random.sample(all_points, sample_size)
X, Y, Z = zip(*sample) # unzip sample
plot_3d_scatter(X, Y, Z, 'paramspace-stepped')
Out[6]: