public override void GenerateCandidates(ref List <ICandidate> candidates, int numSamples = -1) { if (numSamples == -1) { numSamples = (int)MaxVariableSizes.Min(); } for (var i = 0; i < numSamples; i++) { candidates.Add(new Candidate(double.NaN, makeOneRandomCandidate())); } }
public override List <double[]> GenerateCandidates(double[] candidate, int numSamples = -1) { var candidates = new List <double[]>(); if (numSamples == -1) { numSamples = (int)MaxVariableSizes.Min(); } for (var i = 0; i < numSamples; i++) { candidates.Add(makeOneRandomCandidate()); } return(candidates); }
/// <summary> /// Generates the candidates. /// </summary> /// <param name="candidate">The candidate.</param> /// <param name="numSamples">The number samples.</param> /// <returns>List<System.Double[]>.</returns> /// <exception cref="Exception">The bounds on the " + j + "(th) variable must not be at infinity for" + /// "performing Latin Hypercube sampling.</exception> public override List <double[]> GenerateCandidates(double[] candidate, int numSamples = -1) { if (numSamples == -1) { numSamples = (int)MaxVariableSizes.Min(); } var rnd = new Random(); var data = new List <double> [n]; // the following is not correct - need to fix // also what about the non-discrete variables and LHC? for (var j = 0; j < n; j++) { var varVals = new List <double>(); if (discreteSpaceDescriptor.DiscreteVarIndices.Contains(j) && generateFor != VariablesInScope.OnlyReal) { varVals = new List <double>(); for (var i = 0; i < numSamples; i++) { var effectiveIndex = (int)(((double)i * discreteSpaceDescriptor[j].Size) / numSamples); varVals.Add(discreteSpaceDescriptor[j][effectiveIndex]); } } else if (!discreteSpaceDescriptor.DiscreteVarIndices.Contains(j) && generateFor != VariablesInScope.OnlyDiscrete) { var delta = (discreteSpaceDescriptor[j].UpperBound - discreteSpaceDescriptor[j].LowerBound); if (double.IsInfinity(delta)) { throw new Exception("The bounds on the " + j + "(th) variable must not be at infinity for" + "performing Latin Hypercube sampling."); } delta /= numSamples; var lb = discreteSpaceDescriptor[j].LowerBound; varVals = new List <double>(); for (var i = 0; i < numSamples; i++) { varVals.Add(lb + i * delta); } } else { for (var i = 0; i < numSamples; i++) { varVals.Add(double.NaN); } } varVals = varVals.OrderBy(a => rnd.NextDouble()).ToList(); data[j] = varVals; } var candidates = new List <double[]>(numSamples); for (var i = 0; i < numSamples; i++) { var point = new double[n]; for (var j = 0; j < n; j++) { point[j] = data[j][i]; } candidates.Add(point); } return(candidates); }