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 |
|
---|
22 | using HEAL.Attic;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Optimization;
|
---|
26 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
27 |
|
---|
28 | // ReSharper disable once CheckNamespace
|
---|
29 | namespace HeuristicLab.Algorithms.EGO {
|
---|
30 |
|
---|
31 | [StorableType("5e725905-0d77-4379-bbb9-8ca6ae392e59")]
|
---|
32 | [Item("UniformRandomSampling", "A uniform random sampling strategy for real valued optimization")]
|
---|
33 | public class UniformRandomSampling : ParameterizedNamedItem, IInitialSampling<RealVector> {
|
---|
34 |
|
---|
35 | #region HL-Constructors, Serialization and Cloning
|
---|
36 | [StorableConstructor]
|
---|
37 | protected UniformRandomSampling(StorableConstructorFlag deserializing) : base(deserializing) { }
|
---|
38 | protected UniformRandomSampling(UniformRandomSampling original, Cloner cloner) : base(original, cloner) { }
|
---|
39 | public UniformRandomSampling() {
|
---|
40 | }
|
---|
41 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
42 | return new UniformRandomSampling(this, cloner);
|
---|
43 | }
|
---|
44 |
|
---|
45 | public RealVector[] GetSamples(int noSamples, RealVector[] existingSamples, IEncoding encoding, IRandom random) {
|
---|
46 | var enc = encoding as RealVectorEncoding;
|
---|
47 | var res = new RealVector[noSamples];
|
---|
48 | for (var i = 0; i < noSamples; i++) {
|
---|
49 | var r = new RealVector(enc.Length);
|
---|
50 | res[i] = r;
|
---|
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);
|
---|
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 |
|
---|