Accord.Statistics.Links.InverseSquaredLinkFunction.Derivative C# (CSharp) Method

Derivative() public method

First derivative of the Inverse function.
public Derivative ( double x ) : double
x double The input value.
return double
        public double Derivative(double x)
        {
            return -0.5 * B * Math.Pow(B * x + A, -1.5);
        }

Usage Example

        public void DerivativeTest()
        {
            double beta = 3.14;
            double constant = 2.91;

            double[] expected =
            {
                -0.316272, -0.271211, -0.235919, -0.207668, -0.184638,
                -0.16557, -0.149573, -0.135995, -0.124354, -0.114284, -0.105503
            };

            InverseSquaredLinkFunction target = new InverseSquaredLinkFunction(beta, constant);

            for (int i = 0; i < 11; i++)
            {
                double x = i / 10.0;
                double y = target.Inverse(x);

                double d1 = target.Derivative(x);
                double d2 = target.Derivative2(y);

                Assert.AreEqual(expected[i], d1, 1e-6);
                Assert.AreEqual(expected[i], d2, 1e-6);

                Assert.IsFalse(Double.IsNaN(d1));
                Assert.IsFalse(Double.IsNaN(d2));
            }
        }