Browse Source

Optimization: move BFGS over to Optimization namespace

unified_optimization
Christoph Ruegg 12 years ago
parent
commit
7b59dc3d35
  1. 9
      src/Numerics/Numerics.csproj
  2. 14
      src/Numerics/Optimization/BfgsSolver.cs
  3. 6
      src/Numerics/Optimization/LineSearch/WolfeRule.cs
  4. 17
      src/UnitTests/OptimizationTests/BfgsTest.cs
  5. 2
      src/UnitTests/UnitTests.csproj

9
src/Numerics/Numerics.csproj

@ -112,9 +112,8 @@
<Compile Include="Optimization\ObjectiveFunctions\GradientObjectiveFunction.cs" /> <Compile Include="Optimization\ObjectiveFunctions\GradientObjectiveFunction.cs" />
<Compile Include="Optimization\ObjectiveFunctions\GradientHessianObjectiveFunction.cs" /> <Compile Include="Optimization\ObjectiveFunctions\GradientHessianObjectiveFunction.cs" />
<Compile Include="Optimization\IObjectiveFunction.cs" /> <Compile Include="Optimization\IObjectiveFunction.cs" />
<Compile Include="Optimization\Implementation\LineSearchResult.cs" /> <Compile Include="Optimization\LineSearch\LineSearchResult.cs" />
<Compile Include="Optimization\Implementation\CheckedObjectiveFunction.cs" /> <Compile Include="Optimization\LineSearch\WeakWolfeLineSearch.cs" />
<Compile Include="Optimization\Implementation\WeakWolfeLineSearch.cs" />
<Compile Include="Optimization\IUnconstrainedMinimizer.cs" /> <Compile Include="Optimization\IUnconstrainedMinimizer.cs" />
<Compile Include="Optimization\MinimizationResult.cs" /> <Compile Include="Optimization\MinimizationResult.cs" />
<Compile Include="Optimization\MinimizationWithLineSearchResult.cs" /> <Compile Include="Optimization\MinimizationWithLineSearchResult.cs" />
@ -223,12 +222,12 @@
<Compile Include="Providers\NativeProviderLoader.cs" /> <Compile Include="Providers\NativeProviderLoader.cs" />
<Compile Include="Random\SystemRandomSource.cs" /> <Compile Include="Random\SystemRandomSource.cs" />
<Compile Include="Random\RandomSeed.cs" /> <Compile Include="Random\RandomSeed.cs" />
<Compile Include="RootFinding\BfgsSolver.cs" /> <Compile Include="Optimization\BfgsSolver.cs" />
<Compile Include="RootFinding\Broyden.cs" /> <Compile Include="RootFinding\Broyden.cs" />
<Compile Include="RootFinding\Cubic.cs" /> <Compile Include="RootFinding\Cubic.cs" />
<Compile Include="RootFinding\NewtonRaphson.cs" /> <Compile Include="RootFinding\NewtonRaphson.cs" />
<Compile Include="RootFinding\RobustNewtonRaphson.cs" /> <Compile Include="RootFinding\RobustNewtonRaphson.cs" />
<Compile Include="RootFinding\WolfeRule.cs" /> <Compile Include="Optimization\LineSearch\WolfeRule.cs" />
<Compile Include="RootFinding\ZeroCrossingBracketing.cs" /> <Compile Include="RootFinding\ZeroCrossingBracketing.cs" />
<Compile Include="RootFinding\Brent.cs" /> <Compile Include="RootFinding\Brent.cs" />
<Compile Include="FindRoots.cs" /> <Compile Include="FindRoots.cs" />

14
src/Numerics/RootFinding/BfgsSolver.cs → src/Numerics/Optimization/BfgsSolver.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// //
// Copyright (c) 2009-2013 Math.NET // Copyright (c) 2009-2015 Math.NET
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -30,13 +30,11 @@
using System; using System;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.LinearAlgebra.Double;
using System.Linq; using MathNet.Numerics.Optimization.LineSearch;
using System.Text;
namespace MathNet.Numerics.RootFinding namespace MathNet.Numerics.Optimization
{ {
/// <summary> /// <summary>
/// Broyden-Fletcher-Goldfarb-Shanno solver for finding function minima /// Broyden-Fletcher-Goldfarb-Shanno solver for finding function minima
@ -45,8 +43,8 @@ namespace MathNet.Numerics.RootFinding
/// </summary> /// </summary>
public static class BfgsSolver public static class BfgsSolver
{ {
private const double gradientTolerance = 1e-5; private const double GradientTolerance = 1e-5;
private const int maxIterations = 100000; private const int MaxIterations = 100000;
/// <summary> /// <summary>
/// Finds a minimum of a function by the BFGS quasi-Newton method /// Finds a minimum of a function by the BFGS quasi-Newton method
@ -100,7 +98,7 @@ namespace MathNet.Numerics.RootFinding
x_old = x; x_old = x;
iter++; iter++;
} }
while ((grad.InfinityNorm() > gradientTolerance) && (iter < maxIterations)); while ((grad.InfinityNorm() > GradientTolerance) && (iter < MaxIterations));
return x; return x;
} }

6
src/Numerics/RootFinding/WolfeRule.cs → src/Numerics/Optimization/LineSearch/WolfeRule.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// //
// Copyright (c) 2009-2013 Math.NET // Copyright (c) 2009-2015 Math.NET
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -29,11 +29,9 @@
// </copyright> // </copyright>
using System; using System;
using System.Collections.Generic;
using System.Linq;
using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra;
namespace MathNet.Numerics.RootFinding namespace MathNet.Numerics.Optimization.LineSearch
{ {
/// <summary> /// <summary>
/// Performs an inexact line search. This is used as a part of quasi-Newton optimization methods to figure /// Performs an inexact line search. This is used as a part of quasi-Newton optimization methods to figure

17
src/UnitTests/RootFindingTests/BfgsTest.cs → src/UnitTests/OptimizationTests/BfgsTest.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// //
// Copyright (c) 2009-2013 Math.NET // Copyright (c) 2009-2015 Math.NET
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -28,22 +28,17 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra;
using NUnit.Framework;
using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.RootFinding; using MathNet.Numerics.Optimization;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.RootFindingTests namespace MathNet.Numerics.UnitTests.OptimizationTests
{ {
[TestFixture, Category("RootFinding")] [TestFixture, Category("RootFinding")]
internal class BfgsTest internal class BfgsTest
{ {
private const double precision = 1e-4; private const double Precision = 1e-4;
[Test] [Test]
public void MinimizeRosenbrock() public void MinimizeRosenbrock()
@ -56,7 +51,7 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests
private static void CheckRosenbrock(double a, double b, double expectedMin) private static void CheckRosenbrock(double a, double b, double expectedMin)
{ {
var x = BfgsSolver.Solve(new DenseVector(new[] { a, b }), Rosenbrock, RosenbrockGradient); var x = BfgsSolver.Solve(new DenseVector(new[] { a, b }), Rosenbrock, RosenbrockGradient);
Precision.AlmostEqual(expectedMin, Rosenbrock(x), precision); Numerics.Precision.AlmostEqual(expectedMin, Rosenbrock(x), Precision);
} }
private static double Rosenbrock(Vector<double> x) private static double Rosenbrock(Vector<double> x)

2
src/UnitTests/UnitTests.csproj

@ -348,7 +348,7 @@
<Compile Include="OptimizationTests\RosenbrockFunction.cs" /> <Compile Include="OptimizationTests\RosenbrockFunction.cs" />
<Compile Include="OptimizationTests\TestNewtonMinimizer.cs" /> <Compile Include="OptimizationTests\TestNewtonMinimizer.cs" />
<Compile Include="Random\SystemRandomSourceTests.cs" /> <Compile Include="Random\SystemRandomSourceTests.cs" />
<Compile Include="RootFindingTests\BfgsTest.cs" /> <Compile Include="OptimizationTests\BfgsTest.cs" />
<Compile Include="RootFindingTests\BisectionTest.cs" /> <Compile Include="RootFindingTests\BisectionTest.cs" />
<Compile Include="PermutationTest.cs" /> <Compile Include="PermutationTest.cs" />
<Compile Include="PrecisionTest.cs" /> <Compile Include="PrecisionTest.cs" />

Loading…
Cancel
Save