Derivative of the softmax function and the composite function of the cross entropy error

Let's write the derivative of the composition function of the softmax function and the cross entropy function in Perl.

In fact, the derivative of the softmax function is not so easy.

However, the derivative of the composite function of the softmax function and the cross entropy function is a simple expression.

Therefore, the derivative of the softmax function and the composite function of the cross entropy error is used for the inverse mispropagation method.

use strict;
use warnings;

#softmax Derivative of cross entropy error
sub softmax_cross_entropy_cost_derivative {
  my ($softmax_outputs, $desired_outputs) = @_;
  
  my $length = @$softmax_outputs;
  
  my $softmax_cross_entropy_cost_derivative = [];
  for (my $i = 0; $i <@$softmax_outputs; $i ++) {
    $softmax_cross_entropy_cost_derivative->[$i] = ($softmax_outputs->[$i]-$desired_outputs->[$i]) / $length;
  }
  
  return $softmax_cross_entropy_cost_derivative;
}

Associated Information