Exemple #1
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (this.GetType() != obj.GetType())
            {
                return(false);
            }
            LeastSquareResults other = (LeastSquareResults)obj;

            if (System.BitConverter.DoubleToInt64Bits(_chiSq) != Double.doubleToLongBits(other._chiSq))
            {
                return(false);
            }
            if (!Objects.Equals(_covariance, other._covariance))
            {
                return(false);
            }
            if (!Objects.Equals(_inverseJacobian, other._inverseJacobian))
            {
                return(false);
            }
            return(Objects.Equals(_parameters, other._parameters));
        }
        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]);
                }
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testEquals()
        public virtual void testEquals()
        {
            LeastSquareResults ls1 = new LeastSquareResults(1.0, PARAMS, COVAR);
            LeastSquareResults ls2 = new LeastSquareResults(1.0, DoubleArray.of(1.0, 2.0), DoubleMatrix.copyOf(new double[][]
            {
                new double[] { 0.1, 0.2 },
                new double[] { 0.2, 0.3 }
            }));

            assertEquals(ls1, ls2);
            ls2 = new LeastSquareResults(1.0, PARAMS, COVAR, null);
            assertEquals(ls1, ls2);
            ls2 = new LeastSquareResults(1.1, PARAMS, COVAR);
            assertFalse(ls1.Equals(ls2));
            ls2 = new LeastSquareResults(1.0, DoubleArray.of(1.1, 2.0), DoubleMatrix.copyOf(new double[][]
            {
                new double[] { 0.1, 0.2 },
                new double[] { 0.2, 0.3 }
            }));
            assertFalse(ls1.Equals(ls2));
            ls2 = new LeastSquareResults(1.0, DoubleArray.of(1.0, 2.0), DoubleMatrix.copyOf(new double[][]
            {
                new double[] { 0.1, 0.2 },
                new double[] { 0.2, 0.4 }
            }));
            assertFalse(ls1.Equals(ls2));
            ls2 = new LeastSquareResults(1.0, PARAMS, COVAR, INV_JAC);
            assertFalse(ls1.Equals(ls2));
            ls1 = new LeastSquareResults(1, PARAMS, COVAR, INV_JAC);
            ls2 = new LeastSquareResults(1, PARAMS, COVAR, COVAR);
            assertFalse(ls1.Equals(ls2));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testHashCode()
        public virtual void testHashCode()
        {
            LeastSquareResults ls1 = new LeastSquareResults(1.0, PARAMS, COVAR);
            LeastSquareResults ls2 = new LeastSquareResults(1.0, DoubleArray.of(1.0, 2.0), DoubleMatrix.copyOf(new double[][]
            {
                new double[] { 0.1, 0.2 },
                new double[] { 0.2, 0.3 }
            }));

            assertEquals(ls1.GetHashCode(), ls2.GetHashCode(), 0);
            ls2 = new LeastSquareResults(1.0, DoubleArray.of(1.0, 2.0), DoubleMatrix.copyOf(new double[][]
            {
                new double[] { 0.1, 0.2 },
                new double[] { 0.2, 0.3 }
            }), null);
            assertEquals(ls1.GetHashCode(), ls2.GetHashCode(), 0);
            ls1 = new LeastSquareResults(1.0, PARAMS, COVAR, INV_JAC);
            ls2 = new LeastSquareResults(1.0, DoubleArray.of(1.0, 2.0), DoubleMatrix.copyOf(new double[][]
            {
                new double[] { 0.1, 0.2 },
                new double[] { 0.2, 0.3 }
            }), DoubleMatrix.copyOf(new double[][]
            {
                new double[] { 0.5, 0.6 },
                new double[] { 0.7, 0.8 }
            }));
            assertEquals(ls1.GetHashCode(), ls2.GetHashCode(), 0);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testRecall()
        public virtual void testRecall()
        {
            const double       chiSq = 12.46;
            LeastSquareResults res   = new LeastSquareResults(chiSq, PARAMS, COVAR);

            assertEquals(chiSq, res.ChiSq, 0.0);
            for (int i = 0; i < 2; i++)
            {
                assertEquals(PARAMS.get(i), res.FitParameters.get(i), 0);
                for (int j = 0; j < 2; j++)
                {
                    assertEquals(COVAR.get(i, j), res.Covariance.get(i, j), 0);
                }
            }
            res = new LeastSquareResults(chiSq, PARAMS, COVAR, INV_JAC);
            assertEquals(chiSq, res.ChiSq, 0.0);
            for (int i = 0; i < 2; i++)
            {
                assertEquals(PARAMS.get(i), res.FitParameters.get(i), 0);
                for (int j = 0; j < 2; j++)
                {
                    assertEquals(COVAR.get(i, j), res.Covariance.get(i, j), 0);
                    assertEquals(INV_JAC.get(i, j), res.FittingParameterSensitivityToData.get(i, j), 0);
                }
            }
        }
        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");
                }
            }
        }
        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);
        }
Exemple #9
0
 public LeastSquareResults(LeastSquareResults from) : this(from._chiSq, from._parameters, from._covariance, from._inverseJacobian)
 {
 }
 public LeastSquareResultsWithTransform(LeastSquareResults transformedFitResult, NonLinearParameterTransforms transform) : base(transformedFitResult)
 {
     ArgChecker.notNull(transform, "null transform");
     _transform       = transform;
     _modelParameters = transform.inverseTransform(FitParameters);
 }
 public LeastSquareResultsWithTransform(LeastSquareResults transformedFitResult) : base(transformedFitResult)
 {
     _transform                   = null;
     _modelParameters             = transformedFitResult.FitParameters;
     _inverseJacobianModelPararms = FittingParameterSensitivityToData;
 }