//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void test() public virtual void test() { const double a0 = 2.3; const double a1 = -4.5; const double a2 = 0.76; const double a3 = 3.4; const int n = 30; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[][] x = new double[n][3]; //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: double[][] x = new double[n][3]; double[][] x = RectangularArrays.ReturnRectangularDoubleArray(n, 3); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[] yIntercept = new double[n]; double[] yIntercept = new double[n]; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[] yNoIntercept = new double[n]; double[] yNoIntercept = new double[n]; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[][] w1 = new double[n][n]; //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: double[][] w1 = new double[n][n]; double[][] w1 = RectangularArrays.ReturnRectangularDoubleArray(n, n); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[] w2 = new double[n]; double[] w2 = new double[n]; double y, x1, x2, x3; for (int i = 0; i < n; i++) { x1 = i; x2 = x1 * x1; x3 = Math.Sqrt(x1); x[i] = new double[] { x1, x2, x3 }; y = x1 * a1 + x2 * a2 + x3 * a3; yNoIntercept[i] = y; yIntercept[i] = y + a0; for (int j = 0; j < n; j++) { w1[i][j] = RANDOM.NextDouble(); } w1[i][i] = 1.0; w2[i] = 1.0; } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final WeightedLeastSquaresRegression wlsRegression = new WeightedLeastSquaresRegression(); WeightedLeastSquaresRegression wlsRegression = new WeightedLeastSquaresRegression(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final OrdinaryLeastSquaresRegression olsRegression = new OrdinaryLeastSquaresRegression(); OrdinaryLeastSquaresRegression olsRegression = new OrdinaryLeastSquaresRegression(); try { wlsRegression.regress(x, (double[])null, yNoIntercept, false); Assert.fail(); } //JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#: //ORIGINAL LINE: catch (final IllegalArgumentException e) catch (legalArgumentException) { // Expected } LeastSquaresRegressionResult wls = wlsRegression.regress(x, w1, yIntercept, true); LeastSquaresRegressionResult ols = olsRegression.regress(x, yIntercept, true); assertRegressions(n, 4, wls, ols); wls = wlsRegression.regress(x, w1, yNoIntercept, false); ols = olsRegression.regress(x, yNoIntercept, false); assertRegressions(n, 3, wls, ols); wls = wlsRegression.regress(x, w2, yIntercept, true); ols = olsRegression.regress(x, yIntercept, true); assertRegressions(n, 4, wls, ols); wls = wlsRegression.regress(x, w2, yNoIntercept, false); ols = olsRegression.regress(x, yNoIntercept, false); assertRegressions(n, 3, wls, ols); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void test() public virtual void test() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LeastSquaresRegression regression = new OrdinaryLeastSquaresRegression(); LeastSquaresRegression regression = new OrdinaryLeastSquaresRegression(); try { regression.checkData(null, null); Assert.fail(); } //JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#: //ORIGINAL LINE: catch (final IllegalArgumentException e) catch (legalArgumentException) { // Expected } double[][] x = new double[0][]; try { regression.checkData(x, null); Assert.fail(); } //JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#: //ORIGINAL LINE: catch (final IllegalArgumentException e) catch (legalArgumentException) { // Expected } double[] y = new double[0]; try { regression.checkData(x, (double[])null, y); Assert.fail(); } //JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#: //ORIGINAL LINE: catch (final IllegalArgumentException e) catch (legalArgumentException) { // Expected } //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: x = new double[1][2]; x = RectangularArrays.ReturnRectangularDoubleArray(1, 2); y = new double[3]; try { regression.checkData(x, (double[])null, y); Assert.fail(); } //JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#: //ORIGINAL LINE: catch (final IllegalArgumentException e) catch (legalArgumentException) { // Expected } x = new double[][] { new double[] { 1.0, 2.0, 3.0 }, new double[] { 4.0, 5.0 }, new double[] { 6.0, 7.0, 8.0 }, new double[] { 9.0, 0.0, 0.0 } }; try { regression.checkData(x, (double[])null, y); Assert.fail(); } //JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#: //ORIGINAL LINE: catch (final IllegalArgumentException e) catch (legalArgumentException) { // Expected } x[1] = new double[] { 4.0, 5.0, 6.0 }; try { regression.checkData(x, (double[])null, y); Assert.fail(); } //JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#: //ORIGINAL LINE: catch (final IllegalArgumentException e) catch (legalArgumentException) { // Expected } y = new double[] { 1.0, 2.0, 3.0, 4.0 }; double[] w1 = new double[0]; try { regression.checkData(x, w1, y); Assert.fail(); } //JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#: //ORIGINAL LINE: catch (final IllegalArgumentException e) catch (legalArgumentException) { // Expected } double[][] w = new double[0][]; try { regression.checkData(x, w, y); Assert.fail(); } //JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#: //ORIGINAL LINE: catch (final IllegalArgumentException e) catch (legalArgumentException) { // Expected } w1 = new double[3]; try { regression.checkData(x, w1, y); Assert.fail(); } //JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#: //ORIGINAL LINE: catch (final IllegalArgumentException e) catch (legalArgumentException) { // Expected } //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: w = new double[3][0]; w = RectangularArrays.ReturnRectangularDoubleArray(3, 0); try { regression.checkData(x, w, y); Assert.fail(); } //JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#: //ORIGINAL LINE: catch (final IllegalArgumentException e) catch (legalArgumentException) { // Expected } w = new double[][] { new double[] { 1.0, 2.0, 3.0 }, new double[] { 4.0, 5.0 }, new double[] { 6.0, 7.0, 8.0 }, new double[] { 9.0, 0.0, 0.0 } }; try { regression.checkData(x, w, y); Assert.fail(); } //JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#: //ORIGINAL LINE: catch (final IllegalArgumentException e) catch (legalArgumentException) { // Expected } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void test() public virtual void test() { const int n = 100; const double beta0 = 0.3; const double beta1 = 2.5; const double beta2 = -0.3; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.function.DoubleBinaryOperator f1 = (x1, x2) -> beta1 * x1 + beta2 * x2; System.Func <double, double, double> f1 = (x1, x2) => beta1 * x1 + beta2 * x2; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.function.DoubleBinaryOperator f2 = (x1, x2) -> beta0 + beta1 * x1 + beta2 * x2; System.Func <double, double, double> f2 = (x1, x2) => beta0 + beta1 * x1 + beta2 * x2; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[][] x = new double[n][2]; //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: double[][] x = new double[n][2]; double[][] x = RectangularArrays.ReturnRectangularDoubleArray(n, 2); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[] y1 = new double[n]; double[] y1 = new double[n]; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[] y2 = new double[n]; double[] y2 = new double[n]; for (int i = 0; i < n; i++) { x[i][0] = RANDOM.NextDouble(); x[i][1] = RANDOM.NextDouble(); y1[i] = f1(x[i][0], x[i][1]); y2[i] = f2(x[i][0], x[i][1]); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LeastSquaresRegression ols = new OrdinaryLeastSquaresRegression(); LeastSquaresRegression ols = new OrdinaryLeastSquaresRegression(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<String> names = java.util.Arrays.asList("1", "2"); IList <string> names = Arrays.asList("1", "2"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final NamedVariableLeastSquaresRegressionResult result1 = new NamedVariableLeastSquaresRegressionResult(names, ols.regress(x, null, y1, false)); NamedVariableLeastSquaresRegressionResult result1 = new NamedVariableLeastSquaresRegressionResult(names, ols.regress(x, null, y1, false)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final NamedVariableLeastSquaresRegressionResult result2 = new NamedVariableLeastSquaresRegressionResult(names, ols.regress(x, null, y2, true)); NamedVariableLeastSquaresRegressionResult result2 = new NamedVariableLeastSquaresRegressionResult(names, ols.regress(x, null, y2, true)); try { result1.getPredictedValue((IDictionary <string, double>)null); Assert.fail(); } //JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#: //ORIGINAL LINE: catch (final IllegalArgumentException e) catch (legalArgumentException) { // Expected } assertEquals(result1.getPredictedValue(System.Linq.Enumerable.Empty <string, double>()), 0.0, 1e-16); try { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.Map<String, double> map = new java.util.HashMap<>(); IDictionary <string, double> map = new Dictionary <string, double>(); map["1"] = 0.0; result1.getPredictedValue(map); Assert.fail(); } //JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#: //ORIGINAL LINE: catch (final IllegalArgumentException e) catch (legalArgumentException) { // Expected } double x1, x2, x3; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.Map<String, double> var = new java.util.HashMap<>(); IDictionary <string, double> var = new Dictionary <string, double>(); for (int i = 0; i < 10; i++) { x1 = RANDOM.NextDouble(); x2 = RANDOM.NextDouble(); x3 = RANDOM.NextDouble(); var["1"] = x1; var["2"] = x2; assertEquals(result1.getPredictedValue(var), f1(x1, x2), EPS); assertEquals(result2.getPredictedValue(var), f2(x1, x2), EPS); var["3"] = x3; assertEquals(result1.getPredictedValue(var), f1(x1, x2), EPS); assertEquals(result2.getPredictedValue(var), f2(x1, x2), EPS); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void test() public virtual void test() { const double a0 = 2.3; const double a1 = 4.7; const double a2 = -0.99; const double a3 = -5.1; const double a4 = 0.27; const int n = 30; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[][] x = new double[n][4]; //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: double[][] x = new double[n][4]; double[][] x = RectangularArrays.ReturnRectangularDoubleArray(n, 4); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[] yIntercept = new double[n]; double[] yIntercept = new double[n]; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[] yNoIntercept = new double[n]; double[] yNoIntercept = new double[n]; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[][] w = new double[n][n]; //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: double[][] w = new double[n][n]; double[][] w = RectangularArrays.ReturnRectangularDoubleArray(n, n); double y, x1, x2, x3, x4; for (int i = 0; i < n; i++) { x1 = i; x2 = x1 * x1; x3 = Math.Sqrt(x1); x4 = x1 * x2; x[i] = new double[] { x1, x2, x3, x4 }; y = x1 * a1 + x2 * a2 + x3 * a3 + x4 * a4; yNoIntercept[i] = y; yIntercept[i] = y + a0; for (int j = 0; j < n; j++) { w[i][j] = 0.0; } w[i][i] = 1.0; } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final GeneralizedLeastSquaresRegression regression = new GeneralizedLeastSquaresRegression(); GeneralizedLeastSquaresRegression regression = new GeneralizedLeastSquaresRegression(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final OrdinaryLeastSquaresRegression olsRegression = new OrdinaryLeastSquaresRegression(); OrdinaryLeastSquaresRegression olsRegression = new OrdinaryLeastSquaresRegression(); LeastSquaresRegressionResult gls = regression.regress(x, w, yIntercept, true); LeastSquaresRegressionResult ols = olsRegression.regress(x, yIntercept, true); assertRegressions(n, 5, gls, ols); gls = regression.regress(x, w, yNoIntercept, false); ols = olsRegression.regress(x, yNoIntercept, false); assertRegressions(n, 4, gls, ols); gls = regression.regress(x, w, yIntercept, true); ols = olsRegression.regress(x, yIntercept, true); assertRegressions(n, 5, gls, ols); gls = regression.regress(x, w, yNoIntercept, false); ols = olsRegression.regress(x, yNoIntercept, false); assertRegressions(n, 4, gls, ols); }