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)); } }
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 TestException() { var fn = new InverseSquaredLinkFunction(); double[] x = { 1, 2 }; fn.Evaluate(x); }
public void TestEvaluate() { var fn = new InverseSquaredLinkFunction(); double[] x = { 2 }; double y = fn.Evaluate(x); Assert.AreEqual(-0.25, y, AIFH.DefaultPrecision); }
public void InverseSquaredLinkFunctionConstructorTest() { InverseSquaredLinkFunction target = new InverseSquaredLinkFunction(); Assert.AreEqual(0, target.A); Assert.AreEqual(1, target.B); for (int i = 0; i < 11; i++) { double x = i / 10.0; double y = 1 / (x * x); Assert.AreEqual(y, target.Function(x), 1e-10); Assert.AreEqual(x, target.Inverse(y), 1e-10); } }
public void InverseSquaredLinkFunctionConstructorTest1() { double beta = 3.14; double constant = 2.91; InverseSquaredLinkFunction target = new InverseSquaredLinkFunction(beta, constant); Assert.AreEqual(constant, target.A); Assert.AreEqual(beta, target.B); for (int i = 0; i < 11; i++) { double x = i / 10.0; double y = (1 / (x * x) - constant) / beta; Assert.AreEqual(y, target.Function(x), 1e-10); Assert.AreEqual(x, target.Inverse(y), 1e-10); } }