Welcome again!
We not too long ago mentioned backpropagation, and I hope you now have an thought of what backpropagation is and the way it truly works.
Let’s proceed the deep studying journey.
Regardless that we apply the backpropagation algorithm to a neural community, we nonetheless have some issues, and vanishing gradients is one among them.
Whereas I used to be studying about vanishing gradients, I got here throughout the sigmoid perform.
Everyone knows that it’s utilized in logistic regression, the place we apply the sigmoid perform to a worth to acquire an output between 0 and 1.
Now, right here in neural networks, it may be used as an activation perform.
What I learn about sigmoid is the equation we have now and its utilization in logistic regression and neural networks.
I used to be interested in how we get this equation and the story behind it.
On this weblog, let’s have a look at how we get to the sigmoid equation.
By the way in which, if you have not learn Half 3 of the backpropagation collection, you possibly can learn it right here.
···
How Do We Truly Use Sigmoid?
We already know the equation of the sigmoid perform.
Earlier than we proceed, let’s have a look at how we use it in logistic regression.
For instance, we need to predict whether or not a scholar will go or fail primarily based on the variety of hours they studied.
We’re utilizing the logistic regression mannequin right here.
First, it calculates a rating
As an instance the rating for a scholar is:
This rating just isn’t a chance.
It’s simply the linear mixture of parameters.
Now we go it via the sigmoid perform:
we get,
The sigmoid perform at all times produces an output between 0 and 1.
Right here the output is roughly 0.88 or 88%.
In logistic regression, this may be interpreted as an 88% chance of the coed passing the examination.
We are able to then use a threshold, reminiscent of 0.5, to make the ultimate classification.
Briefly, the circulation could be like
That is how we generally use the sigmoid perform in logistic regression.
However What Is This “e”?
Now, let’s as soon as once more take a look at the sigmoid equation.
The very first thing we discover is the e.
We all know that it’s a mathematical fixed and its worth is
However what precisely is ‘e’?
Why is that this quantity current within the sigmoid equation?
Let’s take a step again and perceive the place this quantity comes from.
One factor is that right here we aren’t attempting to find ‘e’, however the purpose is to grasp the importance of ‘e’ and see the place it naturally seems.
Now let’s go to the financial institution and see what we will observe.
Let’s Begin with a Easy Financial institution Instance
Think about we deposited Rs.100 right into a checking account.
As an instance the financial institution is giving us a 100% annual rate of interest.
If the financial institution provides your entire 12 months’s curiosity on the finish of the 12 months, we earn Rs.100 in curiosity.
So after one 12 months, we have now
We are able to additionally write it as
Rs.100 turned Rs.200 after one 12 months.
However now let’s change one factor.
What if the financial institution does not wait till the tip of the 12 months so as to add the curiosity?
What if it provides the curiosity twice a 12 months?
The annual rate of interest remains to be 100%.
However now the 12 months is split into two durations.
So for every six-month interval we get half of the annual rate of interest:
Throughout the first six months, we get
After six months, we have now Rs.150.
Throughout the subsequent six months, the curiosity is calculated on this new quantity
Then we have now
Why did we get Rs.225 as a substitute of Rs.200?
As a result of the curiosity earned in the course of the first six months additionally earned curiosity in the course of the second six months.
In easy phrases we will say
‘curiosity earns curiosity’
That is the essential thought behind compound curiosity.
What Occurs When We Compound Extra Often?
Now let’s make the compounding extra frequent.
If we compound 4 instances a 12 months:
If we compound 12 instances a 12 months:
If we compound day-after-day:
Observe the sample.
As we enhance the variety of compounding durations, the ultimate quantity retains rising.
The reason being that development is being utilized repeatedly to an quantity that has already elevated.
The place Does e Come From?
The Rs.100 just isn’t the vital half right here.
Let’s take away it and take a look at the expansion issue:
Right here, ‘n’ represents the variety of instances we compound in the course of the 12 months.
For instance:
As we make the compounding increasingly frequent, the worth will get nearer and nearer to
This quantity known as ‘e’
Mathematically, we will categorical this concept utilizing a restrict
The notation might look advanced, however the thought is straightforward.
Right here, we’re asking:
“What worth does this expression method as ‘n’ turns into bigger and bigger?”
As ‘n’ will increase:
will get nearer and nearer to:
That limiting worth is ‘e’.
So, What Does the Financial institution Need to Do with Sigmoid?
However why are we speaking about this and what does this checking account should do with sigmoid.
This instance is not to elucidate compound curiosity, nevertheless it provides us an instinct for the place ‘e’ naturally seems.
The vital thought right here is repeated development.
When development is repeatedly utilized to an quantity that has already grown, we get a compounding course of.
And when that course of occurs time and again extra often, the quantity ‘e’ naturally seems.
So as a substitute of merely memorizing that
we now have some instinct behind it.
The Particular Property of e
From the financial institution instance, we noticed that ‘e’ naturally seems after we take a look at repeated development and steady compounding.
However ‘e’ is greater than only a quantity that seems in compound curiosity.
It has a really particular property after we take a look at it via calculus.
Let’s take into account the exponential perform
If we differentiate this perform, we get
This formulation we already know.
However what does the spinoff inform us?
We already know that it tells us the fee of change of a perform.
For instance, if we have now
its spinoff is
Which means that the speed at which x2 modifications is determined by the worth of x.
At x=1:
At x=3:
So, for x2, the perform and its fee of change are completely different.
Now let’s take a look at ex.
For
we have now
Which means that the speed of change of ex is the same as its present worth.
Let us take a look at some values.
When x=0
and
When x=1
and
When x=2
and
So, right here we will say that
Price of change = Present worth
This is among the most vital properties of the exponential perform with base e.
Why Is the By-product of ex Equal to ex?
We now have an thought of an vital property of ‘e’ in calculus.
We simply mentioned what it’s however let’s have a look at why does this occur?
When you already know why
then use this part for fast revision as we join it again to the sigmoid perform.
Beginning with a Common Exponential
First let’s take into account a basic exponential perform.
Right here, z is the bottom and x is the exponent.
are all examples of this way.
Now let’s have a look at what occurs after we differentiate zx
We have now,
Utilizing the exponent rule we get
Due to this fact
Now discover that zx seems in each phrases within the numerator.
We are able to issue it out
Right here zx doesn’t rely upon h, so we will take it outdoors the restrict
And that is the place issues get fascinating.
Our result’s
Take a look at the 2 components individually.
The primary half is
That’s our authentic exponential perform.
The second half is
We are able to see that there isn’t any ‘x’ on this expression.
It is determined by the bottom ‘z’, however not on ‘x’.
This implies, for any worth of ‘z’, this complete restrict is only a fixed.
Let’s name this fixed ‘C’.
Due to this fact we will write it as,
This tells us one thing vital.
After we differentiate an exponential perform, we get the unique exponential perform, multiplied by a relentless.
In different manner,
The Fixed Relies on the Base
Now let’s take an instance of exponential perform:
From our outcome, we have now
For z=3, the fixed is
Now we have to discover the worth of this restrict.
Let’s perceive this in intuitive manner.
For the bottom 3, the worth of the fixed is roughly
Due to this fact,
Let’s examine what this tells us by utilizing at completely different ‘x’ values.
When
we have now
the speed of change right here is roughly
When
we get
The speed of change is
And when
we have now
The speed of change is roughly
We are able to see that the spinoff just isn’t precisely equal to 3x.
As an alternative, we received
The perform and its fee of change have the identical exponential form, however the fee of change is scaled by a relentless.
Discovering the Particular Base
Now, we all know that
The worth of ‘C’ trusted the bottom.
For 3x,
Okay however what if we may discover a base for which C is strictly 1?
Do we have now any quantity?
If sure, then we get
Our spinoff would grow to be
In different phrases, we will say that the perform could be precisely equal to its personal spinoff.
So, now we’re in search of a base z that satisfies
There may be one explicit constructive quantity that satisfies this situation and also you all know what’s that quantity is.
We name this quantity
and its numerical worth is
For this explicit base, the fixed turns into
Due to this fact,
which supplies us
···
So What Did We Truly Uncover?
We began with a basic exponential perform
Utilizing the definition of a spinoff, we discovered
We then noticed that the restrict is solely a relentless that is determined by the bottom.
Then we have now written it as
Then we requested:
Is there a base for which C=1?
The reply is sure.
That particular base is e.
Due to this fact,
Now we have now an thought of how we received the spinoff.
Within the earlier financial institution instance, ‘e’ appeared via repeated development and steady compounding.
Now, via calculus, we have now seen one other particular property of the identical quantity
In easy phrases, we will say that ex grows at a fee equal to its present worth.
Now, Let’s Return to Sigmoid
Let’s as soon as once more take a look at the sigmoid equation.
Now we have now some thought of what ‘e’ truly is.
Now we give attention to the entire equation.
The query right here is why does the sigmoid perform is on this explicit type?
To know this we should always return to logistic regression.
We began with a uncooked rating
‘z’ could be any actual quantity.
However for classification, we wished to interpret the mannequin’s output as a chance.
A chance should lie between 0 and 1
0<p<1
So we need to remodel any worth of ‘z’ into a worth between 0 and 1.
In different phrases, we wish one thing that may obtain
and produce:
Constructing a Operate That Outputs Between 0 and 1
Now, the duty is to assemble such transformation.
However how can we try this?
Let’s begin with a quite simple remark.
Suppose we have now a quantity better than 1.
For instance
If we take its reciprocal, we get
which is between 0 and 1.
The identical thought works for any numbers better than 1
Right here we will discover that
If
then
This offers us a easy thought.
If we will have a amount that’s at all times better than 1, then taking its reciprocal will routinely give us a worth between 0 and 1.
And that’s precisely the vary we wish for a chance.
Nevertheless, there’s yet another factor we want.
We don’t need to use a set quantity reminiscent of 5 within the denominator.
as a result of that at all times give us the identical output.
Our output ought to change when the enter ‘x’ modifications.
For instance, we wish a constructive enter to provide a bigger chance, whereas a destructive enter ought to produce a smaller chance.
So, we want a amount that modifications with x.
Now e Enters the Image
You might be proper. It is time for ‘e’ to enter.
That is the place the exponential perform we simply realized about turns into helpful.
Exponential features are at all times constructive, which suggests
for each actual worth of x.
For instance:
Whether or not the x is destructive, zero, or constructive, ex by no means turns into destructive or zero.
However the sigmoid equation accommodates e-x.
Until right here we solely mentioned about ex.
So let’s first see what a destructive exponent means.
We already know what a constructive exponent means.
For instance:
and:
A destructive exponent represents the reciprocal of the corresponding constructive exponent.
For instance:
Equally
and
Typically, we will write as
So, e-x just isn’t a very completely different perform.
It’s merely the reciprocal of ex.
Now we will use what we already learn about ex.
Since:
its reciprocal can be constructive
and since
we get
for each actual worth of x.
That is vital as a result of it provides us precisely the sort of amount we want.
If e-x is at all times constructive, then including 1 provides us a amount that’s at all times better than 1
And now we will use our reciprocal thought.
If a quantity is larger than 1, its reciprocal lies between 0 and 1
Now we have now a perform whose output is at all times between 0 and 1.
The expression we simply received is
and that is precisely the sigmoid perform we began with
So as a substitute of wanting on the sigmoid equation as a formulation, now we will perceive the instinct behind its construction.
We wished the output to lie between 0 and 1.
We noticed that the reciprocal of a quantity better than 1 lies between 0 and 1.
As e-x is at all times constructive, we used it to assemble a amount better than 1
Taking its reciprocal gave us
This gave us the vary we wished.
However does this equation truly behave the way in which we anticipated it to do?
Right here, our purpose is to grasp the instinct behind the construction of the sigmoid perform.
There are different features that may map values to the vary 0 to 1, and why logistic regression makes use of sigmoid is said to odds and log-odds, a subject which we’ll discover in future blogs.
Does the Sigmoid Behave the Means We Anticipated?
Let’s take a look at on few values.
First, let’s take into account
Substituting into the sigmoid perform:
as
we get
When the enter is 0, the sigmoid provides us precisely 0.5.
Now let’s take a constructive quantity
then
We already seen
which supplies
The sigmoid transformed the enter 2 into roughly 0.881 or 88.1%.
Now let’s have a look at what occurs when the enter is a destructive quantity.
Contemplate
Then
We all know
Lastly we get
So the sigmoid transformed the enter -2 into roughly 0.119 or 11.9%.
Now we will see how the sigmoid behaves.
For a destructive enter:
For zero:
For a constructive enter:
In order x will increase, the sigmoid output strikes from values near 0, passes via 0.5 and strikes towards 1.
Within the excessive instances:
and
That is precisely the habits we wished from a perform that transforms any actual quantity into one thing between 0 and 1.

Now we have now an thought of how we received the equation of the sigmoid perform.
When you bear in mind, in my latest blogs, after we mentioned backpropagation and neural networks basically, we talked about activation features and why they’re vital.
We used the ReLU activation perform to grasp these ideas.
Now, we will additionally use sigmoid as an activation perform.
But when we use sigmoid as an activation perform, there’s yet another factor we have to know.
Throughout the backward go, we already know that the community calculates gradients utilizing derivatives.
So, if sigmoid is a part of the community, we have to differentiate it as nicely.
Now let’s focus solely on deriving the spinoff of the sigmoid perform step-by-step.
As an alternative of carrying the exponential time period all through calculations, we will merely use the sigmoid output itself.
That is the spinoff we use at any time when sigmoid seems within the gradient calculations of a neural community.
···
Abstract
Within the upcoming blogs, we’re going to focus on subjects like vanishing gradients and exploding gradients.
As we discover these subjects, we’ll come throughout the sigmoid perform, and we may even want its spinoff.
If we derive the sigmoid perform and its spinoff in these blogs, the dialogue may grow to be lengthy, and we might lose give attention to the precise idea that we try to grasp.
It could even be higher to have an thought of the place the sigmoid perform and its spinoff come from earlier than utilizing them in additional ideas.
We first began with the financial institution instance to see how e seems. We then realized about its vital property in calculus and, utilizing these concepts, steadily constructed the sigmoid equation.
We noticed how this equation is utilized in logistic regression and neural networks, and we additionally derived its spinoff.
Now, after we transfer on to the upcoming subjects, we have already got this basis which will likely be helpful for us.
I hope you discovered this weblog useful in understanding an idea that we often use.
If in case you have any questions or strategies for enchancment, be happy to share them within the feedback on LinkedIn.
And if you have not learn my newest weblog collection on backpropagation but, you possibly can learn it right here.
Generally, shifting ahead means going again and understanding the fundamentals.
Thanks for studying!
···
















