|
|
|
@ -31,6 +31,7 @@ |
|
|
|
using System; |
|
|
|
using NUnit.Framework; |
|
|
|
using MathNet.Numerics.Optimization; |
|
|
|
using System.Threading; |
|
|
|
|
|
|
|
namespace MathNet.Numerics.UnitTests.OptimizationTests |
|
|
|
{ |
|
|
|
@ -46,6 +47,7 @@ namespace MathNet.Numerics.UnitTests.OptimizationTests |
|
|
|
|
|
|
|
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)); |
|
|
|
Thread.Sleep(10*1000); |
|
|
|
} |
|
|
|
|
|
|
|
[Test] |
|
|
|
@ -69,5 +71,38 @@ namespace MathNet.Numerics.UnitTests.OptimizationTests |
|
|
|
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)); |
|
|
|
} |
|
|
|
|
|
|
|
[Test] |
|
|
|
public void FindMinimum_BigRosenbrock_Easy() |
|
|
|
{ |
|
|
|
var obj = new SimpleObjectiveFunction(BigRosenbrockFunction.Value, BigRosenbrockFunction.Gradient); |
|
|
|
var solver = new BfgsMinimizer(1e-10, 1e-5, 1000); |
|
|
|
var result = solver.FindMinimum(obj, new LinearAlgebra.Double.DenseVector(new[] { 1.2*100.0, 1.2*100.0 })); |
|
|
|
|
|
|
|
Assert.That(Math.Abs(result.MinimizingPoint[0] - 100.0), Is.LessThan(1e-3)); |
|
|
|
Assert.That(Math.Abs(result.MinimizingPoint[1] - 100.0), Is.LessThan(1e-3)); |
|
|
|
} |
|
|
|
|
|
|
|
[Test] |
|
|
|
public void FindMinimum_BigRosenbrock_Hard() |
|
|
|
{ |
|
|
|
var obj = new SimpleObjectiveFunction(RosenbrockFunction.Value, RosenbrockFunction.Gradient); |
|
|
|
var solver = new BfgsMinimizer(1e-5, 1e-5, 1000); |
|
|
|
var result = solver.FindMinimum(obj, new LinearAlgebra.Double.DenseVector(new[] { -1.2*100.0, 1.0*100.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)); |
|
|
|
} |
|
|
|
|
|
|
|
[Test] |
|
|
|
public void FindMinimum_BigRosenbrock_Overton() |
|
|
|
{ |
|
|
|
var obj = new SimpleObjectiveFunction(BigRosenbrockFunction.Value, BigRosenbrockFunction.Gradient); |
|
|
|
var solver = new BfgsMinimizer(1e-5, 1e-5, 1000); |
|
|
|
var result = solver.FindMinimum(obj, new LinearAlgebra.Double.DenseVector(new[] { -0.9*100.0, -0.5*100.0 })); |
|
|
|
|
|
|
|
Assert.That(Math.Abs(result.MinimizingPoint[0] - 100.0), Is.LessThan(1e-3)); |
|
|
|
Assert.That(Math.Abs(result.MinimizingPoint[1] - 100.0), Is.LessThan(1e-3)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|