Accord.Statistics.Kernels.TaylorGaussian.Transform C# (CSharp) Method

Transform() public method

Projects an input point into feature space.
public Transform ( double input ) : double[]
input double The input point to be projected into feature space.
return double[]
        public double[] Transform(double[] input)
        {
            // http://epubs.siam.org/doi/pdf/10.1137/1.9781611972818.19 

            double[] features = new double[coefficients.Length];

            features[0] = 1;

            for (int index = 1, k = 0; index < coefficients.Length; k++)
            {
                double alpha = coefficients[k];

                foreach (int[] s in Combinatorics.Sequences(input.Length, k + 1))
                {
                    double prod = 1.0;
                    for (int i = 0; i < s.Length; i++)
                        prod *= input[s[i]];

                    features[index++] = alpha * prod;
                    if (index >= coefficients.Length)
                        break;
                }
            }

            double norm = Norm.SquareEuclidean(input);
            double constant = Math.Exp(-gaussian.Gamma * norm);

            for (int i = 0; i < features.Length; i++)
                features[i] *= constant;

            return features;
        }

Usage Example

        public void ExpandReverseDistanceTest()
        {
            for (int i = 1; i <= 3; i++)
            {
                TaylorGaussian kernel = new TaylorGaussian(i);

                kernel.Degree = 64000;

                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, 1e-3);
                Assert.IsFalse(double.IsNaN(phi_d));
                Assert.IsFalse(double.IsNaN(d));
            }
        }
All Usage Examples Of Accord.Statistics.Kernels.TaylorGaussian::Transform