コード例 #1
0
 protected override void Evaluate()
 {
     // here we could directly overwrite the existing matrix cells instead.
     // note: values must then be initialized manually first, if null.
     Value    = RosenbrockFunction.Value(Point);
     Gradient = RosenbrockFunction.Gradient(Point);
     Hessian  = RosenbrockFunction.Hessian(Point);
 }
コード例 #2
0
        public void FindMinimum_Rosenbrock_Hard()
        {
            var obj    = ObjectiveFunction.GradientHessian(point => Tuple.Create(RosenbrockFunction.Value(point), RosenbrockFunction.Gradient(point), RosenbrockFunction.Hessian(point)));
            var solver = new NewtonMinimizer(1e-5, 1000);
            var result = solver.FindMinimum(obj, new DenseVector(new[] { -1.2, 1.0 }));

            Assert.That(Math.Abs(result.MinimizingPoint[0] - 1.0), Is.LessThan(1e-3));
            Assert.That(Math.Abs(result.MinimizingPoint[1] - 1.0), Is.LessThan(1e-3));
        }
コード例 #3
0
        public virtual ActionResult RosenbrockFunctionPlot(PlotViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(HttpNotFound());
            }

            var f = new RosenbrockFunction();

            return(plot(f, model));
        }
コード例 #4
0
        public void TestRosenbrockFunction()
        {
            var minimizer = new QNMinimizer();
            var f         = new RosenbrockFunction();
            var x         = minimizer.Minimize(f);
            var minValue  = f.ValueAt(x);

            Assert.AreEqual(x[0], 1.0, 1e-5);
            Assert.AreEqual(x[1], 1.0, 1e-5);
            Assert.AreEqual(minValue, 0, 1e-10);
        }
コード例 #5
0
        public void TestGradient()
        {
            var input = new DenseVector(new[] { -0.9, -0.5 });

            var v1 = RosenbrockFunction.Value(input);
            var g  = RosenbrockFunction.Gradient(input);

            var eps  = 1e-5;
            var eps0 = (new DenseVector(new[] { 1.0, 0.0 })) * eps;
            var eps1 = (new DenseVector(new[] { 0.0, 1.0 })) * eps;

            var g0 = (RosenbrockFunction.Value(input + eps0) - RosenbrockFunction.Value(input - eps0)) / (2 * eps);
            var g1 = (RosenbrockFunction.Value(input + eps1) - RosenbrockFunction.Value(input - eps1)) / (2 * eps);

            Assert.That(Math.Abs(g0 - g[0]) < 1e-3);
            Assert.That(Math.Abs(g1 - g[1]) < 1e-3);
        }
コード例 #6
0
        public void TestHessian()
        {
            var input = new DenseVector(new[] { -0.9, -0.5 });

            var v1 = RosenbrockFunction.Value(input);
            var h  = RosenbrockFunction.Hessian(input);

            var eps = 1e-5;

            var eps0 = (new DenseVector(new[] { 1.0, 0.0 })) * eps;
            var eps1 = (new DenseVector(new[] { 0.0, 1.0 })) * eps;

            var epsuu = (new DenseVector(new[] { 1.0, 1.0 })) * eps;
            var epsud = (new DenseVector(new[] { 1.0, -1.0 })) * eps;

            var h00 = (RosenbrockFunction.Value(input + eps0) - 2 * RosenbrockFunction.Value(input) + RosenbrockFunction.Value(input - eps0)) / (eps * eps);
            var h11 = (RosenbrockFunction.Value(input + eps1) - 2 * RosenbrockFunction.Value(input) + RosenbrockFunction.Value(input - eps1)) / (eps * eps);
            var h01 = (RosenbrockFunction.Value(input + epsuu) - RosenbrockFunction.Value(input + epsud) - RosenbrockFunction.Value(input - epsud) + RosenbrockFunction.Value(input - epsuu)) / (4 * eps * eps);

            Assert.That(Math.Abs(h00 - h[0, 0]) < 1e-3);
            Assert.That(Math.Abs(h11 - h[1, 1]) < 1e-3);
            Assert.That(Math.Abs(h01 - h[0, 1]) < 1e-3);
            Assert.That(Math.Abs(h01 - h[1, 0]) < 1e-3);
        }
コード例 #7
0
 protected override void EvaluateHessian()
 {
     Hessian = RosenbrockFunction.Hessian(Point);
 }
コード例 #8
0
 protected override void EvaluateGradient()
 {
     Gradient = RosenbrockFunction.Gradient(Point);
 }
コード例 #9
0
 protected override void EvaluateValue()
 {
     Value = RosenbrockFunction.Value(Point);
 }
コード例 #10
0
ファイル: BfgsTest.cs プロジェクト: jkalias/mathnet-numerics
        private static void CheckRosenbrock(double a, double b, double expectedMin)
        {
            var x = BfgsSolver.Solve(new DenseVector(new[] { a, b }), RosenbrockFunction.Value, RosenbrockFunction.Gradient);

            Numerics.Precision.AlmostEqual(expectedMin, RosenbrockFunction.Value(x), Precision);
        }