From febf07b584e17ab7fb4e10db45855276c973b4b3 Mon Sep 17 00:00:00 2001 From: Erik Ovegard Date: Wed, 8 Jun 2016 21:40:28 +0200 Subject: [PATCH] Removed NelderMeadSimplexTests.FindParableConstantsThatMinimizesErrors() since it only passed due to new SystemRandom() being called in close succession which leads to identical seeds. --- .../NelderMeadSimplexTests.cs | 44 ++----------------- 1 file changed, 3 insertions(+), 41 deletions(-) diff --git a/src/UnitTests/OptimizationTests/NelderMeadSimplexTests.cs b/src/UnitTests/OptimizationTests/NelderMeadSimplexTests.cs index aed9409c..64ba24db 100644 --- a/src/UnitTests/OptimizationTests/NelderMeadSimplexTests.cs +++ b/src/UnitTests/OptimizationTests/NelderMeadSimplexTests.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2015 Math.NET +// Copyright (c) 2009-2016 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -28,54 +28,16 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using MathNet.Numerics.LinearAlgebra.Double; +using MathNet.Numerics.Optimization; using NUnit.Framework; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using MathNet.Numerics.Optimization; -using MathNet.Numerics.LinearAlgebra.Double; namespace MathNet.Numerics.UnitTests.OptimizationTests { [TestFixture] public class NelderMeadSimplexTests { - /// - /// Test that finds the constants of a parable, function adds noise and return the mean square error - /// Copied from the test in https://code.google.com/p/nelder-mead-simplex/ - /// - [Test] - public void FindParableConstantsThatMinimizesErrors() - { - var nms = new NelderMeadSimplex(1e-6, 1000); - double a = 5; - double b = 10; - System.Random r = new System.Random(2); - IObjectiveFunction objFun = ObjectiveFunction.Value((constants)=> - { - double ssq = 0; - for (double x = -10; x < 10; x += .1) - { - double yTrue = a * x * x + b * x + r.NextDouble(); - double yRegress = constants[0] * x * x + constants[1] * x; - ssq += Math.Pow((yTrue - yRegress), 2); - } - return ssq; - }); - var initialGuess = new DenseVector(2); - initialGuess[0] = 3; - initialGuess[1] = 5; - var result = nms.FindMinimum(objFun, initialGuess); - - Assert.NotNull(result); - Assert.NotNull(result.MinimizingPoint); - Assert.NotNull(result.FunctionInfoAtMinimum); - Assert.That(Math.Abs(result.MinimizingPoint[0] - a), Is.LessThan(1e-2)); - Assert.That(Math.Abs(result.MinimizingPoint[1] - b), Is.LessThan(1e-2)); - } - [Test] public void NMS_FindMinimum_Rosenbrock_Easy() {