Пример #1
0
        public void FindRoot_QuadraticIncorrectIntialGuess_ReturnsRootWithinTolerance()
        {
            OneDimensionalFunction f = x => x * x - 4;

            double lowerBound = -1;
            double upperBound = 3;
            BisectionSolver solver = new BisectionSolver(f, lowerBound, upperBound);

            var root = solver.FindRoot();

            Assert.IsTrue(Math.Abs(f(root)) < solver.Tolerance);
        }
Пример #2
0
        public void FindRoot_SinFunction_ReturnsRootWithinTolerance()
        {
            OneDimensionalFunction f = Math.Sin;

            double lowerBound = -3*Math.PI / 4;
            double upperBound = Math.PI/2;
            BisectionSolver solver = new BisectionSolver(f, lowerBound, upperBound);

            var root = solver.FindRoot();

            Assert.IsTrue(Math.Abs(f(root)) < solver.Tolerance);
        }
Пример #3
0
        public void FindRoot_PolynomialLowerBoundIsZero_ReturnsExactRoot()
        {
            OneDimensionalFunction f = x => x * x - 4;

            double lowerBound = -2;
            double upperBound = 3;
            BisectionSolver solver = new BisectionSolver(f, lowerBound, upperBound);

            var root = solver.FindRoot();

            Assert.AreEqual(lowerBound, root);
        }
Пример #4
0
        public double GetMle(List<int> responseVector)
        {
            LogLikelihoodFunction logLikelihoodFunction = new LogLikelihoodFunction(_modelParametersList);

            const double initialGuess = 0;
            OneDimensionalFunction firstDerivativeFunction = x => logLikelihoodFunction.LogLikelihoodFirstDerivative(responseVector, x);
            OneDimensionalFunction secondDerivativeFunction = x => logLikelihoodFunction.LogLikelihoodSecondDerivative(responseVector, x);
            //NewtonRhapsonSolver rootSolver = new NewtonRhapsonSolver(firstDerivativeFunction, secondDerivativeFunction, initialGuess);
            BisectionSolver rootSolver = new BisectionSolver(firstDerivativeFunction, -5, 5);

            double mle = rootSolver.FindRoot();

            return mle;
        }