[14833] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[17332] | 22 | using HEAL.Attic;
|
---|
[14833] | 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
[15343] | 25 | using HeuristicLab.Optimization;
|
---|
[14833] | 26 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
| 27 |
|
---|
| 28 | // ReSharper disable once CheckNamespace
|
---|
| 29 | namespace HeuristicLab.Algorithms.EGO {
|
---|
| 30 |
|
---|
[17332] | 31 | [StorableType("5e725905-0d77-4379-bbb9-8ca6ae392e59")]
|
---|
| 32 | [Item("UniformRandomSampling", "A uniform random sampling strategy for real valued optimization")]
|
---|
[15343] | 33 | public class UniformRandomSampling : ParameterizedNamedItem, IInitialSampling<RealVector> {
|
---|
[14833] | 34 |
|
---|
| 35 | #region HL-Constructors, Serialization and Cloning
|
---|
| 36 | [StorableConstructor]
|
---|
[17332] | 37 | protected UniformRandomSampling(StorableConstructorFlag deserializing) : base(deserializing) { }
|
---|
[15064] | 38 | protected UniformRandomSampling(UniformRandomSampling original, Cloner cloner) : base(original, cloner) { }
|
---|
[14833] | 39 | public UniformRandomSampling() {
|
---|
| 40 | }
|
---|
| 41 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 42 | return new UniformRandomSampling(this, cloner);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[15343] | 45 | public RealVector[] GetSamples(int noSamples, RealVector[] existingSamples, IEncoding encoding, IRandom random) {
|
---|
| 46 | var enc = encoding as RealVectorEncoding;
|
---|
[14833] | 47 | var res = new RealVector[noSamples];
|
---|
| 48 | for (var i = 0; i < noSamples; i++) {
|
---|
[15343] | 49 | var r = new RealVector(enc.Length);
|
---|
[14833] | 50 | res[i] = r;
|
---|
[15343] | 51 | for (var j = 0; j < enc.Length; j++) {
|
---|
| 52 | var b = j % enc.Bounds.Rows;
|
---|
| 53 | r[j] = UniformRandom(enc.Bounds[b, 0], enc.Bounds[b, 1], random);
|
---|
[14833] | 54 | }
|
---|
| 55 | }
|
---|
| 56 | return res;
|
---|
| 57 | }
|
---|
| 58 | private static double UniformRandom(double min, double max, IRandom rand) {
|
---|
| 59 | return rand.NextDouble() * (max - min) + min;
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | #endregion
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | }
|
---|
| 70 |
|
---|