<jupyter_start><jupyter_text>Generate 2D binary data and plot<jupyter_code>from sklearn.datasets import make_circles
X_circle, y_circle = make_circles(n_samples= 100, noise=0.05, factor=0.5,random_state=1)
X_circle *= 0.8
plot = sns.scatterplot(x= X_circle[:,0], y=X_circle[:,1],hue=y_circle)
plot.set(xlim=(-1,1), ylim=(-1,1))<jupyter_output><empty_output><jupyter_text>Generate grid for the heatmap<jupyter_code>step = 0.01
n_steps=int(2/step)
grid = np.concatenate([np.array([(-1 +(i+.5)* step)*np.ones(n_steps),np.arange(-1+step/2,1,step)]).T for i in range(n_steps)],axis=0)
step = 0.01
n_steps=int(2/step)
columns=[]
for i in range(n_steps):
    columns.append(np.array([(-1 +(i+.5)* step)*np.ones(n_steps),np.arange(-1+step/2,1,step)]).T)
grid=np.concatenate(columns,axis=0)<jupyter_output><empty_output><jupyter_text>Benchmarking the optimizers<jupyter_code>model = handmade_nn(input_dim=2)
model.add_dense_layer(4,'relu')
model.add_dense_layer(4,'relu')
model.add_dense_layer(1, 'sigmoid')
model.fit(X_circle,y_circle,loss='binary_crossentropy', optimizer= 'sgd', batch_size=16,n_epochs=1000)
graph=sns.heatmap(model.predict(grid).reshape((n_steps,n_steps)))
graph.scatter(x= (X_circle[:,0]+1)*100, y=(X_circle[:,1]+1)*100)
model = handmade_nn(input_dim=2)
model.add_dense_layer(4,'relu')
model.add_dense_layer(4,'relu')
model.add_dense_layer(1, 'sigmoid')
model.fit(X_circle,y_circle,loss='binary_crossentropy', optimizer='adam', batch_size=16,n_epochs=1000)
graph=sns.heatmap(model.predict(grid).reshape((n_steps,n_steps)))
graph.scatter(x= (X_circle[:,0]+1)*100, y=(X_circle[:,1]+1)*100)<jupyter_output>initial loss: 0.6982000343836507
final loss: 0.001601608549692142<jupyter_text>New test with the same network as in the tutorial<jupyter_code>model = handmade_nn(input_dim=2)
model.add_dense_layer(4,'tanh')
model.add_dense_layer(3,'tanh')
model.add_dense_layer(1, 'sigmoid')
model.weights = [np.array([[5.15045094e-01, 7.71080942e-01],
         [2.40597558e-05, 1.27794266e-01],
         [8.51358255e-01, 2.40605413e-01],
         [1.81029934e-01, 7.25234350e-01]]),
  np.array([[0.31549234, 0.57829072, 0.04666635, 0.93386572],
         [0.60140935, 0.92364091, 0.24940746, 0.13005867],
         [0.59650737, 0.3965407 , 0.24233158, 0.32827774]]),
  np.array([[0.01200974, 0.36626125, 0.34816268]])]
y_pred_initial = model.predict(X_circle)
y_pred_initial
model.fit(X_circle,y_circle,loss='binary_crossentropy', batch_size=10,n_epochs=1)
graph=sns.heatmap(model.predict(grid).reshape((n_steps,n_steps)))
graph.scatter(x= (X_circle[:,0]+1)*100, y=(X_circle[:,1]+1)*100)
model.weights
my_nn=handmade_nn(5)
my_nn.add_dense_layer(10,'tanh',weights_initializer='ones')
my_nn.add_dense_layer(1,'sigmoid',weights_initializer='ones')
my_nn.set_loss('binary_crossentropy')
my_nn.predict([1,0.2,0.1,1,0.1])
my_nn.score([1,0.2,0.1,1,0.1],np.ones((1,1)),'binary_crossentropy')
my_nn.compute_backpropagation(np.array([[1,0.2,0.1,1,0.1]]),np.ones((1,1)))
my_nn.fit(np.array([[1,0.2,0.1,1,0.1]]), np.ones(1),n_epochs=1)
my_nn.weights
my_nn.bias<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1938211382113821, 'fraction_numerical': 0.12845528455284552, 'mean_word_length': 8.43558282208589, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '253120', 'license': 'MIT', 'n_tokens_mistral': 1575, 'n_tokens_neox': 1384, 'n_words': 141, 'path': 'notebooks/Neuralnet_Testing.ipynb', 'repo_name': 'bdepebhe/handmadeML', 'size': '3075'}