public void Multimodal_Sin() { var f = new SinTestFunction().FunctionValueAnalysisFor1D(); var a = f.ValueWithDerivative(1.4 * Math.PI); var b = f.ValueWithDerivative(4.4 * Math.PI); a.Y.AssertIsLessThan(b.Y); a.First.AssertIsLessThan(0); b.First.AssertIsGreaterThan(0); var point = new NumberFunctionOptimizationSearchRange(a: a, b: b); point.BorderSmaller.X.AssertIsEqualTo(a.X); point.BorderSmaller.Y.AssertIsEqualTo(a.Y); point.IsEmptyRange.AssertIsFalse(); try { _method.MoveNext(in f, ref point); throw new Exception("I should never get here"); } catch (MultimodalFunctionException) { // all is fine } }
public void Multimodal_Sin() { var f = new SinTestFunction().FunctionValueAnalysisFor1D(); var a = f.ValueWithDerivative(1.4 * Math.PI); Number b = 4.4 * Math.PI; ushort i = _method.FindOptimal(in f, a, b, out NumberFunctionPointWithDerivative solution); solution.Y.AssertIsEqualTo(2); i.AssertIsEqualTo(22); }
public void Unimodal_Sin_CornerIncreasing() { var f = new SinTestFunction().FunctionValueAnalysisFor1D(); var a = f.ValueWithDerivative(0); Number b = 0.7 * Math.PI; ushort i = _method.FindOptimal(in f, a, b, out NumberFunctionPointWithDerivative solution); solution.Y.AssertIsEqualTo(3); i.AssertIsEqualTo(23); }
public void Unimodal_Sin_Optimum() { var f = new SinTestFunction().FunctionValueAnalysisFor1D(); var a = f.ValueWithDerivative(-1.3 * Math.PI); var b = f.ValueWithDerivative(0.4 * Math.PI); ushort iterationCount = _optimizer.FindOptimal(f, ref a, b.X); a.X.AssertIsEqualTo(-0.5 * Math.PI); iterationCount.AssertIsEqualTo(17); }
public void Multimodal_Sin() { var f = new SinTestFunction().FunctionValueAnalysisFor1D(); var a = f.ValueWithDerivative(-1.1 * Math.PI); var b = f.ValueWithDerivative(2 * Math.PI); a.First.AssertIsLessThan(0); b.First.AssertIsGreaterThan(0); ushort iterationCount = _optimizer.FindOptimal(f, ref a, b.X); Assert.Equal(-0.5 * Math.PI, (double)a.X, 8); iterationCount.AssertIsEqualTo(18); }
public void Unimodal_Sin_Optimum() { var f = new SinTestFunction().FunctionValueAnalysisFor1D(); var a = f.ValueWithDerivative(-1.3 * Math.PI); var b = f.ValueWithDerivative(0.4 * Math.PI); var point = new NumberFunctionOptimizationSearchRange(a: a, b: b); point.BorderSmaller.X.AssertIsEqualTo(a.X); point.BorderSmaller.Y.AssertIsEqualTo(a.Y); ushort i = _method.FindOptimal(in f, ref point); point.BorderSmaller.Y.AssertIsEqualTo(2); i.AssertIsEqualTo(6); }
public void Unimodal_Sin_CornerIncreasing() { var f = new SinTestFunction().FunctionValueAnalysisFor1D(); var a = f.ValueWithDerivative(0); var b = f.ValueWithDerivative(0.7 * Math.PI); var point = new NumberFunctionOptimizationSearchRange(a: a, b: b); point.BorderSmaller.X.AssertIsEqualTo(a.X); point.BorderSmaller.Y.AssertIsEqualTo(a.Y); b.Y.AssertIsGreaterThan(a.Y); ushort i = _method.FindOptimal(in f, ref point); point.BorderSmaller.Y.AssertIsEqualTo(3); i.AssertIsEqualTo(23); }
public void Multimodal_Sin() { var f = new SinTestFunction().FunctionValueAnalysisFor1D(); var a = f.ValueWithDerivative(1.4 * Math.PI); var b = f.ValueWithDerivative(4.4 * Math.PI); a.Y.AssertIsLessThan(b.Y); a.First.AssertIsLessThan(0); b.First.AssertIsGreaterThan(0); var point = new NumberFunctionOptimizationSearchRange(a: a, b: b); point.BorderSmaller.X.AssertIsEqualTo(a.X); point.BorderSmaller.Y.AssertIsEqualTo(a.Y); ushort i = _method.FindOptimal(in f, ref point); point.BorderSmaller.Y.AssertIsEqualTo(2); i.AssertIsEqualTo(6); }