function value = sigmoid_value ( n, x )

%*****************************************************************************80
%
%% sigmoid_value(): evaluate sigmoid derivative at x.
%
%  Discussion:
%
%    s(x) = 1 / ( 1 + exp ( - x ) )
%
%    s(x)^(n) = sum ( 1 <= j <= n + 1 ) coef(j) * s(x)^j 
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    22 May 2024
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Joe McKenna,
%    Derivatives of the sigmoid function,
%    https://joepatmckenna.github.io/calculus/derivative/sigmoid%20function/linear%20albegra/2018/01/20/sigmoid-derivs/
%
%  Input:
%
%    integer n: the order of the derivative.
%
%    real x: the evaluation point.
%
%  Output:
%
%    real value: the value of s^(n)(x).
%
  sig = 1.0 / ( 1.0 + exp ( - x ) );
  value = 0.0;
  sigk = 1.0;

  for k = 0 : n
    sigk = sigk * sig;
    cnk = 0.0;
    mop = -1.0;
    for j = 0 : k
      mop = - mop;
      cnk = cnk + mop * ( j + 1 )^n * nchoosek ( k, j );
    end
    value = value + cnk * sigk;
  end

  return
end

