There are many times that you will want to take the derivative of an expression. Taking a derivative is a very common thing to do in Machine Learning. One example is the activation function of a neural network. If you are going to train the neural network using any of the backpropagation techniques, you will need the derivative of the activation function. In this article I will show you how to take the derivative of a function using R.
For this article we will obtain the derivative of the Sigmoid Activation Function. You might be tempted to create a function for the sigmoid. This can be done as follows.


Once the sigmoid function has been created it can easily be queried as follows.


The above code would produce 0.5. Functions are useful when you need to graph the function. However, to take the derivative you must produce an expression. This is done as follows.


This produces the following.


If you would like to simplify the above, use the following.

