source: branches/2994-AutoDiffForIntervals/HeuristicLab.Encodings.RealVectorEncoding/3.3/Creators/UniformRandomRealVectorCreator.cs @ 17209

Last change on this file since 17209 was 17209, checked in by gkronber, 5 weeks ago

#2994: merged r17132:17198 from trunk to branch

File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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
22using System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Optimization;
27using HEAL.Attic;
28
29namespace HeuristicLab.Encodings.RealVectorEncoding {
30  /// <summary>
31  /// An operator which creates a new random real vector with each element uniformly distributed in a specified range.
32  /// </summary>
33  [Item("UniformRandomRealVectorCreator", "An operator which creates a new random real vector with each element uniformly distributed in a specified range.")]
34  [StorableType("DF237BEA-D21B-4A2C-820B-47CCC998D0E1")]
35  public class UniformRandomRealVectorCreator : RealVectorCreator, IStrategyParameterCreator {
36    [StorableConstructor]
37    protected UniformRandomRealVectorCreator(StorableConstructorFlag _) : base(_) { }
38    protected UniformRandomRealVectorCreator(UniformRandomRealVectorCreator original, Cloner cloner) : base(original, cloner) { }
39    public UniformRandomRealVectorCreator() : base() { }
40
41    public override IDeepCloneable Clone(Cloner cloner) {
42      return new UniformRandomRealVectorCreator(this, cloner);
43    }
44   
45    /// <summary>
46    /// Generates a new random real vector with the given <paramref name="length"/> and in the interval [min,max).
47    /// </summary>
48    /// <exception cref="ArgumentException">
49    /// Thrown when <paramref name="length"/> is smaller or equal to 0.<br />
50    /// Thrown when <paramref name="min"/> is greater than <paramref name="max"/>.
51    /// </exception>
52    /// <remarks>
53    /// Note that if <paramref name="min"/> is equal to <paramref name="max"/>, all elements of the vector will be equal to <paramref name="min"/>.
54    /// </remarks>
55    /// <param name="random">The random number generator.</param>
56    /// <param name="length">The length of the real vector.</param>
57    /// <param name="bounds">The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.</param>
58    /// <returns>The newly created real vector.</returns>
59    public static RealVector Apply(IRandom random, int length, DoubleMatrix bounds) {
60      RealVector result = new RealVector(length);
61      result.Randomize(random, bounds);
62      return result;
63    }
64
65    /// <summary>
66    /// Forwards the call to <see cref="Apply(IRandom, int, DoubleMatrix)"/>.
67    /// </summary>
68    /// <param name="random">The pseudo random number generator to use.</param>
69    /// <param name="length">The length of the real vector.</param>
70    /// <param name="bounds">The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.</param>
71    /// <returns>The newly created real vector.</returns>
72    protected override RealVector Create(IRandom random, IntValue length, DoubleMatrix bounds) {
73      return Apply(random, length.Value, bounds);
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.