Grid Search |
This topic contains the following sections:
This algorithm performs the consistent search over the all possible factor combinations for the objective function minimization.
The algorithm supports simple (one search point at once) and block-oriented (multiple search point points at once) objective function estimation. Compared with simple search the block oriented call allows user to perform multiple search point optimization in parallel or use shared information for calculation speedup.
Next most important methods and properties are featured in the class:
1using System; 2using System.Collections.Generic; 3using System.Text; 4using System.Threading.Tasks; 5using FinMath.MachineLearning.EvolutionaryAlgorithms; 6using FinMath.Statistics; 7 8namespace FinMath.Samples 9{ 10 internal class GridSearchSample 11 { 12 static readonly SearchAlgorithm.ICountableFactor[] Factors = 13 { 14 new SearchAlgorithm.DiscreteFactor("DiscreteFactor1", Math.PI, -Math.Exp(1.0), false, 5), 15 new SearchAlgorithm.DiscreteFactor("DiscreteFactor1", 2.7, 3.1, false, 0.1), 16 new SearchAlgorithm.CategoricalFactor("CategoricalFactor1", new double[] {3, 2, -1}), 17 new SearchAlgorithm.CategoricalFactor("CategoricalFactor2", new double[] {-1, 1, 45}), 18 }; 19 20 public static void SimpleProcessing() 21 { 22 var searchAlgo = new GridSearch(Factors, 23 factorsPoint => factorsPoint.SumMagnitudes()); 24 25 searchAlgo.Run(); 26 27 Console.WriteLine($"GridSearchSample.SimpleProcessing: Best objective: {searchAlgo.MinimumObjectiveValue} at [{String.Join(", ", searchAlgo.MinimumObjectivePoint)}]"); 28 } 29 30 public static void BlockProcessing() 31 { 32 var searchAlgo = new GridSearch(Factors, 10, 33 (factorPoints, objectives) => Parallel.For(0, factorPoints.Length, 34 i => objectives[i] = factorPoints[i].SumMagnitudes())); 35 36 searchAlgo.Run(); 37 38 Console.WriteLine($"GridSearchSample.BlockProcessing: Best objective: {searchAlgo.MinimumObjectiveValue} at [{String.Join(", ", searchAlgo.MinimumObjectivePoint)}]"); 39 } 40 } 41}