Answers.Body: <p>This derivative is used when calculating the error of your machine learning algorithm during gradient based minimization methods. 
  Read below for more info. </p>
  
  <p>When performing supervised classification (with X, Y data vectors of inputs and outcome data to train with) you begin with the error function </p>
  
  <p>E(X, Y; &theta;)= &sum;<sub>i</sub> (&fnof;(x<sub>i</sub>; &theta;)-y<sub>i</sub>)<sup>2</sup></p>
  
  <p>for total error over all data instances i, where f is your neural network, linear regression,...method of interest and &theta; is the set of weights. The goal here is to find weights that minimize your error when predicting training data (y) (which ideally generalizes to new data as well). To be explicit, &fnof;(x<sub>i</sub>; &theta;); outputs value of interest which should be y<sub>i</sub>. And E measures how far off it is in prediction. </p>
  
  <p>So to train your classifier, you optimize E with something like gradient descent. Thus when &part;E/&part;&theta; = 0 (for a particular &theta;), that means you hit a local minimum for the error function, or a point where the error in the current state of the predictor is low, meaning it is (hopefully) a good predictor.</p>
  
  <p>Note the &fnof; here is not the same as an activation function, as a neural network is defined differently than in linear regression, etc. and must perform a special kind of gradient descent called backpropagation. </p>
  
  <p>So when you take &part;E/&part;&theta;, what does it equal for a neural net? You should note the activation functions derivative is involved which is how it’s used to measure error so to say. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-01T16:27:52.320Z
Answers.LastActivityDate: 2017-12-01T19:09:47.183Z
Answers.LastEditDate: 2017-12-01T19:09:47.183Z
Answers.UserDisplayName: sma
Answers.Body: <p>You dont need a sigmoid function if you dont want one.  Any differentiable function will do.  Sigmoid functions are just one of many suitable functions. You could write your own differentiable function if you want a propriety solution. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-01T03:29:59.720Z
Answers.Text: PS: The function must be diferrentiable for back-propogation reasons.
Answers.UserDisplayName: solarflare
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-01T02:46:02.760Z
Answers.LastActivityDate: 2017-12-01T02:46:02.760Z
Answers.UserDisplayName: solarflare
Answers.Body: <p>Measuring the error rate of a neural network does not involve the derivative of the sigmoid function at all. It only needs the neural networks outputs, and the expected outputs. It does not matter how the neural network got to those outputs, the outputs only have to be based on the inputs. What the other of that specific text is trying to say is that the derivative of the sigmoid function is important when you use the algorithm back propagation to train the neural network. This method involves using derivatives to optimize the neural network. While this technique is more complicated with neural networks because of how many variables are involved, you can easily see the basics of this approach if you look at a calculus textbook and look at the chapter that is usually titled Applications of the derivative.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2017-12-01T00:39:55.820Z
Answers.LastActivityDate: 2018-06-22T20:49:44.953Z
Answers.LastEditDate: 2018-06-22T20:49:44.953Z
Answers.UserDisplayName: Aiden Grossman
Answers.Body: <p>In order to train a neural network, you have to adjust each weights and biases to reduce the cost to as minimum as possible. The only way to do so is to subtract a small amount of the partial derivative of cost w.r.t. w, b from the respective parameters.</p>
  
  <p>if J is our cost function, after each iteration:</p>
  
  <pre><code>w = w - lr*dJ_dw,      //where lr is a small scalar called learning rate and dJ_dw is the partial derivative of cost function w.r.t. w
  </code></pre>
  
  <p>and same for bias</p>
  
  <pre><code>b = b - lr*dJ_db,    //dJ_db is the partial derivative of cost function w.r.t b
  </code></pre>
  
  <p>let's look at how the partial derivatives are calculated.</p>
  
  <p>using sigmoid as activation function, and squared error function as cost, we have:</p>
  
  <pre><code>z = w*x + b
  a = sigmoid(z)       // sigmoid(z) = 1.0 / (1.0 + exp(-z)), a is the final output
  
  J = (a - y)*(a - y)  // where y is the expected output
  </code></pre>
  
  <p>For us to calculate partial derivatives of this cost function w.r.t. w, b, we need to use, chain rule of derivatives as:</p>
  
  <pre><code>dJ_dw = dJ_da * da_dz * dz_dw    // dJ_da is the partial derivative of cost w.r.t. activation, a
  dJ_db = dJ_da * da_dz * dz_db
  </code></pre>
  
  <p>in the above equations, <strong><em>da_dz</em></strong> is the derivative of activation function (sigmoid in our case) which is <strong><em>sigmoid(z).(1 - sigmoid(z))</em></strong></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-22T07:06:53.663Z
Answers.LastActivityDate: 2018-06-22T07:06:53.663Z
Answers.UserDisplayName: Mahesh Nepal
Answers.Body: <p>The derivative of your loss is the "slope" at that given prediction. So by "moving down along the slope", we can reduce the value of the loss function. </p>
  
  <p>Intuitively, one can imagine a ball rolling down a slope in the direction of the tangent. Eventually the ball will roll towards the lowest point (global minima), or a small pothole (local minima), or even some weird looking shape (saddle point) if you are very unlucky.</p>
  
  <p>With some fixed input/output pair, we can consider the loss function as a value of the parameters (weights). Here, the Z axis is the value of your loss <em>f</em> (what you are trying to optimize), while the X,Y axis are the parameters of the loss <em>f</em> (what you are allowed change):</p>
  
  <p><a href="https://i.sstatic.net/sMaC5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sMaC5.png" alt="enter image description here"></a> </p>
  
  <p>Note that the image provided is a bit misleading. In practice, we only know the value of the loss function at the location we have probed. The entire graph can only be drawn if we evaluate the loss function for every parameter. So we can't just look at the picture and know which location is the best.</p>
  
  <p>Recall that the goal of the prediction task is to update the parameters in a way such that we minimize the loss function for some given input/output pair. Assuming the loss function is reasonably smooth, then our best bet of reaching a lower value of the error rate is by taking a small step towards the direction of the slope, which is the derivative of the function. The size of the "small step" is called the learning rate. </p>
  
  <p>Under the assumption that the loss function looks similar given different input/output pairs, by iteratively moving down the slope for each datapoint, we can eventually reach a "good" set of weights that give a low error.</p>
  
  <p>This is the motivation and idea of the back-propagation algorithm. </p>
  
  <p>A good follow-up question might be: Why do we say that the loss function is  similar given different data points? This is basically the same as assuming that there is some regularity in the data such that there is a "most normal looking loss function" that the data-set naturally approaches.</p>
  
  <p>Hopefully that helps!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-01T21:32:55.040Z
Answers.LastActivityDate: 2017-12-01T21:32:55.040Z
Answers.UserDisplayName: k.c. sayz 'k.c sayz'
Body: <p>A blog post called "Text Classification using Neural Networks" states that the derivative of the output of a sigmoid function is used to measure error rates.</p>
  
  <p>What is the rationale for this?</p>
  
  <p>I thought the derivative of a sigmoid function output is just the slope of the sigmoid line at a specific point. </p>
  
  <p>Meaning it's steepest when sigmoid output is 0.5 (occuring when the sigmoid function input is 0).</p>
  
  <p>Why does a sigmoid function input of 0 imply error (if i understand correctly)?</p>
  
  <p><strong>Source:</strong> <a href="https://machinelearnings.co/text-classification-using-neural-networks-f5cd7b8765c6" rel="nofollow noreferrer">https://machinelearnings.co/text-classification-using-neural-networks-f5cd7b8765c6</a></p>
  
  <blockquote>
    <p>We use a sigmoid function to normalize values and its derivative to
    measure the error rate. Iterating and adjusting until our error rate
    is acceptably low.</p>
  </blockquote>
  
  <pre><code>def sigmoid(x):
      output = 1/(1+np.exp(-x))
      return output
  
  def sigmoid_output_to_derivative(output):
      return output*(1-output)
  
  def train(...)
      ...
      layer_2_error = y - layer_2
      layer_2_delta = layer_2_error * sigmoid_output_to_derivative(layer_2)
      ...
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Apologies. I don't think I was clear (I've updated the title)</p>
  
  <p>I understand we don't need to use sigmoid as the activation funtion (we could use relu, tanh or softmax).</p>
  
  <p>My question is about using the <code>derivative to measure the error rate</code> (full quotation from article above in yellow) -> what does the derivative of the activation function have to do with measuring/fixing the "error rate"?</p>
  
Tags: <neural-networks><training>
Title: How does an activation function's derivative measure error rate in a neural network?
UserDisplayName: tim_xyz
ThreadText: # How does an activation function's derivative measure error rate in a neural network?
  
  (Asked by: username_0 on 2017-11-30)
  
  A blog post called "Text Classification using Neural Networks" states that the derivative of the output of a sigmoid function is used to measure error rates.
  What is the rationale for this?
  I thought the derivative of a sigmoid function output is just the slope of the sigmoid line at a specific point. 
  Meaning it's steepest when sigmoid output is 0.5 (occuring when the sigmoid function input is 0).
  Why does a sigmoid function input of 0 imply error (if i understand correctly)?
  Source: https://machinelearnings.co/text-classification-using-neural-networks-f5cd7b8765c6
  
  We use a sigmoid function to normalize values and its derivative to
    measure the error rate. Iterating and adjusting until our error rate
    is acceptably low.
  
  def sigmoid(x):
      output = 1/(1+np.exp(-x))
      return output
  
  def sigmoid_output_to_derivative(output):
      return output*(1-output)
  
  def train(...)
      ...
      layer_2_error = y - layer_2
      layer_2_delta = layer_2_error * sigmoid_output_to_derivative(layer_2)
      ...
  
  UPDATE
  Apologies. I don't think I was clear (I've updated the title)
  I understand we don't need to use sigmoid as the activation funtion (we could use relu, tanh or softmax).
  My question is about using the derivative to measure the error rate (full quotation from article above in yellow) -> what does the derivative of the activation function have to do with measuring/fixing the "error rate"?
  
  **Tags:** neural-networks, training
  
  ---
  
  ## 5 answers
  
  ### Answer by username_1 on 2017-12-01. Score: 4
  
  This derivative is used when calculating the error of your machine learning algorithm during gradient based minimization methods.
  Read below for more info.
  
  When performing supervised classification (with X, Y data vectors of inputs and outcome data to train with) you begin with the error function
  
  E(X, Y; θ)= ∑i (ƒ(xi; θ)-yi)2
  
  for total error over all data instances i, where f is your neural network, linear regression,...method of interest and θ is the set of weights. The goal here is to find weights that minimize your error when predicting training data (y) (which ideally generalizes to new data as well). To be explicit, ƒ(xi; θ); outputs value of interest which should be yi. And E measures how far off it is in prediction.
  
  So to train your classifier, you optimize E with something like gradient descent. Thus when ∂E/∂θ = 0 (for a particular θ), that means you hit a local minimum for the error function, or a point where the error in the current state of the predictor is low, meaning it is (hopefully) a good predictor.
  
  Note the ƒ here is not the same as an activation function, as a neural network is defined differently than in linear regression, etc. and must perform a special kind of gradient descent called backpropagation.
  
  So when you take ∂E/∂θ, what does it equal for a neural net? You should note the activation functions derivative is involved which is how it’s used to measure error so to say.
  
  
  ---
  
  ### Answer by username_2 on 2017-12-01. Score: 2
  
  You dont need a sigmoid function if you dont want one. Any differentiable function will do. Sigmoid functions are just one of many suitable functions. You could write your own differentiable function if you want a propriety solution.
  
  > **Comments:**
  > **username_2**: PS: The function must be diferrentiable for back-propogation reasons.  
  
  ---
  
  ### Answer by username_3 on 2017-12-01. Score: 1
  
  Measuring the error rate of a neural network does not involve the derivative of the sigmoid function at all. It only needs the neural networks outputs, and the expected outputs. It does not matter how the neural network got to those outputs, the outputs only have to be based on the inputs. What the other of that specific text is trying to say is that the derivative of the sigmoid function is important when you use the algorithm back propagation to train the neural network. This method involves using derivatives to optimize the neural network. While this technique is more complicated with neural networks because of how many variables are involved, you can easily see the basics of this approach if you look at a calculus textbook and look at the chapter that is usually titled Applications of the derivative.
  
  
  ---
  
  ### Answer by username_4 on 2018-06-22. Score: 0
  
  In order to train a neural network, you have to adjust each weights and biases to reduce the cost to as minimum as possible. The only way to do so is to subtract a small amount of the partial derivative of cost w.r.t. w, b from the respective parameters.
  if J is our cost function, after each iteration:
  w = w - lr*dJ_dw,      //where lr is a small scalar called learning rate and dJ_dw is the partial derivative of cost function w.r.t. w
  
  and same for bias
  b = b - lr*dJ_db,    //dJ_db is the partial derivative of cost function w.r.t b
  
  let's look at how the partial derivatives are calculated.
  using sigmoid as activation function, and squared error function as cost, we have:
  z = w*x + b
  a = sigmoid(z)       // sigmoid(z) = 1.0 / (1.0 + exp(-z)), a is the final output
  
  J = (a - y)*(a - y)  // where y is the expected output
  
  For us to calculate partial derivatives of this cost function w.r.t. w, b, we need to use, chain rule of derivatives as:
  dJ_dw = dJ_da * da_dz * dz_dw    // dJ_da is the partial derivative of cost w.r.t. activation, a
  dJ_db = dJ_da * da_dz * dz_db
  
  in the above equations, da_dz is the derivative of activation function (sigmoid in our case) which is sigmoid(z).(1 - sigmoid(z))
  
  
  ---
  
  ### Answer by username_5 on 2017-12-01. Score: 0
  
  The derivative of your loss is the "slope" at that given prediction. So by "moving down along the slope", we can reduce the value of the loss function.
  
  Intuitively, one can imagine a ball rolling down a slope in the direction of the tangent. Eventually the ball will roll towards the lowest point (global minima), or a small pothole (local minima), or even some weird looking shape (saddle point) if you are very unlucky.
  
  With some fixed input/output pair, we can consider the loss function as a value of the parameters (weights). Here, the Z axis is the value of your loss *f* (what you are trying to optimize), while the X,Y axis are the parameters of the loss *f* (what you are allowed change):
  
  [![enter image description here](https://i.sstatic.net/sMaC5.png)](https://i.sstatic.net/sMaC5.png)
  
  Note that the image provided is a bit misleading. In practice, we only know the value of the loss function at the location we have probed. The entire graph can only be drawn if we evaluate the loss function for every parameter. So we can't just look at the picture and know which location is the best.
  
  Recall that the goal of the prediction task is to update the parameters in a way such that we minimize the loss function for some given input/output pair. Assuming the loss function is reasonably smooth, then our best bet of reaching a lower value of the error rate is by taking a small step towards the direction of the slope, which is the derivative of the function. The size of the "small step" is called the learning rate.
  
  Under the assumption that the loss function looks similar given different input/output pairs, by iteratively moving down the slope for each datapoint, we can eventually reach a "good" set of weights that give a low error.
  
  This is the motivation and idea of the back-propagation algorithm.
  
  A good follow-up question might be: Why do we say that the loss function is similar given different data points? This is basically the same as assuming that there is some regularity in the data such that there is a "most normal looking loss function" that the data-set naturally approaches.
  
  Hopefully that helps!
  
  
  ---
  
  