Great! Now that you understand the structure of the perceptron, here’s an important question — how are the inputs and weights magically turned into an output? This is a two-step process, and the first step is finding the weighted sum of the inputs.
What is the weighted sum? This is just a number that gives a reasonable representation of the inputs:
The x‘s are the inputs and the w‘s are the weights.
Here’s how we can implement it:
- Start with a weighted sum of 0. Let’s call it
- Start with the first input and multiply it by its corresponding weight. Add this result to
- Go to the next input and multiply it by its corresponding weight. Add this result to
- Repeat this process for all inputs.
Create a variable called
weighted_sum to hold the value of the weighted sum and set its starting value to
weighted_sum outside the
Let’s go through each input-weight pair and find the weighted sum using indexing.
pass statement inside the
for loop. For each iteration in the loop, find the product of the input and weight at index
i, add the result to
weighted_sum, and store it back in
weighted_sum to update the value of
Perceptron class, after the
cool_perceptron has been created, print out the weighted sum for the inputs
What is the weighted sum?