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);
        }
        public void DerivativeTest()
        {
            double beta     = 0.52;
            double constant = 2.42;

            double[] expected =
            {
                5.84785, 6.15998, 6.48877, 6.83512, 7.19995, 7.58425,
                7.98906, 8.41549, 8.86467, 9.33783, 9.83624
            };

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

                Assert.IsFalse(Double.IsNaN(d1));
                Assert.IsFalse(Double.IsNaN(d2));
            }
        }
Example #3
0
        public void TestException()
        {
            var fn = new LogLinkFunction();

            double[] x = { 1, 2 };
            fn.Evaluate(x);
        }
Example #4
0
        public void TestEvaluate()
        {
            var fn = new LogLinkFunction();

            double[] x = { 2 };
            double   y = fn.Evaluate(x);

            Assert.AreEqual(0.6931471805599453, y, AIFH.DefaultPrecision);
        }
        public void LogLinkFunctionConstructorTest2()
        {
            LogLinkFunction target = new LogLinkFunction();

            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(x);

                Assert.AreEqual(y, target.Function(x), 1e-10);
                Assert.AreEqual(x, target.Inverse(y), 1e-10);
            }
        }
        public void LogLinkFunctionConstructorTest()
        {
            double          beta     = 0.52;
            double          constant = 2.42;
            LogLinkFunction target   = new LogLinkFunction(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(x) - constant) / beta;

                Assert.AreEqual(y, target.Function(x), 1e-10);
                Assert.AreEqual(x, target.Inverse(y), 1e-10);
            }
        }
        public void TestBasic()
        {
            var reg = new MultipleLinearRegression(1);

            Assert.AreEqual(2, reg.LongTermMemory.Length);

            var lnk = new LogLinkFunction();

            reg.LinkFunction = lnk;
            Assert.IsTrue(reg.LinkFunction == lnk);

            reg.LongTermMemory[0] = 1;
            reg.LongTermMemory[1] = 2;

            double[] input  = { 1.0 };
            double[] output = reg.ComputeRegression(input);
            Assert.AreEqual(1, output.Length);
            Assert.AreEqual(1.0986122886681098, output[0], AIFH.DefaultPrecision);
        }