Free cookie consent management tool by TermsFeed Policy Generator

source: tags/3.3.0/HeuristicLab.Encodings.RealVectorEncoding/3.3/Creators/UniformRandomRealVectorCreator.cs @ 3838

Last change on this file since 3838 was 3376, checked in by swagner, 14 years ago

Moved interfaces and classes for deep cloning from HeuristicLab.Core to HeuristicLab.Common (#975).

File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Encodings.RealVectorEncoding {
32  /// <summary>
33  /// An operator which creates a new random real vector with each element uniformly distributed in a specified range.
34  /// </summary>
35  [Item("UniformRandomRealVectorCreator", "An operator which creates a new random real vector with each element uniformly distributed in a specified range.")]
36  [StorableClass]
37  public class UniformRandomRealVectorCreator : RealVectorCreator, IStrategyParameterCreator {
38    /// <summary>
39    /// Generates a new random real vector with the given <paramref name="length"/> and in the interval [min,max).
40    /// </summary>
41    /// <exception cref="ArgumentException">
42    /// Thrown when <paramref name="length"/> is smaller or equal to 0.<br />
43    /// Thrown when <paramref name="min"/> is greater than <paramref name="max"/>.
44    /// </exception>
45    /// <remarks>
46    /// Note that if <paramref name="min"/> is equal to <paramref name="max"/>, all elements of the vector will be equal to <paramref name="min"/>.
47    /// </remarks>
48    /// <param name="random">The random number generator.</param>
49    /// <param name="length">The length of the real vector.</param>
50    /// <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>
51    /// <returns>The newly created real vector.</returns>
52    public static RealVector Apply(IRandom random, int length, DoubleMatrix bounds) {
53      RealVector result = new RealVector(length);
54      result.Randomize(random, bounds);
55      return result;
56    }
57
58    /// <summary>
59    /// Forwards the call to <see cref="Apply(IRandom, int, DoubleMatrix)"/>.
60    /// </summary>
61    /// <param name="random">The pseudo random number generator to use.</param>
62    /// <param name="length">The length of the real vector.</param>
63    /// <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>
64    /// <returns>The newly created real vector.</returns>
65    protected override RealVector Create(IRandom random, IntValue length, DoubleMatrix bounds) {
66      return Apply(random, length.Value, bounds);
67    }
68  }
69}
Note: See TracBrowser for help on using the repository browser.