def test_rotate_moons5(self): x = np.array([[1.0,1.0],[1.0,1.0]]) theta = math.pi/10 theta1 = math.pi/12 x = my_fn.rotate_moons(theta1, my_fn.rotate_moons(theta, x)) x_f = my_fn.rotate_moons(theta+theta1, x) self.assertAlmostEqual(x_f.all(), x.all())
def test_rotate_moons6(self): x = np.array([[1.0,1.0,1.0],[1.0,1.0,1.0]]) with self.assertRaises(TypeError): my_fn.rotate_moons(0.0, x)
def test_rotate_moons2(self): x = np.array([[1.0,1.0],[1.0,1.0]]) theta = math.pi/10 x_f = my_fn.rotate_moons(-theta, my_fn.rotate_moons(theta, x)) self.assertAlmostEqual(x_f.all(), x.all())
def test_rotate_moons4(self): x = np.array([[1.0,1.0],[1.0,1.0]]) x_f = my_fn.rotate_moons(2*math.pi, x) self.assertAlmostEqual(x_f.all(), x.all())
import matplotlib.pyplot as plt from sklearn import datasets import glob import sys import math sys.path.append('../') import common_fn as my_fn import tensorflow as tf #%% (x, y) = datasets.make_moons(n_samples=840, shuffle=True, noise=0.1, random_state=42) x_tr = my_fn.translate_moons(0.5, 0.5, x.copy()) x_rot = my_fn.rotate_moons(math.pi / 5, x_tr.copy()) y = y * 0 + 20 y_tr = y.copy() * 0 + 50 y_rot = y.copy() * 0 + 100 x = np.concatenate((x, x_tr), axis=0) y = np.concatenate((y, y_tr), axis=0) x = np.concatenate((x, x_rot), axis=0) y = np.concatenate((y, y_rot), axis=0) cm = plt.cm.get_cmap('RdYlBu') sns.set_style('whitegrid') fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(18, 9)) ax.set_xlabel('x') ax.set_ylabel('Y') # Plot the samples plt.scatter(x[:, 0], x[:, 1], c=y, cmap=cm, marker=".")