本文整理汇总了C#中HeuristicLab.Encodings.RealVectorEncoding.RealVector类的典型用法代码示例。如果您正苦于以下问题:C# RealVector类的具体用法?C# RealVector怎么用?C# RealVector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RealVector类属于HeuristicLab.Encodings.RealVectorEncoding命名空间,在下文中一共展示了RealVector类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AdditiveMove
protected AdditiveMove(AdditiveMove original, Cloner cloner)
: base(original, cloner) {
this.Dimension = original.Dimension;
this.MoveDistance = original.MoveDistance;
if (original.RealVector != null)
this.RealVector = cloner.Clone(original.RealVector);
}
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:7,代码来源:AdditiveMove.cs
示例2: Apply
/// <summary>
/// Mutates the endogenous strategy parameters.
/// </summary>
/// <param name="random">The random number generator to use.</param>
/// <param name="vector">The strategy vector to manipulate.</param>
/// <param name="generalLearningRate">The general learning rate dampens the mutation over all dimensions.</param>
/// <param name="learningRate">The learning rate dampens the mutation in each dimension.</param>
public static void Apply(IRandom random, RealVector vector, double generalLearningRate, double learningRate) {
NormalDistributedRandom N = new NormalDistributedRandom(random, 0.0, 1.0);
double generalMultiplier = Math.Exp(generalLearningRate * N.NextDouble());
for (int i = 0; i < vector.Length; i++) {
vector[i] *= generalMultiplier * Math.Exp(learningRate * N.NextDouble());
}
}
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:14,代码来源:StrategyVectorManipulator.cs
示例3: Apply
/// <summary>
/// Checks if all elements of the given <paramref name="vector"/> are inside the bounds and if not, elements are set to the respective values of the bounds.
/// </summary>
/// <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>
/// <param name="vector">The vector to check.</param>
/// <returns>The corrected real vector.</returns>
public static void Apply(RealVector vector, DoubleMatrix bounds) {
for (int i = 0; i < vector.Length; i++) {
double min = bounds[i % bounds.Rows, 0], max = bounds[i % bounds.Rows, 1];
if (vector[i] < min) vector[i] = min;
if (vector[i] > max) vector[i] = max;
}
}
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:13,代码来源:BoundsChecker.cs
示例4: Evaluate
public override double[] Evaluate(RealVector r, int objectives) {
if (r.Length < 10 * objectives) throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than ten times the number of objectives ");
double n = r.Length;
double M = objectives;
double ratio = n / M;
double[] res = new double[objectives];
for (int j = 0; j < objectives; j++) {
double sum = 0;
for (int i = (int)(j * ratio); i < (j + 1) + ratio; i++) {
sum += r[i];
}
sum /= (int)ratio;
res[j] = sum;
}
for (int j = 0; j < M - 1; j++) {
if (res[objectives - 1] + 4 * res[j] - 1 < 0) return IllegalValue(objectives, GetMaximization(objectives));
}
double min = Double.PositiveInfinity;
for (int i = 0; i < res.Length - 1; i++) {
for (int j = 0; j < i; j++) {
double d = res[i] + res[j];
if (min < d) min = d;
}
}
if (2 * res[objectives - 1] + min - 1 < 0) return IllegalValue(objectives, GetMaximization(objectives));
return res;
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:28,代码来源:DTLZ8.cs
示例5: Apply
/// <summary>
/// Evaluates the test function for a specific <paramref name="point"/>.
/// </summary>
/// <param name="point">N-dimensional point for which the test function should be evaluated.</param>
/// <returns>The result value of the Sum Squares function at the given point.</returns>
public static double Apply(RealVector point) {
double result = 0;
for (int i = 0; i < point.Length; i++) {
result += (i + 1) * point[i] * point[i];
}
return result;
}
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:12,代码来源:SumSquaresEvaluator.cs
示例6: Evaluate
public override double[] Evaluate(RealVector r, int objectives) {
if (r.Length < objectives) {
throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives");
}
double[] res = new double[objectives];
//calculate g(Xm)
double sum = 0;
int length = r.Length - objectives + 1;
for (int i = r.Length - length; i < r.Length; i++) {
double d = r[i] - 0.5;
sum += d * d - Math.Cos(20 * Math.PI * d);
}
double g = 100 * (length + sum);
//calculating f0...fM-1
for (int i = 0; i < objectives; i++) {
double f = i == 0 ? 1 : (Math.Sin(r[objectives - i - 1] * Math.PI / 2)) * (1 + g);
for (int j = 0; j < objectives - i - 1; j++) {
f *= Math.Cos(r[j] * Math.PI / 2);
}
res[i] = f;
}
return res;
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:25,代码来源:DTLZ3.cs
示例7: Evaluate
public override double[] Evaluate(RealVector r, int objectives) {
if (r.Length < objectives) {
throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives");
}
double[] res = new double[objectives];
//calculate g(Xm)
double g = 0;
for (int i = objectives; i < r.Length; i++) {
g += Math.Pow(r[i], 0.1);
}
//phi definition
Func<double, double> phi;
phi = (double x) => { return Math.PI / (4 * (1 + g)) * (1 + 2 * g * x); };
//calculating f0...fM-1
for (int i = 0; i < objectives; i++) {
double f = i == 0 ? 1 : (Math.Sin(phi(r[objectives - i - 1]) * Math.PI / 2)) * (1 + g);
for (int j = 0; j < objectives - i - 1; j++) {
f *= Math.Cos(phi(r[j]) * Math.PI / 2);
}
res[i] = f;
}
return res;
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:26,代码来源:DTLZ6.cs
示例8: Evaluate
public override double[] Evaluate(RealVector r, int objectives) {
if (objectives != 2) throw new ArgumentException("The CIGTAB problem must always have 2 objectives");
double x = r[0];
double a = 1000;
double sum = x * x;
for (int i = 1; i < r.Length - 1; i++) {
sum += a * r[i] * r[i];
}
sum += a * a * r[r.Length - 1] * r[r.Length - 1];
//objective1
double f0 = 1 / (a * a * r.Length) * sum;
x = x - 2;
sum = x * x;
for (int i = 1; i < r.Length - 1; i++) {
sum += a * (r[i] - 2) * (r[i] - 2);
}
sum += a * a * (r[r.Length - 1] - 2) * (r[r.Length - 1] - 2);
//objective0
double f1 = 1 / (a * a * r.Length) * sum;
return new double[] { f0, f1 };
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:25,代码来源:CIGTAB.cs
示例9: G
protected override double G(RealVector y) {
double sum = 0.0;
for (int i = 1; i < y.Length; i++) {
sum += HG(y[i]);
}
return 1 + 9 * Math.Pow(sum / (y.Length - 1), 0.25);
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:7,代码来源:IHR6.cs
示例10: G
protected override double G(RealVector y) {
double sum = 0.0;
for (int i = 1; i < y.Length; i++) {
sum += y[i] * y[i] - 10 * Math.Cos(4 * Math.PI * y[i]);
}
return 1 + 10 * (y.Length - 1) + sum;
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:7,代码来源:IHR4.cs
示例11: Apply
/// <summary>
/// Performs an adaptive normally distributed all position manipulation on the given
/// <paramref name="vector"/>.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown when the strategy vector is not
/// as long as the vector to get manipulated.</exception>
/// <param name="sigma">The strategy vector determining the strength of the mutation.</param>
/// <param name="random">A random number generator.</param>
/// <param name="vector">The real vector to manipulate.</param>
/// <returns>The manipulated real vector.</returns>
public static void Apply(IRandom random, RealVector vector, RealVector sigma) {
if (sigma == null || sigma.Length == 0) throw new ArgumentException("ERROR: Vector containing the standard deviations is not defined.", "sigma");
NormalDistributedRandom N = new NormalDistributedRandom(random, 0.0, 1.0);
for (int i = 0; i < vector.Length; i++) {
vector[i] = vector[i] + (N.NextDouble() * sigma[i % sigma.Length]);
}
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:17,代码来源:FixedNormalAllPositionsManipulator.cs
示例12: Evaluate
protected override double Evaluate(double quality, RealVector point, AdditiveMove move) {
RealVectorAdditiveMoveWrapper wrapper = new RealVectorAdditiveMoveWrapper(move, point);
var eval = EvaluatorParameter.ActualValue as MultinormalEvaluator;
if (eval != null)
return eval.Evaluate(wrapper);
throw new InvalidOperationException("evaluator is not a multinormal evaluator");
}
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:7,代码来源:MultinormalAdditiveMoveEvaluator.cs
示例13: Evaluate
public override double[] Evaluate(RealVector r, int objectives) {
if (r.Length < objectives) {
throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives");
}
double[] res = new double[objectives];
//calculate g(Xm)
double g = 0, length = length = r.Length - objectives + 1;
for (int i = objectives; i < r.Length; i++) {
g += r[i];
}
g = 1.0 + 9.0 / length * g;
if (length == 0) { g = 1; }
//calculating f0...fM-2
for (int i = 0; i < objectives - 1; i++) {
res[i] = r[i];
}
//calculate fM-1
double h = objectives;
for (int i = 0; i < objectives - 1; i++) {
h -= res[i] / (1 + g) * (1 + Math.Sin(3 * Math.PI * res[i]));
}
res[objectives - 1] = (1 + g) * h;
return res;
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:27,代码来源:DTLZ7.cs
示例14: CheckConstraints
public double[] CheckConstraints(RealVector r, int objectives) {
if (r.Length < 10 * objectives) throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than ten times the number of objectives ");
double n = r.Length;
double M = objectives;
double ratio = n / M;
double[] res = new double[objectives];
double[] constraints = new double[objectives];
for (int j = 0; j < objectives; j++) {
double sum = 0;
for (int i = (int)(j * ratio); i < (j + 1) + ratio; i++) {
sum += r[i];
}
sum /= (int)ratio;
res[j] = sum;
}
for (int j = 0; j < M - 1; j++) {
double d1 = res[objectives - 1] + 4 * res[j] - 1;
constraints[j] = d1 < 0 ? -d1 : 0;
}
double min = Double.PositiveInfinity;
for (int i = 0; i < res.Length - 1; i++) {
for (int j = 0; j < i; j++) {
double d2 = res[i] + res[j];
if (min < d2) min = d2;
}
}
double d = 2 * res[objectives - 1] + min - 1;
constraints[constraints.Length - 1] = d < 0 ? -d : 0;
return constraints;
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:30,代码来源:DTLZ8.cs
示例15: Apply
/// <summary>
/// Performs a breeder genetic algorithm manipulation on the given <paramref name="vector"/>.
/// </summary>
/// <param name="random">A random number generator.</param>
/// <param name="vector">The real vector to manipulate.</param>
/// <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>
/// <param name="searchIntervalFactor">The factor determining the size of the search interval.</param>
public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, DoubleValue searchIntervalFactor) {
int length = vector.Length;
double prob, value;
do {
value = Sigma(random);
} while (value == 0);
prob = 1.0 / (double)length;
bool wasMutated = false;
for (int i = 0; i < length; i++) {
if (random.NextDouble() < prob) {
double range = bounds[i % bounds.Rows, 1] - bounds[i % bounds.Rows, 0];
if (random.NextDouble() < 0.5) {
vector[i] = vector[i] + value * searchIntervalFactor.Value * range;
} else {
vector[i] = vector[i] - value * searchIntervalFactor.Value * range;
}
wasMutated = true;
}
}
// make sure at least one gene was mutated
if (!wasMutated) {
int pos = random.Next(length);
double range = bounds[pos % bounds.Rows, 1] - bounds[pos % bounds.Rows, 0];
if (random.NextDouble() < 0.5) {
vector[pos] = vector[pos] + value * searchIntervalFactor.Value * range;
} else {
vector[pos] = vector[pos] - value * searchIntervalFactor.Value * range;
}
}
}
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:40,代码来源:BreederGeneticAlgorithmManipulator.cs
示例16: Evaluate
public override double[] Evaluate(RealVector r) {
double g = 0;
for (int i = 1; i < r.Length; i++) g += r[i];
g = 1.0 + 9.0 * g / (r.Length - 1);
double f0 = r[0];
double f1 = g * (1.0 - Math.Sqrt(r[0] / g));
return new double[] { f0, f1 };
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:8,代码来源:ZDT1.cs
示例17: Evaluate
public override double[] Evaluate(RealVector r) {
double g = 0;
for (int i = 1; i < r.Length; i++) g += r[i];
g = 1.0 + 9.0 * Math.Pow(g / (r.Length - 1), 0.25);
double f1 = 1 - Math.Exp(-4 * r[0]) * Math.Pow(Math.Sin(6 * Math.PI * r[0]), 6);
double d = f1 / g;
double f2 = g * (1.0 - d * d);
return new double[] { f1, f2 };
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:9,代码来源:ZDT6.cs
示例18: GetOptimalParetoFront
protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) {
List<double[]> res = new List<double[]>();
for (int i = 0; i <= 500; i++) {
RealVector r = new RealVector(objectives);
r[0] = 1 / 500.0 * i;
res.Add(this.Evaluate(r, objectives));
}
return res;
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:9,代码来源:IHR6.cs
示例19: Apply
/// <summary>
/// Performs the arithmetic crossover on all positions by calculating x = alpha * p1 + (1 - alpha) * p2.
/// </summary>
/// <exception cref="ArgumentException">Thrown when the parent vectors are of different length or alpha is outside the range [0;1].</exception>
/// <param name="random">The random number generator.</param>
/// <param name="parent1">The first parent vector.</param>
/// <param name="parent2">The second parent vector.</param>
/// <param name="alpha">The alpha parameter (<see cref="AlphaParameter"/>).</param>
/// <returns>The vector resulting from the crossover.</returns>
public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2, DoubleValue alpha) {
int length = parent1.Length;
if (length != parent2.Length) throw new ArgumentException("UniformAllPositionsArithmeticCrossover: The parent vectors are of different length.", "parent1");
if (alpha.Value < 0 || alpha.Value > 1) throw new ArgumentException("UniformAllPositionsArithmeticCrossover: Parameter alpha must be in the range [0;1]", "alpha");
RealVector result = new RealVector(length);
for (int i = 0; i < length; i++) {
result[i] = alpha.Value * parent1[i] + (1 - alpha.Value) * parent2[i];
}
return result;
}
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:19,代码来源:UniformAllPositionsArithmeticCrossover.cs
示例20: Apply
/// <summary>
/// Evaluates the test function for a specific <paramref name="point"/>.
/// </summary>
/// <param name="point">N-dimensional point for which the test function should be evaluated.</param>
/// <returns>The result value of the Zakharov function at the given point.</returns>
public static double Apply(RealVector point) {
int length = point.Length;
double s1 = 0;
double s2 = 0;
for (int i = 0; i < length; i++) {
s1 += point[i] * point[i];
s2 += 0.5 * i * point[i];
}
return s1 + (s2 * s2) + (s2 * s2 * s2 * s2);
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:16,代码来源:ZakharovEvaluator.cs
注:本文中的HeuristicLab.Encodings.RealVectorEncoding.RealVector类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论