public Transform ( double input ) : double[] | ||
input | double | The input point to be projected into feature space. |
return | double[] |
/// <summary> /// Projects an input point into feature space. /// </summary> /// /// <param name="input">The input point to be projected into feature space.</param> /// /// <returns> /// The feature space representation of the given <paramref name="input"/> point. /// </returns> /// public double[] Transform(double[] input) { switch (degree) { case 1: return(Linear.Transform(input, constant)); case 2: return(Quadratic.Transform(input, constant)); default: return(Transform(input, degree, constant)); } }
public void ExpandReverseDistanceWithConstantTest() { Quadratic kernel = new Quadratic(4.2); var x = new double[] { 0.5, 2.0 }; var y = new double[] { 1.3, -0.2 }; var phi_x = kernel.Transform(x); var phi_y = kernel.Transform(y); double d = Distance.SquareEuclidean(x, y); double phi_d = kernel.ReverseDistance(phi_x, phi_y); Assert.AreEqual(5.48, phi_d, 1e-10); Assert.AreEqual(5.48, d); Assert.IsFalse(double.IsNaN(phi_d)); Assert.IsFalse(double.IsNaN(d)); }
public void ExpandReverseDistanceTest() { Quadratic kernel = new Quadratic(0); var x = new double[] { 0.5, 2.0 }; var y = new double[] { 1.3, -0.2 }; var phi_x = kernel.Transform(x); var phi_y = kernel.Transform(y); double d = Distance.SquareEuclidean(x, y); double phi_d = kernel.ReverseDistance(phi_x, phi_y); Assert.AreEqual(phi_d, d); }
public void ExpandDistanceWithConstantTest() { Quadratic kernel = new Quadratic(4.2); var x = new double[] { 0.5, 2.0 }; var y = new double[] { 1.3, -0.2 }; var phi_x = kernel.Transform(x); var phi_y = kernel.Transform(y); double d1 = Distance.SquareEuclidean(phi_x, phi_y); double d2 = kernel.Distance(x, y); double d3 = Accord.Statistics.Tools.Distance(kernel, x, y); Assert.AreEqual(66.9624, d1); Assert.AreEqual(66.9624, d2, 1e-10); Assert.AreEqual(66.9624, d3, 1e-10); Assert.IsFalse(double.IsNaN(d1)); Assert.IsFalse(double.IsNaN(d2)); Assert.IsFalse(double.IsNaN(d3)); }
public void TransformTest_Quadratic() { double[][] data = { new double[] { 5.1, 3.5, 1.4, 0.2 }, new double[] { 5.0, 3.6, 1.4, 0.2 }, new double[] { 4.9, 3.0, 1.4, 0.2 }, new double[] { 5.8, 4.0, 1.2, 0.2 }, new double[] { 4.7, 3.2, 1.3, 0.2 }, }; var target = new Polynomial(2); var quadratic = new Quadratic(); double[][] expected = data.Apply(x => quadratic.Transform(x)); double[][] actual = data.Apply(target.Transform); Assert.IsTrue(expected.IsEqual(actual, 1e-10)); }