public void FitTest1() { double[] values = { 0, 1, 2, 4, 2, 3, 5, 7, 4, 3, 2, 1, 4, }; var exp = new ExponentialDistribution(); exp.Fit(values); string actual; var cultureInfo = CultureInfo.GetCultureInfo("fr-FR"); #if NETCORE System.Globalization.CultureInfo.DefaultThreadCurrentCulture = cultureInfo; System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = cultureInfo; #else Thread.CurrentThread.CurrentCulture = cultureInfo; #endif actual = exp.ToString("G3", CultureInfo.InvariantCulture); Assert.AreEqual("Exp(x; λ = 0.342)", actual); actual = exp.ToString("G3"); Assert.AreEqual("Exp(x; λ = 0,342)", actual); actual = exp.ToString(CultureInfo.InvariantCulture); Assert.AreEqual("Exp(x; λ = 0.342105263157895)", actual); actual = exp.ToString(); Assert.AreEqual("Exp(x; λ = 0,342105263157895)", actual); }
public void ToStringTest() { // Issue 51: SimpleLinearRegression regression = new SimpleLinearRegression(); var x = new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var y = new double[] { 1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321 }; regression.Regress(x, y); { string expected = "y(x) = 32x + -44"; expected = expected.Replace(".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator); string actual = regression.ToString(); Assert.AreEqual(expected, actual); } { string expected = "y(x) = 32x + -44"; string actual = regression.ToString(null, CultureInfo.GetCultureInfo("en-US")); Assert.AreEqual(expected, actual); } { string expected = "y(x) = 32.0x + -44.0"; string actual = regression.ToString("N1", CultureInfo.GetCultureInfo("en-US")); Assert.AreEqual(expected, actual); } { string expected = "y(x) = 32,00x + -44,00"; string actual = regression.ToString("N2", CultureInfo.GetCultureInfo("pt-BR")); Assert.AreEqual(expected, actual); } }
public void RegressTest6() { MultipleLinearRegression target = new MultipleLinearRegression(2, false); double[][] inputs = { new double[] { 0, 0 }, new double[] { 0, 0 }, new double[] { 0, 0 }, new double[] { 0, 0 }, new double[] { 0, 0 }, }; double[] outputs = { 20, 40, 30, 50, 60 }; double error = target.Regress(inputs, outputs); double slope = target.Coefficients[0]; double intercept = target.Coefficients[1]; Assert.AreEqual(0, slope, 1e-5); Assert.AreEqual(0, intercept, 1e-5); Assert.AreEqual(9000, error); double r = target.CoefficientOfDetermination(inputs, outputs); Assert.AreEqual(-8, r, 1e-6); string str = target.ToString(null, CultureInfo.GetCultureInfo("pt-BR")); Assert.AreEqual("y(x0, x1) = 0*x0 + 0*x1", str); }
public void ToStringTest() { // Issue 51: PolynomialRegression poly = new PolynomialRegression(2); var x = new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var y = new double[] { 1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321 }; poly.Regress(x, y); { string expected = "y(x) = 3x^2 + 1.99999999999998x^1 + 1.00000000000005"; expected = expected.Replace(".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator); string actual = poly.ToString(); Assert.AreEqual(expected, actual); } { string expected = "y(x) = 3x^2 + 1.99999999999998x^1 + 1.00000000000005"; string actual = poly.ToString(null, CultureInfo.GetCultureInfo("en-US")); Assert.AreEqual(expected, actual); } { string expected = "y(x) = 3.0x^2 + 2.0x^1 + 1.0"; string actual = poly.ToString("N1", CultureInfo.GetCultureInfo("en-US")); Assert.AreEqual(expected, actual); } { string expected = "y(x) = 3,00x^2 + 2,00x^1 + 1,00"; string actual = poly.ToString("N2", CultureInfo.GetCultureInfo("pt-BR")); Assert.AreEqual(expected, actual); } }
public void RegressTest2() { var target = new MultipleLinearRegression(2, false); Assert.IsFalse(target.HasIntercept); double[][] inputs = { new double[] { 80, 1 }, new double[] { 60, 1 }, new double[] { 10, 1 }, new double[] { 20, 1 }, new double[] { 30, 1 }, }; double[] outputs = { 20, 40, 30, 50, 60 }; double error = target.Regress(inputs, outputs); Assert.AreEqual(2, target.NumberOfInputs); Assert.AreEqual(1, target.NumberOfOutputs); double slope = target.Coefficients[0]; double intercept = target.Coefficients[1]; Assert.AreEqual(-0.264706, slope, 1e-5); Assert.AreEqual(50.588235, intercept, 1e-5); Assert.AreEqual(761.764705, error, 1e-5); double r = target.CoefficientOfDetermination(inputs, outputs); Assert.AreEqual(0.23823529, r, 1e-6); string str = target.ToString(null, CultureInfo.GetCultureInfo("en-US")); Assert.AreEqual("y(x0, x1) = -0.264705882352941*x0 + 50.5882352941176*x1", str); }
public void RegressTest() { MultipleLinearRegression target = new MultipleLinearRegression(1, true); double[][] inputs = { new double[] { 80 }, new double[] { 60 }, new double[] { 10 }, new double[] { 20 }, new double[] { 30 }, }; double[] outputs = { 20, 40, 30, 50, 60 }; double error = target.Regress(inputs, outputs); Assert.AreEqual(1, target.NumberOfInputs); Assert.AreEqual(1, target.NumberOfOutputs); double slope = target.Coefficients[0]; double intercept = target.Coefficients[1]; Assert.AreEqual(-0.264706, slope, 1e-5); Assert.AreEqual(50.588235, intercept, 1e-5); Assert.AreEqual(761.764705, error, 1e-5); double r = target.CoefficientOfDetermination(inputs, outputs); Assert.AreEqual(0.23823529, r, 1e-6); string str = target.ToString(null, CultureInfo.GetCultureInfo("pt-BR")); Assert.AreEqual("y(x0) = -0,264705882352941*x0 + 50,5882352941176", str); }