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')
[((9, 0, 9, 17), 'numpy.random.seed', 'np.random.seed', ({(9, 15, 9, 16): '(8)'}, {}), '(8)', True, 'import numpy as np\n'), ((13, 5, 13, 72), 'numpy.random.multivariate_normal', 'np.random.multivariate_normal', ({(13, 35, 13, 41): '[0, 0]', (13, 43, 13, 62): '[[1, 0.75], [0.75, 1]]', (13, 64, 13, 71): 'num_obs'}, {}), '([0, 0], [[1, 0.75], [0.75, 1]], num_obs)', True, 'import numpy as np\n'), ((14, 5, 14, 72), 'numpy.random.multivariate_normal', 'np.random.multivariate_normal', ({(14, 35, 14, 41): '[3, 8]', (14, 43, 14, 62): '[[1, 0.25], [0.25, 1]]', (14, 64, 14, 71): 'num_obs'}, {}), '([3, 8], [[1, 0.25], [0.25, 1]], num_obs)', True, 'import numpy as np\n'), ((17, 4, 17, 23), 'numpy.vstack', 'np.vstack', ({(17, 14, 17, 22): '(x1, x2)'}, {}), '((x1, x2))', True, 'import numpy as np\n'), ((29, 35, 29, 90), 'sklearn.model_selection.train_test_split', 'train_test_split', (), '', False, 'from sklearn.model_selection import train_test_split\n'), ((32, 10, 32, 22), 'gwu_nn.gwu_network.GWUNetwork', 'GWUNetwork', ({}, {}), '()', False, 'from gwu_nn.gwu_network import GWUNetwork\n'), ((45, 0, 45, 27), 'matplotlib.pyplot.figure', 'plt.figure', (), '', True, 'import matplotlib.pyplot as plt\n'), ((46, 0, 46, 50), 'matplotlib.pyplot.scatter', 'plt.scatter', (), '', True, 'import matplotlib.pyplot as plt\n'), ((56, 0, 56, 60), 'matplotlib.pyplot.plot', 'plt.plot', (), '', True, 'import matplotlib.pyplot as plt\n'), ((33, 12, 33, 40), 'gwu_nn.layers.Dense', 'Dense', ({(33, 18, 33, 19): '(2)', (33, 21, 33, 22): '(1)', (33, 24, 33, 28): '(True)', (33, 30, 33, 39): '"""sigmoid"""'}, {}), "(2, 1, True, 'sigmoid')", False, 'from gwu_nn.layers import Dense\n'), ((34, 12, 34, 21), 'gwu_nn.activation_layers.Sigmoid', 'Sigmoid', ({}, {}), '()', False, 'from gwu_nn.activation_layers import Sigmoid\n'), ((20, 15, 20, 32), 'numpy.zeros', 'np.zeros', ({(20, 24, 20, 31): 'num_obs'}, {}), '(num_obs)', True, 'import numpy as np\n'), ((20, 34, 20, 50), 'numpy.ones', 'np.ones', ({(20, 42, 20, 49): 'num_obs'}, {}), '(num_obs)', True, 'import numpy as np\n'), ((54, 42, 54, 52), 'scipy.special.logit', 'logit', ({(54, 48, 54, 51): '(0.5)'}, {}), '(0.5)', False, 'from scipy.special import logit\n'), ((55, 38, 55, 48), 'scipy.special.logit', 'logit', ({(55, 44, 55, 47): '(0.5)'}, {}), '(0.5)', False, 'from scipy.special import logit\n')]