Exemplo n.º 1
0
        public void DerivativeTest()
        {
            LogLogLinkFunction target = new LogLogLinkFunction();

            double[] expected =
            {
                -0.367879, -0.365982, -0.360089, -0.349987, -0.335604, -0.317042,
                -0.294605, -0.268809, -0.240378, -0.210219, -0.179374
            };

            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-5);
                Assert.AreEqual(expected[i], d2, 1e-5);

                Assert.IsFalse(Double.IsNaN(d1));
                Assert.IsFalse(Double.IsNaN(d2));
            }
        }
Exemplo n.º 2
0
        public void DerivativeTest2()
        {
            double             beta     = 2;
            double             constant = 0.5;
            LogLogLinkFunction target   = new LogLogLinkFunction(beta, constant);

            double[] expected =
            {
                -0.634084,   -0.537619,   -0.420439,    -0.297894, -0.187093, -0.101414,
                -0.0459225, -0.0166933, -0.00464008, -0.000929341, -0.000124732
            };

            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-5);
                Assert.AreEqual(expected[i], d2, 1e-5);

                Assert.IsFalse(Double.IsNaN(d1));
                Assert.IsFalse(Double.IsNaN(d2));
            }
        }
        public static ILinkFunction Get(LinkFunctionType link)
        {
            ILinkFunction result = null;

            switch (link)
            {
            case LinkFunctionType.Absolute: result = new AbsoluteLinkFunction(); break;

            case LinkFunctionType.Cauchit: result = new CauchitLinkFunction(); break;

            case LinkFunctionType.Identity: result = new IdentityLinkFunction(); break;

            case LinkFunctionType.Inverse: result = new InverseLinkFunction(); break;

            case LinkFunctionType.InverseSquared: result = new InverseSquaredLinkFunction(); break;

            case LinkFunctionType.Logit: result = new LogitLinkFunction(); break;

            case LinkFunctionType.Log: result = new LogLinkFunction(); break;

            case LinkFunctionType.LogLog: result = new LogLogLinkFunction(); break;

            case LinkFunctionType.Probit: result = new ProbitLinkFunction(); break;

            case LinkFunctionType.Sin: result = new SinLinkFunction(); break;

            case LinkFunctionType.Threshold: result = new ThresholdLinkFunction(); break;
            }

            return(result);
        }
Exemplo n.º 4
0
        public void LogLogLinkFunctionConstructorTest2()
        {
            LogLogLinkFunction target = new LogLogLinkFunction();

            Assert.AreEqual(1, target.B);
            Assert.AreEqual(0, target.A);

            for (int i = 0; i < 11; i++)
            {
                double x = i / 10.0;
                double y = Math.Log(-Math.Log(x));

                Assert.AreEqual(y, target.Function(x), 1e-10);
                Assert.AreEqual(x, target.Inverse(y), 1e-10);
            }
        }
Exemplo n.º 5
0
        public void LogLogLinkFunctionConstructorTest()
        {
            double             beta     = 3.14;
            double             constant = 2.91;
            LogLogLinkFunction target   = new LogLogLinkFunction(beta, constant);

            Assert.AreEqual(beta, target.B);
            Assert.AreEqual(constant, target.A);

            for (int i = 0; i < 11; i++)
            {
                double x = i / 10.0;
                double y = (Math.Log(-Math.Log(x)) - constant) / beta;

                Assert.AreEqual(y, target.Function(x), 1e-10);
                Assert.AreEqual(x, target.Inverse(y), 1e-10);
            }
        }