<jupyter_start><jupyter_text>MLP<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>Calculating the hidden layer (H)<jupyter_code># Entry
x = [0.05,0.10]

# Weights
w = [0.15,0.20,0.25,0.30,0.40,0.45,0.50,0.55]

# Bias
b = [0.35,0.60]

# Learning rate
n = 0.50
# Propagation of entries
net_h = [(x[0] * w[0] + x[1] * w[1] + b[0] * 1),
         (x[0] * w[2] + x[1] * w[3] + b[0] * 1)]

print("Entry NET H¹: ",net_h[0],"\nEntry NET H²: ",net_h[1])
# Applying activation function
g_h = [(1 / (1 + np.exp(-net_h[0]))),
       (1 / (1 + np.exp(-net_h[1])))]

print("Hidden H¹: ",g_h[0],"\nHidden H²: ",g_h[1])<jupyter_output>Hidden H¹:  0.5932699921071872 
Hidden H²:  0.596884378259767<jupyter_text>Calculating the output layer (O)<jupyter_code># Propagation of entries
net_o = [(g_h[0] * w[4] + g_h[1] * w[5] + b[1] * 1),
         (g_h[0] * w[6] + g_h[1] * w[7] + b[1] * 1)]

print("Entry NET O¹: ",net_o[0],"\nEntry NET O²: ",net_o[1])
# Applying activation function
# Output layer
g_o = [(1 / (1 + np.exp(-net_o[0]))),
       (1 / (1 + np.exp(-net_o[1])))]

print("Activation Func H¹: ",g_h[0],"\nActivation Func H²: ",g_h[1])<jupyter_output>Activation Func H¹:  0.5932699921071872 
Activation Func H²:  0.596884378259767<jupyter_text>Calculating errors<jupyter_code># Expected entry
d = [0.01,0.99]

# Error total
erro_total = (((1 / 2) * (d[0] - g_o[0])**2) + ((1 / 2) * (d[1] - g_o[1])**2))

# Error output
erro_o = [((1 / 2) * (d[0] - g_o[0])**2),
          ((1 / 2) * (d[1] - g_o[1])**2)]

print(erro_o[0])
print(erro_o[1])
# Updating the output layer weights (Back Propagation)

dpp = [(-(d[0] - g_o[0])),
       (-(d[1] - g_o[1]))]

dsp = [(g_o[0] * (1 - g_o[0])),
       (g_o[1] * (1 - g_o[1]))]

print(dpp[0]*dsp[0])
print(dpp[1]*dsp[1])
# Updating the weights of the hidden layer (Back Propagation)

dpp = [((((g_o[0] - d[0])) * g_o[0] * (1 - g_o[0]) * w[4]) + (((g_o[1] - d[1])) * g_o[1] * (1 - g_o[1]) * w[6])),
       ((((g_o[0] - d[0])) * g_o[0] * (1 - g_o[0]) * w[5]) + (((g_o[1] - d[1])) * g_o[1] * (1 - g_o[1]) * w[7]))]

dsp = [(g_h[0] * (1 - g_h[0])),
       (g_h[1] * (1 - g_h[1]))]
# Weights of the hidden layer (Back Propagation)
w[0] = w[0] - n * (dpp[0] * dsp[0] * x[0])
w[1] = w[1] - n * (dpp[0] * dsp[0] * x[0])
w[2] = w[2] - n * (dpp[1] * dsp[1] * x[1])
w[3] = w[3] - n * (dpp[1] * dsp[1] * x[1])

# Output layer weights (Back Propagation)
w[4] = w[4] - n * (dpp5 * dsp5 * g_h[0])
w[5] = w[5] - n * (dpp6 * dsp6 * g_h[1])
w[6] = w[6] - n * (dpp7 * dsp7 * g_h[0])
w[7] = w[7] - n * (dpp8 * dsp8 * g_h[1])

print("Epoch = 1\n----------")
print("Erro Total: ",erro_total,"\n\nError Output O¹: ",erro_o[0],"\nError Output O²: ",erro_o[1])
print("\nHidden layer - Weights corrected")
print("Weights 1: ",w[0],"\nWeights 2: ",w[1],"\nWeights 3: ",w[2],"\nWeights 4: ",w[3])
print("\nExit layer - Weights corrected")
print("Weights 5: ",w[4],"\nWeights 6: ",w[5],"\nWeights 7: ",w[6],"\nWeights 8: ",w[7])<jupyter_output>Epoch = 1
----------
Erro Total:  0.2983711087600027 

Error Output O¹:  0.274811083176155 
Error Output O²:  0.023560025583847746

Hidden layer - Weights corrected
Weights 1:  0.1497807161327628 
Weights 2:  0.19978071613276283 
Weights 3:  0.24950228726473914 
Weights 4:  0.29950228726473915

Exit layer - Weights corrected
Weights 5:  0.35891647971788465 
Weights 6:  0.4086661860762334 
Weights 7:  0.5113012702387375 
Weights 8:  0.5613701211079891
{'fraction_non_alphanumeric': 0.24341720304271502, 'fraction_numerical': 0.14072557050906964, 'mean_word_length': 3.709366391184573, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '330025', 'license': 'MIT', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1751, 'n_words': 349, 'path': 'CNN_MLP/MLP.ipynb', 'repo_name': 'WesGtoX/Simple-Projects-I2A2', 'size': '3418'}