0

There are two semi-circles of width thk with inner radius rad, separated by sep as shown (red is -1 and blue is + 1). The center of the top semi-circle is aligned with the middle of the edge of the bottom semi-circle. This task is linearly separable when sep >= 0, and not so for sep <0. Set rad = 10, thk = 5 and sep = 5 . Then, generate 2,000 examples uniformly, which means you will have approximately 1,000 examples for each class.

Figure Describing the problem:

Figure Describing the problem

Can someone help me in generating such a dataset?

L_J
  • 2,351
  • 10
  • 23
  • 28

1 Answers1

2

We start by defining the parameters:

n_data_points = 2000

rad = 0.6
thk = 0.2
sep = 0.1

Now we calculate the centers of the two semicircles:

c1 = np.array([(rad+thk)/2, sep/2])
c2 =  np.array([-(rad+thk)/2, -sep/2])

It is time to generate data! we do so by randomizing via np.random:

# We use random radius in the interval [rad, rad+thk]
#  and random angles from 0 to pi radians.
r1 = np.random.rand(n_data_points)*thk+rad
a1 = np.random.rand(n_data_points)*np.pi

r2 = np.random.rand(n_data_points)*thk+rad
a2 = np.random.rand(n_data_points)*np.pi+np.pi

# In order to plot it we convert it to cartesian:
p1 = np.array((r1*np.cos(a1), r1*np.sin(a1)))
p2 = np.array((r2*np.cos(a2), r2*np.sin(a2)))

We are so far creating centered data. We apply now the previously calculated centers to shift the data:

x1, y1 = (p1[0] - c1[0], p1[1] - c1[1])
x2, y2 = (p2[0] - c2[0], p2[1] - c2[1])

We can now plot the result!

import matplotlib.pyplot as plt
plt.scatter(x1, y1, marker='.', linewidths=0.1)
plt.scatter(x2, y2, marker='.', linewidths=0.1)
plt.show()

Final Dataset

ibarrond
  • 6,617
  • 4
  • 26
  • 45