def create_moons(self, nsamples):
     x, y = make_moons(n_samples=self.nsamples, noise=0.1)
     h = OneHotEncoder()
     y = h.fit_transform(y.reshape((-1, 1))).todense()
     self.x = sn.Tensor(data=x, requires_grad=False)
     self.y = sn.Tensor(data=y, requires_grad=False)
     self.nsamples = nsamples
Beispiel #2
0
 def setUpClass(cls):
     nsamples = 100
     cls.x = sn.Tensor(data=np.random.rand(nsamples, 10),
                       requires_grad=False)
     cls.y = sn.Tensor(data=np.matmul(cls.x.data, 0.2 * np.ones(
         (10, 1))) + 0.1,
                       requires_grad=False)
     print("net test begins.")
 def get_test_samples(self):
     n = int(self.nsamples * 0.5)
     test_x = sn.Tensor(data=self.x.data[n:, :], requires_grad=False)
     test_y = sn.Tensor(data=self.y.data[n:, :], requires_grad=False)
     return test_x, test_y
 def get_train_samples(self):
     n = int(self.nsamples * 0.5)
     train_x = sn.Tensor(data=self.x.data[0:n, :], requires_grad=False)
     train_y = sn.Tensor(data=self.y.data[0:n, :], requires_grad=False)
     return train_x, train_y
 def create_y_by_fun2(self, nsamples):
     self.x = sn.Tensor(data=np.random.rand(nsamples, 3), requires_grad=False)
     self.y = sn.Tensor(data=np.zeros((nsamples,)), requires_grad=False)
     self.y.data[:, 0] = np.exp(self.x.data[:, 0]) * self.x.data[:, 1] + self.x.data[:, 2]
 def create_y_by_fun1(self, nsamples):
     self.x = sn.Tensor(data=np.random.rand(nsamples, 3), requires_grad=False)
     self.y = sn.Tensor(data=np.zeros((nsamples, 1)), requires_grad=False)
     self.y.data[:, 0] = 0.5*self.x.data[:, 0] * self.x.data[:, 1] + self.x.data[:, 2]**2 + 0.1
     self.nsamples = nsamples