def _generate_segments(self, n_segments, n_superpositions=5):
# Assume that the actual surface is a superposition of sinusoid
# functions from which sample n_segments points and connect those
# linearly
# Generate sinusoids of the form -5 * sin(a * x + b)
a = np.logspace(0, 0.5, n_superpositions)
b = (0.25 * self.random_state.rand(n_superpositions) - 0.125) * np.pi
# Generate x and y components of segments
x = np.hstack((np.sort(self.random_state.rand(n_segments) * 8.0)))
y = (-5 * np.sin(a * x[:, None] + b)).mean(axis=1)
# Start at (0, 0)
x[0] = y[0] = 0
# Planar segment at the end which is long enough to avoid shooting
# over the border
x[-1] = 100.0
y[-1] = y[-2]
return np.vstack((x, y)).T
评论列表
文章目录