Changeset 8086 for branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/SimilarityCalculators/SingleObjectiveTestFunctionSimilarityCalculator.cs
- Timestamp:
- 06/22/12 11:11:38 (12 years ago)
- Location:
- branches/ScatterSearch (trunk integration)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)
- Property svn:ignore
-
old new 20 20 bin 21 21 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/SimilarityCalculators/SingleObjectiveTestFunctionSimilarityCalculator.cs
r7954 r8086 26 26 using HeuristicLab.Encodings.RealVectorEncoding; 27 27 using HeuristicLab.Optimization.Operators; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;29 28 30 29 namespace HeuristicLab.Problems.TestFunctions { … … 33 32 /// </summary> 34 33 [Item("SingleObjectiveTestFunctionSimilarityCalculator", "An operator that performs similarity calculation between two test functions solutions.")] 35 [StorableClass]36 34 public sealed class SingleObjectiveTestFunctionSimilarityCalculator : SimilarityCalculator { 37 35 #region Properties … … 39 37 #endregion 40 38 41 [StorableConstructor]42 39 private SingleObjectiveTestFunctionSimilarityCalculator(bool deserializing) : base(deserializing) { } 43 40 private SingleObjectiveTestFunctionSimilarityCalculator(SingleObjectiveTestFunctionSimilarityCalculator original, Cloner cloner) : base(original, cloner) { } 44 41 public SingleObjectiveTestFunctionSimilarityCalculator() : base() { } 45 42 46 public override IDeepCloneable Clone(Cloner cloner) { 47 return new SingleObjectiveTestFunctionSimilarityCalculator(this, cloner); 43 public static double CalculateSimilarity(RealVector left, RealVector right, DoubleMatrix bounds) { 44 if (left == null || right == null) 45 throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null."); 46 if (bounds == null) 47 throw new ArgumentException("Cannot calculate similarity because no bounds were provided."); 48 49 double maxSum = 0.0; 50 for (int i = 0; i < left.Length; i++) 51 maxSum += Math.Pow(bounds[0, 0] - bounds[0, 1], 2); 52 double maxDistance = Math.Sqrt(maxSum) / left.Length; 53 54 double sum = 0.0; 55 for (int i = 0; i < left.Length; i++) 56 sum += Math.Pow(left[i] - right[i], 2); 57 double distance = Math.Sqrt(sum) / left.Length; 58 59 return 1.0 - distance / maxDistance; 48 60 } 49 61 50 62 protected override double CalculateSimilarity(IScope left, IScope right) { 51 RealVector sol1 = left.Variables[ "Point"].Value as RealVector;52 RealVector sol2 = right.Variables[ "Point"].Value as RealVector;63 RealVector sol1 = left.Variables[Target].Value as RealVector; 64 RealVector sol2 = right.Variables[Target].Value as RealVector; 53 65 54 double maxSum = 0.0; 55 for (int i = 0; i < sol1.Length; i++) 56 maxSum += Math.Pow(Bounds[0, 0] - Bounds[0, 1], 2); 57 double maxDistance = Math.Sqrt(maxSum) / sol1.Length; 58 59 double sum = 0.0; 60 for (int i = 0; i < sol1.Length; i++) 61 sum += Math.Pow(sol1[i] - sol2[i], 2); 62 double distance = Math.Sqrt(sum) / sol1.Length; 63 64 return 1.0 - distance / maxDistance; 66 return CalculateSimilarity(sol1, sol2, Bounds); 65 67 } 66 68 }
Note: See TracChangeset
for help on using the changeset viewer.