Hi Everybody! today we will talk about the perceptron
which is how we call a single unit of logic
inside an artificial neural network
the perceptron is an algorithm
a set of instructions
that determines if something is true or false
one or zero
chicken or goat
it is a very basic unit
it only consists of one node
and we can imagine it as a small neuron
living inside a much bigger brain
but because it's so hard to imagine such abstract concepts
let's have a quick look at an example and we'll go from there
so whenever we think about logic and the process of thought
we very often begin with data
so we either see something, we hear it
we smell it, we taste it
and our thought is a direct result of the data we've been exposed to
for example - I tasted a snail in Paris
my taste buds received the snail input
then, they sent a signal to my brain
where I came to the conclusion that I don't like snail
in the table next to me, however,
there was a gentleman that also ate snail
he received the exact same input
but came to a completely different conclusion than mine
he LOVES snail
so even though we were both exposed to the exact same input -
our process of thought led us to completely different conclusions
so just like in real life -
even if we expose two different perceptron to the exact same input data
it doesn't necessarily mean that they'll come to the same conclusion
which also known as "output"
in fact, we can control the "thinking patterns"
of perceptron with different weights and threshold
let me show you what I mean:
so as I just mentioned, one of the main components of perceptron is input data
for this example we will use a set of floating point numbers
which we will call "X"
each perceptron also has a set of weights
these weights determine exactly how much impact
a particular input value has on the data as a whole
for example - x[2] is much more significant than x[1]
because x[2] has a weights of 0.6
which is bigger than 0.3
and therefore x[2] will be much more important to our data
now in order to reach a logical conclusion
we will need to apply the weights on the inputs
we can do this by multiplying each of the inputs
by it's corresponding weight
and then adding the results to get a weighted sum
then we will need to evaluate if this sum has reached a certain threshold
also known as bias
now very often you will the bias being added during the sum operation
however, in this example, just to keep things simple
we will refer (to) it as a threshold instead
to evaluate weather the threshold was reached
we will use something called an "activation function"
and while there are many different activation functions out there
we will use the most simple one which is called the "step function"
so with this type of function - if our threshold is .5 for example
and our sum is bigger than .5
then the function will return "true" or 1
on the other hand - if the weighted sum is smaller than .5
or equal to .5
then the function will return "false" or 0
and the key note here is that we get to choose the threshold
so it doesn't necessarily have to be .5
and another very important thing we get to choose
is the initial set of weights
so it doesn't have to be the numbers that I selected
it could be a set of zeroes, it could be a set of halves or quarters
it is all up to you- the developer!
in fact, just by selecting different values for our initial set of weights
our perceptron may come to a completely different output
just like the snail loving gentlemen in Paris!
and therefore, the accuracy of our neural network
depends on how well we can adjust to weights
to better understand our input data
and so far, we've only talked about setting initial weights values
but how exactly do we update them?
I will actually answer this question in the next tutorial
but in the meanwhile, let's quickly implement everything that we've learned in Python
we will begin with our set of inputs
we will call it "X_input"
and this will equal a list where the first item is .1
the second item is .5 and the last item is .2
then we will select our initial set of weights
we'll call it "w_weights"
and this will equal a list where the first value is 0.4
the second value is 0.3 and the last value is 0.6
and the last variable we'll defined will be the threshold
is you guys remember, that equals .5
at least in our example
and before we combine these variables inside out perceptron
let's define our activation function first
for this we will type "def step" function
which will take in a single parameter that equals to our weighted sum
and if you guys remember - if our weighted sum
is bigger than our threshold
then our function will return 1
otherwise - it will return 0
and now we can move on with the actual perceptron
so let's define a brand new function called "perceptron"
which doesn't take in any parameters
and as the first line in our function - we would like to set the weighted sum to 0
next, we will iterate over both of these lists
multiplying the input values by it's corresponding weight
we can do this with the help of a "for" loop, so we will type:
"for x,w in zip(x_input, w_weights):"
and for each iteration - we would like to multiply x by w
and not only this - we would also like to increment our weighted sum by the results
so we will just copy this variable from above
we will paste it and we will add a "+=" operator
to increment our sum each and every time we go through the "for" loop
and we can of course print this sum as we go - just to see our progress
and last - but not least!
we will leave the "for" loop
and we will return the step function results on our weighted sum
and if we're already here - let's fix my typo!
this is how you spell "w_weights"
not how I spelled it before!
and in the very very end - we can safely set our output
to equal our perceptron function
and we can print it right away - so I'll type:
"output: " and I will concatenate the string instance of our output
and if everything looks good - let's give it a run!
and here we can see how each iteration
is increasing our weighted sum
and then in the very end - we get to .31
which is unfortunately smaller than our threshold of .5
and that's why the output of our perceptron will be 0 or "false"
and if you guys didn't feel like coding along with me
but you still want to have a reference to this script -
you can click on the link in the description and access it through Wayscript
thank you so much for watching folks!
if you found this video helpful -
please give it a like, a comment, maybe subscribe to my channel
or even better - share this video with your co-workers or your friends
I really appreciate any form of help!
thanks again and I will see you very soon! :)