MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / get_spiral

Function get_spiral

svm_class/util.py:40–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38
39
40def get_spiral():
41 # Idea: radius -> low...high
42 # (don't start at 0, otherwise points will be "mushed" at origin)
43 # angle = low...high proportional to radius
44 # [0, 2pi/6, 4pi/6, ..., 10pi/6] --> [pi/2, pi/3 + pi/2, ..., ]
45 # x = rcos(theta), y = rsin(theta) as usual
46
47 radius = np.linspace(1, 10, 100)
48 thetas = np.empty((6, 100))
49 for i in range(6):
50 start_angle = np.pi*i / 3.0
51 end_angle = start_angle + np.pi / 2
52 points = np.linspace(start_angle, end_angle, 100)
53 thetas[i] = points
54
55 # convert into cartesian coordinates
56 x1 = np.empty((6, 100))
57 x2 = np.empty((6, 100))
58 for i in range(6):
59 x1[i] = radius * np.cos(thetas[i])
60 x2[i] = radius * np.sin(thetas[i])
61
62 # inputs
63 X = np.empty((600, 2))
64 X[:,0] = x1.flatten()
65 X[:,1] = x2.flatten()
66
67 # add noise
68 X += np.random.randn(600, 2)*0.5
69
70 # targets
71 Y = np.array([0]*100 + [1]*100 + [0]*100 + [1]*100 + [0]*100 + [1]*100)
72 return X, Y
73
74
75def get_xor():

Callers 2

spiralFunction · 0.90
spiralFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected