Generation

generate functionWed, 17 May 2023

2-layers XOR classification To complete this exercise, you will need to have a basic understanding of NumPy and JAX. You can use the resources provided in the previous exercises to learn more about these libraries. We help you out by first defining the XOR classification problem to solve (and outlining some basic properties) from cml.data import xor_separation # Definition of our data properties n_observations = 500 noise_factor = 0.1 # Properties of our problem n_input = 2 n_output = 1 # Generate a XOR dataset x_inputs, y_classes = xor_separation(n_observations, noise_factor) We also show some potential implementation of the initialization scheme. Note that you can later try to replace this naive implementation by some more refined functions # 1st layer weights weights1 = (np.random.randn(n_hidden, n_input) * 0.01) # 2nd layer weights weights2 = (np.random.randn(n_output, n_hidden) * 0.01) # 1st layer biases bias1 = (np.random.randn(n_hidden, 1) * 0.01) # 2nd layer biases bias2 = (np.random.randn(n_output, 1) * 0.01) Question 1.1 - Implement 2-layer XOR classification with NumPy Update the forward propagation and error computation Update the back-propagation part to learn the weights of both layers. Run the learning and check your network results For optional questions, please look at the end of this exercise's code boxes for more information

# Imports import numpy as np # Definition of our data properties n_observations = 500 noise_factor = 0.1 # Properties of our problem n_input = 2 n_output = 1 n_hidden = 2 # Generate a XOR dataset x_inputs, y_classes = xor_separation(n_observations, noise_factor) # 1st layer weights weights1 = (np.random.randn(n_hidden, n_input) * 0.01) # 2nd layer weights weights2 = (np.random.randn(n_output, n_hidden) * 0.01) # 1st layer biases bias1 = (np.random.randn(n_hidden, 1) * 0.01) # 2nd layer biases bias2 = (np.random.randn(n_output, 1) * 0.01) def sigmoid(x): return 1/(1+np.exp(-x)) # Forward propagation a1 = x_inputs z

Want to kickstart your project?Use the new AI Studio to create your code