import numpy as np
import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split
from gwu_nn.gwu_network import GWUNetwork
from gwu_nn.layers import Dense
from gwu_nn.activation_layers import Sigmoid

np.random.seed(8)
num_obs = 8000

# Create our features to draw from two distinct 2D normal distributions
x1 = np.random.multivariate_normal([0, 0], [[1, .75],[.75, 1]], num_obs)
x2 = np.random.multivariate_normal([3, 8], [[1, .25],[.25, 1]], num_obs)

# Stack our inputs into one feature space
X = np.vstack((x1, x2))
print(X.shape)

y = np.hstack((np.zeros(num_obs), np.ones(num_obs)))
print(y.shape)


# colors = ['red'] * num_obs + ['blue'] * num_obs
# plt.figure(figsize=(12,8))
# plt.scatter(X[:, 0], X[:, 1], c = colors, alpha = 0.5)

# Lets randomly split things into training and testing sets so we don't cheat
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)

# Create our model
network = GWUNetwork()
network.add(Dense(2, 1, True, 'sigmoid'))
network.add(Sigmoid())
#network.set_loss('mse')
network.compile('log_loss', 0.001)
network.fit(X_train, y_train, epochs=100)




from scipy.special import logit

colors = ['red'] * num_obs + ['blue'] * num_obs
plt.figure(figsize=(12, 8))
plt.scatter(X[:, 0], X[:, 1], c=colors, alpha=0.5)

# Range of our X values
start_x1 = -5
end_x1 = 7

weights = network.layers[0].weights.reshape(-1).tolist()
bias = network.layers[0].bias[0][0]
start_y = (bias + start_x1 * weights[0] - logit(0.5)) / - weights[1]
end_y = (bias + end_x1 * weights[0] - logit(0.5)) / -weights[1]
plt.plot([start_x1, end_x1], [start_y, end_y], color='grey')
[((233, 250), 'numpy.random.seed', 'np.random.seed', (['(8)'], {}), '(8)\n', (247, 250), True, 'import numpy as np\n'), ((348, 418), 'numpy.random.multivariate_normal', 'np.random.multivariate_normal', (['[0, 0]', '[[1, 0.75], [0.75, 1]]', 'num_obs'], {}), '([0, 0], [[1, 0.75], [0.75, 1]], num_obs)\n', (377, 418), True, 'import numpy as np\n'), ((422, 492), 'numpy.random.multivariate_normal', 'np.random.multivariate_normal', (['[3, 8]', '[[1, 0.25], [0.25, 1]]', 'num_obs'], {}), '([3, 8], [[1, 0.25], [0.25, 1]], num_obs)\n', (451, 492), True, 'import numpy as np\n'), ((540, 559), 'numpy.vstack', 'np.vstack', (['(x1, x2)'], {}), '((x1, x2))\n', (549, 559), True, 'import numpy as np\n'), ((908, 963), 'sklearn.model_selection.train_test_split', 'train_test_split', (['X', 'y'], {'test_size': '(0.33)', 'random_state': '(42)'}), '(X, y, test_size=0.33, random_state=42)\n', (924, 963), False, 'from sklearn.model_selection import train_test_split\n'), ((997, 1009), 'gwu_nn.gwu_network.GWUNetwork', 'GWUNetwork', ([], {}), '()\n', (1007, 1009), False, 'from gwu_nn.gwu_network import GWUNetwork\n'), ((1275, 1302), 'matplotlib.pyplot.figure', 'plt.figure', ([], {'figsize': '(12, 8)'}), '(figsize=(12, 8))\n', (1285, 1302), True, 'import matplotlib.pyplot as plt\n'), ((1304, 1358), 'matplotlib.pyplot.scatter', 'plt.scatter', (['X[:, (0)]', 'X[:, (1)]'], {'c': 'colors', 'alpha': '(0.5)'}), '(X[:, (0)], X[:, (1)], c=colors, alpha=0.5)\n', (1315, 1358), True, 'import matplotlib.pyplot as plt\n'), ((1642, 1702), 'matplotlib.pyplot.plot', 'plt.plot', (['[start_x1, end_x1]', '[start_y, end_y]'], {'color': '"""grey"""'}), "([start_x1, end_x1], [start_y, end_y], color='grey')\n", (1650, 1702), True, 'import matplotlib.pyplot as plt\n'), ((1023, 1051), 'gwu_nn.layers.Dense', 'Dense', (['(2)', '(1)', '(True)', '"""sigmoid"""'], {}), "(2, 1, True, 'sigmoid')\n", (1028, 1051), False, 'from gwu_nn.layers import Dense\n'), ((1066, 1075), 'gwu_nn.activation_layers.Sigmoid', 'Sigmoid', ([], {}), '()\n', (1073, 1075), False, 'from gwu_nn.activation_layers import Sigmoid\n'), ((594, 611), 'numpy.zeros', 'np.zeros', (['num_obs'], {}), '(num_obs)\n', (602, 611), True, 'import numpy as np\n'), ((613, 629), 'numpy.ones', 'np.ones', (['num_obs'], {}), '(num_obs)\n', (620, 629), True, 'import numpy as np\n'), ((1549, 1559), 'scipy.special.logit', 'logit', (['(0.5)'], {}), '(0.5)\n', (1554, 1559), False, 'from scipy.special import logit\n'), ((1615, 1625), 'scipy.special.logit', 'logit', (['(0.5)'], {}), '(0.5)\n', (1620, 1625), False, 'from scipy.special import logit\n')]