public virtual void testBSplineFit() { //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, Y, SIGMA, BASIS_FUNCTIONS); LeastSquareResults results = gls.solve(X, Y, SIGMA, BASIS_FUNCTIONS); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.function.Function<double, double> spline = new com.opengamma.strata.math.impl.interpolation.BasisFunctionAggregation<>(BASIS_FUNCTIONS, results.getFitParameters().toArray()); System.Func <double, double> spline = new BasisFunctionAggregation <double, double>(BASIS_FUNCTIONS, results.FitParameters.toArray()); assertEquals(0.0, results.ChiSq, 1e-12); assertEquals(-0.023605293, spline(0.5), 1e-8); 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 testBSplineFit2D() { //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_SIN_EXP, Y_SIN_EXP, SIGMA_COS_EXP, BASIS_FUNCTIONS_2D); LeastSquareResults results = gls.solve(X_SIN_EXP, Y_SIN_EXP, SIGMA_COS_EXP, BASIS_FUNCTIONS_2D); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.function.Function<double[], double> spline = new com.opengamma.strata.math.impl.interpolation.BasisFunctionAggregation<>(BASIS_FUNCTIONS_2D, results.getFitParameters().toArray()); System.Func <double[], double> spline = new BasisFunctionAggregation <double[], double>(BASIS_FUNCTIONS_2D, results.FitParameters.toArray()); assertEquals(0.0, results.ChiSq, 1e-16); assertEquals(0.05161579, spline(new double[] { 4, 3 }), 1e-8); /* * Print out function for debugging */ if (PRINT) { Console.WriteLine("Chi^2:\t" + results.ChiSq); Console.WriteLine("weights:\t" + results.FitParameters); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[] x = new double[2]; double[] x = new double[2]; for (int i = 0; i < 101; i++) { x[0] = 0 + i * 10.0 / 100.0; Console.Write("\t" + x[0]); } Console.Write("\n"); for (int i = 0; i < 101; i++) { x[0] = -0.0 + i * 10 / 100.0; Console.Write(x[0]); for (int j = 0; j < 101; j++) { x[1] = -0.0 + j * 10.0 / 100.0; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double y = spline.apply(x); double y = spline(x); Console.Write("\t" + y); } Console.Write("\n"); } } }