/// <summary> /// Inheritors of this class should specify how to get actual values for the parameters /// given a index vector in the grid-search space. Those indices indicate which values /// should be given, e.g. if there are two parameters in the problem, the ranges of the /// first parameter are {10, 20, 30}, and the ranges of the second parameter are {0.1, 0.01, 0.001 }, /// if the index vector is { 1, 2 } this method should return { 20, 0.001 }. /// </summary> /// /// <param name="indices">The indices in grid-search space.</param> /// /// <returns>The parameters at the location indicated by <paramref name="indices"/>.</returns> /// protected override TRange GetParameters(int[] indices) { var ranges = new List <IGridSearchRange>(); foreach (PropertyInfo property in ParameterRanges.GetType().GetProperties()) { var p = (IGridSearchRange)property.GetValue(ParameterRanges); ranges.Add((IGridSearchRange)p.Clone()); } for (int j = 0; j < indices.Length; j++) { ranges[j].Index = indices[j]; } return((TRange)Activator.CreateInstance(ParameterRanges.GetType(), ranges.ToArray())); }
/// <summary> /// Inheritors of this class should return the number of possible parameter values for /// each parameter in the grid-search range. For example, if a problem should search /// parameters in the range {0, 1, ... 9} (10 values) and {-1, -2, -3 } (3 values), this /// method should return { 10, 3 }. /// </summary> /// /// <returns>The number of possibilities for each parameter.</returns> /// protected override int[] GetLengths() { List <int> lengths = new List <int>(); foreach (PropertyInfo property in ParameterRanges.GetType().GetProperties()) { Type expected = typeof(GridSearchRange <object>).GetGenericTypeDefinition(); Type actual = property.PropertyType.GetGenericTypeDefinition(); if (actual != expected) { throw new Exception(); } var p = (IGridSearchRange)property.GetValue(ParameterRanges); lengths.Add(p.Length); } return(lengths.ToArray()); }