static GeneralizedLeastSquareTest()
        {
            SIN_FUNCTIONS = new List <>();
            for (int i = 0; i < WEIGHTS.Length; i++)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int k = i;
                int k = i;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.function.Function<double, double> func = new java.util.function.Function<double, double>()
                System.Func <double, double> func = (final double?x) =>
                {
                    return(Math.Sin((2 * k + 1) * x));
                };
                SIN_FUNCTIONS.Add(func);
            }
            TEST_FUNCTION = new BasisFunctionAggregation <>(SIN_FUNCTIONS, WEIGHTS);

            VECTOR_TRIG_FUNCTIONS = new List <>();
            for (int i = 0; i < WEIGHTS.Length; i++)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int k = i;
                int k = i;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.function.Function<com.opengamma.strata.collect.array.DoubleArray, double> func = new java.util.function.Function<com.opengamma.strata.collect.array.DoubleArray, double>()
                System.Func <DoubleArray, double> func = (final DoubleArray x) =>
                {
                    ArgChecker.isTrue(x.size() == 2);
                    return(Math.Sin((2 * k + 1) * x.get(0)) * Math.Cos((2 * k + 1) * x.get(1)));
                };
                VECTOR_TRIG_FUNCTIONS.Add(func);
            }
            VECTOR_TEST_FUNCTION = new BasisFunctionAggregation <>(VECTOR_TRIG_FUNCTIONS, WEIGHTS);

            SIN_EXP_FUNCTION = (final double[] x) =>
            {
                return(Math.Sin(Math.PI * x[0] / 10.0) * Math.Exp(-x[1] / 5.0));
            };

            const int n = 10;

            X          = new double?[n];
            Y          = new double[n];
            SIGMA      = new double[n];
            X_TRIG     = new List <>();
            Y_TRIG     = new List <>();
            SIGMA_TRIG = new List <>();
            for (int i = 0; i < n; i++)
            {
                X[i] = i / 5.0;
                Y[i] = TEST_FUNCTION.apply(X[i]);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] temp = new double[2];
                double[] temp = new double[2];
                temp[0] = 2.0 * RANDOM.NextDouble();
                temp[1] = 2.0 * RANDOM.NextDouble();
                X_TRIG.Add(DoubleArray.copyOf(temp));
                Y_TRIG.Add(VECTOR_TEST_FUNCTION.apply(X_TRIG[i]));
                SIGMA[i] = 0.01;
                SIGMA_TRIG.Add(0.01);
            }

            SIGMA_COS_EXP = new List <>();
            X_SIN_EXP     = new List <>();
            Y_SIN_EXP     = new List <>();
            for (int i = 0; i < 20; i++)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] temp = new double[2];
                double[] temp = new double[2];
                temp[0] = 10.0 * RANDOM.NextDouble();
                temp[1] = 10.0 * RANDOM.NextDouble();
                X_SIN_EXP.Add(temp);
                Y_SIN_EXP.Add(SIN_EXP_FUNCTION.apply(X_SIN_EXP[i]));
                SIGMA_COS_EXP.Add(0.01);
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.math.impl.interpolation.BasisFunctionGenerator generator = new com.opengamma.strata.math.impl.interpolation.BasisFunctionGenerator();
            BasisFunctionGenerator generator = new BasisFunctionGenerator();

            BASIS_FUNCTIONS = generator.generateSet(BasisFunctionKnots.fromUniform(0.0, 2.0, 20, 3));
            BasisFunctionKnots[] knots = new BasisFunctionKnots[2];
            knots[0]           = BasisFunctionKnots.fromUniform(0, 10, 10, 3);
            knots[1]           = BasisFunctionKnots.fromUniform(0, 10, 10, 3);
            BASIS_FUNCTIONS_2D = generator.generateSet(knots);
        }
        public virtual void testPSplineFit2()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.math.impl.interpolation.BasisFunctionGenerator generator = new com.opengamma.strata.math.impl.interpolation.BasisFunctionGenerator();
            BasisFunctionGenerator generator = new BasisFunctionGenerator();
            IList <System.Func <double, double> > basisFuncs    = generator.generateSet(BasisFunctionKnots.fromUniform(0, 12, 100, 3));
            IList <System.Func <double, double> > basisFuncsLog = generator.generateSet(BasisFunctionKnots.fromUniform(-5, 3, 100, 3));

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final GeneralizedLeastSquare gls = new GeneralizedLeastSquare();
            GeneralizedLeastSquare gls = new GeneralizedLeastSquare();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] xData = new double[] {7.0 / 365, 14 / 365.0, 21 / 365.0, 1 / 12.0, 3 / 12.0, 0.5, 0.75, 1, 5, 10 };
            double[] xData = new double[] { 7.0 / 365, 14 / 365.0, 21 / 365.0, 1 / 12.0, 3 / 12.0, 0.5, 0.75, 1, 5, 10 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] yData = new double[] {0.972452371, 0.749039802, 0.759792085, 0.714206462, 0.604446956, 0.517955313, 0.474807307, 0.443532132, 0.2404755, 0.197128583};
            double[] yData = new double[] { 0.972452371, 0.749039802, 0.759792085, 0.714206462, 0.604446956, 0.517955313, 0.474807307, 0.443532132, 0.2404755, 0.197128583 };

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int n = xData.length;
            int n = xData.Length;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] lnX = new double[n];
            double[] lnX = new double[n];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] yData2 = new double[n];
            double[] yData2 = new double[n];
            for (int i = 0; i < n; i++)
            {
                lnX[i]    = Math.Log(xData[i]);
                yData2[i] = yData[i] * yData[i] * xData[i];
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] sigma = new double[n];
            double[] sigma = new double[n];
            Arrays.fill(sigma, 0.01);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final GeneralizedLeastSquareResults<double> results = gls.solve(xData, yData, sigma, basisFuncs, 1000.0, 2);
            GeneralizedLeastSquareResults <double> results = gls.solve(xData, yData, sigma, basisFuncs, 1000.0, 2);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.function.Function<double, double> spline = results.getFunction();
            System.Func <double, double> spline = results.Function;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final GeneralizedLeastSquareResults<double> resultsLog = gls.solve(lnX, yData, sigma, basisFuncsLog, 1000.0, 2);
            GeneralizedLeastSquareResults <double> resultsLog = gls.solve(lnX, yData, sigma, basisFuncsLog, 1000.0, 2);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.function.Function<double, double> splineLog = resultsLog.getFunction();
            System.Func <double, double> splineLog = resultsLog.Function;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final GeneralizedLeastSquareResults<double> resultsVar = gls.solve(xData, yData2, sigma, basisFuncs, 1000.0, 2);
            GeneralizedLeastSquareResults <double> resultsVar = gls.solve(xData, yData2, sigma, basisFuncs, 1000.0, 2);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.function.Function<double, double> splineVar = resultsVar.getFunction();
            System.Func <double, double> splineVar = resultsVar.Function;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final GeneralizedLeastSquareResults<double> resultsVarLog = gls.solve(lnX, yData2, sigma, basisFuncsLog, 1000.0, 2);
            GeneralizedLeastSquareResults <double> resultsVarLog = gls.solve(lnX, yData2, sigma, basisFuncsLog, 1000.0, 2);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.function.Function<double, double> splineVarLog = resultsVarLog.getFunction();
            System.Func <double, double> splineVarLog = resultsVarLog.Function;

            if (PRINT)
            {
                Console.WriteLine("Chi^2:\t" + results.ChiSq);
                Console.WriteLine("weights:\t" + results.FitParameters);

                for (int i = 0; i < 101; i++)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double logX = -5 + 8 * i / 100.0;
                    double logX = -5 + 8 * i / 100.0;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double x = Math.exp(logX);
                    double x = Math.Exp(logX);
                    Console.WriteLine(x + "\t" + +logX + "\t" + spline(x) + "\t" + splineLog(logX) + "\t" + splineVar(x) + "\t" + splineVarLog(logX));
                }
                for (int i = 0; i < n; i++)
                {
                    Console.WriteLine(lnX[i] + "\t" + yData[i]);
                }
            }
        }