MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / get_spiral

Function get_spiral

ann_class2/util.py:34–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 2

grid_searchFunction · 0.90
random_searchFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected