MCPcopy Create free account
hub / github.com/apache/singa / generate_data

Method generate_data

test/python/test_model.py:344–355  ·  view source on GitHub ↗
(self, dev, num=400)

Source from the content-addressed store, hash-verified

342 return categorical
343
344 def generate_data(self, dev, num=400):
345 f = lambda x: (5 * x + 1)
346
347 x = np.random.uniform(-1, 1, num)
348 y = f(x) + 2 * np.random.randn(len(x))
349
350 self.label = np.asarray([5 * a + 1 > b for (a, b) in zip(x, y)])
351 self.data = np.array([[a, b] for (a, b) in zip(x, y)], dtype=np.float32)
352 self.label = self.to_categorical(self.label, 2).astype(np.float32)
353
354 self.inputs = Tensor(data=self.data, device=dev)
355 self.target = Tensor(data=self.label, device=dev)
356
357 def get_params(self, model):
358 params = model.get_params()

Callers 2

_forward_helperMethod · 0.95

Calls 3

to_categoricalMethod · 0.95
TensorClass · 0.90
uniformMethod · 0.45

Tested by

no test coverage detected