Accord.Math.Differentiation.FiniteDifferences.derivative C# (CSharp) Method

derivative() private method

Computes the derivative at point x_i.
private derivative ( double x, int index, double output ) : double
x double
index int
output double
return double
        private double derivative(double[] x, int index, double output)
        {
            // Saves the original parameter value

            double original = x[index];
            int order = orders[index];
            double step = stepSizes[index];

            if (original != 0.0)
                step *= System.Math.Abs(original);

            // Create the interpolation points
            var points = new double[pointCount];
            int center = (points.Length - 1) / 2;

            for (int i = 0; i < points.Length; i++)
            {
                if (i != center)
                {
                    // Make a small perturbation in the original parameter
                    x[index] = original + (i - center) * step;

                    // Recompute the function to measure its importance
                    points[i] = Function(x);
                }
                else
                {
                    // The center point is the original function
                    points[i] = output;
                }
            }

            // Reverts the modified value
            x[index] = original;

            return Interpolate(coefficients, points, order, center, step);
        }