Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.RealVector/3.2/SelfAdaptiveNormalAllPositionsManipulator.cs @ 1688

Last change on this file since 1688 was 1530, checked in by gkronber, 16 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

File size: 3.6 KB
RevLine 
[99]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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 System.Collections.Generic;
24using System.Text;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Random;
28
29namespace HeuristicLab.RealVector {
[1184]30  /// <summary>
31  /// Manipulates each dimension in the real vector with the mutation strength given
32  /// in the strategy parameter vector.
33  /// </summary>
[99]34  public class SelfAdaptiveNormalAllPositionsManipulator : RealVectorManipulatorBase {
[1184]35    /// <inheritdoc select="summary"/>
[99]36    public override string Description {
37      get { return @"Manipulates each dimension in the real vector with the mutation strength given in the strategy parameter vector"; }
38    }
39
[1184]40    /// <summary>
41    /// Initializes a new instance of <see cref="SelfAdaptiveNormalAllPositionsManipulator"/> with one
42    /// variable info (<c>StrategyVector</c>).
43    /// </summary>
[99]44    public SelfAdaptiveNormalAllPositionsManipulator()
45      : base() {
46      AddVariableInfo(new VariableInfo("StrategyVector", "The strategy vector determining the strength of the mutation", typeof(DoubleArrayData), VariableKind.In));
47    }
48
[1184]49    /// <summary>
50    /// Performs a self adaptive normally distributed all position manipulation on the given
51    /// <paramref name="vector"/>.
52    /// </summary>
53    /// <exception cref="InvalidOperationException">Thrown when the strategy vector is not
54    /// as long as the vector to get manipulated.</exception>
55    /// <param name="strategyParameters">The strategy vector determining the strength of the mutation.</param>
56    /// <param name="random">A random number generator.</param>
57    /// <param name="vector">The real vector to manipulate.</param>
58    /// <returns>The manipulated real vector.</returns>
[99]59    public static double[] Apply(double[] strategyParameters, IRandom random, double[] vector) {
60      NormalDistributedRandom N = new NormalDistributedRandom(random, 0.0, 1.0);
61      for (int i = 0; i < vector.Length; i++) {
[1180]62        vector[i] = vector[i] + (N.NextDouble() * strategyParameters[i % strategyParameters.Length]);
[99]63      }
64      return vector;
65    }
66
[1184]67    /// <summary>
68    /// Performs a self adaptive normally distributed all position manipulation on the given
69    /// <paramref name="vector"/>.
70    /// </summary>
71    /// <remarks>Calls <see cref="Apply"/>.</remarks>
72    /// <param name="scope">The current scope.</param>
73    /// <param name="random">A random number generator.</param>
74    /// <param name="vector">The real vector to manipulate.</param>
75    /// <returns>The manipulated real vector.</returns>
[99]76    protected override double[] Manipulate(IScope scope, IRandom random, double[] vector) {
77      double[] strategyVector = scope.GetVariableValue<DoubleArrayData>("StrategyVector", true).Data;
78      return Apply(strategyVector, random, vector);
79    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.