CanvasPartition.WaveletSegmentation.GetInnerProdIter C# (CSharp) Method

GetInnerProdIter() private static method

For an input vector of length n, get_inner_prod_iter function computes inner products between the input vector and all possible n-1 Unbalanced Haar vectors of length n
private static GetInnerProdIter ( double x, double I_prod ) : void
x double
I_prod double
return void
        private static void GetInnerProdIter(double[] x, double[] I_prod)
        {
            long n = x.Length;
            double[] I_plus = new double[n - 1];
            double[] I_minus = new double[n - 1];

            I_plus[0] = Math.Sqrt(1 - 1.0 / n) * x[0];
            double sumX = 0; //summing from 2nd element to the end of vector X
            for (uint i = 1; i < n; i++)
            {
                sumX += x[i];
            }

            I_minus[0] = (1.0 / Math.Sqrt(n * (n - 1))) * sumX;

            if (n > 2)
            {
                for (uint m = 1; m < n - 1; m++)
                {
                    double factor = Math.Sqrt((double)((n - m - 1)) * m / (double)(m + 1) / (double)(n - m));
                    I_plus[m] = I_plus[m - 1] * factor + x[m] * Math.Sqrt(1.0 / (m + 1) - 1.0 / n);
                    I_minus[m] = I_minus[m - 1] / factor - (double)(x[m]) / (double)Math.Sqrt(((double)n * n / (double)(m + 1)) - (double)n);
                }
            }
            for (uint i = 0; i < n - 1; i++)
            {
                I_prod[i] = I_plus[i] - I_minus[i];
            }
        }