public virtual void testPerfectFitVector()
        {
//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 LeastSquareResults results = gls.solve(X_TRIG, Y_TRIG, SIGMA_TRIG, VECTOR_TRIG_FUNCTIONS);
            LeastSquareResults results = gls.solve(X_TRIG, Y_TRIG, SIGMA_TRIG, VECTOR_TRIG_FUNCTIONS);

            assertEquals(0.0, results.ChiSq, 1e-8);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray w = results.getFitParameters();
            DoubleArray w = results.FitParameters;

            for (int i = 0; i < WEIGHTS.Length; i++)
            {
                assertEquals(WEIGHTS[i], w.get(i), 1e-8);
            }
        }
        public virtual void testFit()
        {
//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[] y = new double[Y.length];
            double[] y = new double[Y.Length];
            for (int i = 0; i < Y.Length; i++)
            {
                y[i] = Y[i] + SIGMA[i] * NORMAL.nextRandom();
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LeastSquareResults results = gls.solve(X, y, SIGMA, SIN_FUNCTIONS);
            LeastSquareResults results = gls.solve(X, y, SIGMA, SIN_FUNCTIONS);

            assertTrue(results.ChiSq < 3 * Y.Length);
        }
        public virtual void testPSplineFit()
        {
//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 GeneralizedLeastSquareResults<double> results = gls.solve(X, Y, SIGMA, BASIS_FUNCTIONS, 1000.0, 2);
            GeneralizedLeastSquareResults <double> results = gls.solve(X, Y, SIGMA, BASIS_FUNCTIONS, 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;
            assertEquals(2225.7, results.ChiSq, 1e-1);
            assertEquals(-0.758963811327287, spline(1.1), 1e-8);

            /*
             * Print out function for debugging
             */
            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 x = 0 + i * 2.0 / 100.0;
                    double x = 0 + i * 2.0 / 100.0;
                    Console.WriteLine(x + "\t" + spline(x));
                }
                for (int i = 0; i < X.Length; i++)
                {
                    Console.WriteLine(X[i] + "\t" + Y[i]);
                }
            }
        }
        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]);
                }
            }
        }