Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10275


Ignore:
Timestamp:
01/04/14 01:39:50 (11 years ago)
Author:
ascheibe
Message:

#1886 added calculation of diameter and updated convex hull modifier to calculate the new measures

Location:
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/ConvexHullMeasures.cs

    r10274 r10275  
    9090    }
    9191
    92     public static double[] CalculateCentroid(List<double[]> convexHull) {
     92    public static double[] CalculateCentroids(List<double[]> convexHull) {
    9393      int n = convexHull.Count;
    9494      int dim = convexHull.First().Length;
     
    132132      double ca = c.EuclideanDistance(a);
    133133
    134       return Math.Acos((ab * ab + bc * bc - ca * ca) / (2 * ab * bc));
     134      //return degrees
     135      return Math.Acos((ab * ab + bc * bc - ca * ca) / (2 * ab * bc)) * 180.0 / Math.PI;
    135136    }
    136137
     
    145146      return thetas;
    146147    }
     148
     149    public static double CalculateMaxDiameter(List<double[]> convexHull) {
     150      double maxDist = double.MinValue;
     151
     152      for (int i = 0; i < convexHull.Count; i++) {
     153        for (int j = 0; j < convexHull.Count; j++) {
     154          if (i != j) {
     155            double dist = convexHull[i].EuclideanDistance(convexHull[j]);
     156            if (dist > maxDist)
     157              maxDist = dist;
     158          }
     159        }
     160      }
     161      return maxDist;
     162    }
    147163  }
    148164}
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers-3.3.csproj

    r10262 r10275  
    9393      <Private>False</Private>
    9494    </Reference>
     95    <Reference Include="HeuristicLab.Problems.TestFunctions-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     96      <SpecificVersion>False</SpecificVersion>
     97      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.TestFunctions-3.3.dll</HintPath>
     98      <Private>False</Private>
     99    </Reference>
    95100    <Reference Include="HeuristicLab.Problems.TravelingSalesman-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    96101      <SpecificVersion>False</SpecificVersion>
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/Plugin.cs.frame

    r10116 r10275  
    3333  [PluginDependency("HeuristicLab.Encodings.RealVectorEncoding", "3.3")]
    3434  [PluginDependency("HeuristicLab.Problems.TravelingSalesman", "3.3")]
     35  [PluginDependency("HeuristicLab.Problems.TestFunctions", "3.3")]
    3536  [PluginDependency("HeuristicLab.Operators", "3.3")]
    3637  [PluginDependency("HeuristicLab.Optimization", "3.3")]
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/RunCollectionModifiers/RealVectorConvexHullModifier.cs

    r10272 r10275  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    2829using HeuristicLab.Encodings.RealVectorEncoding;
    2930using HeuristicLab.Optimization;
     31using HeuristicLab.Parameters;
    3032using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     33using HeuristicLab.Problems.TestFunctions;
    3134
    3235namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
     
    3538  public class RealVectorConvexHullModifier : ParameterizedNamedItem, IRunCollectionModifier {
    3639    private const string SolutionCacheResultName = "SolutionCache";
     40    private const string CentroidMovementDistancesName = "Centroid Movement Distances";
     41    private const string CentroidMotionName = "Centroid Motion";
     42    private const string BestSolutionName = "Best Solution";
     43
     44    public IValueParameter<DoubleArray> BestSolutionParameter {
     45      get { return (ValueParameter<DoubleArray>)Parameters[BestSolutionName]; }
     46    }
    3747
    3848    [StorableConstructor]
    3949    protected RealVectorConvexHullModifier(bool deserializing) : base(deserializing) { }
    4050    protected RealVectorConvexHullModifier(RealVectorConvexHullModifier original, Cloner cloner) : base(original, cloner) { }
    41     public RealVectorConvexHullModifier() { }
     51    public RealVectorConvexHullModifier() {
     52      Parameters.Add(new ValueParameter<DoubleArray>(BestSolutionName, new DoubleArray()));
     53    }
    4254    public override IDeepCloneable Clone(Cloner cloner) {
    4355      return new RealVectorConvexHullModifier(this, cloner);
     
    5163        if (solutionCache == null) continue;
    5264
     65        List<double[]> centroidList = new List<double[]>();
     66        var bestSolution = run.Results["Best Solution"] as SingleObjectiveTestFunctionSolution;
     67        //var bestKnownSolution = ConvertRealVectorToVertexArray(bestSolution.BestKnownRealVector);
     68        var bestKnownSolution = BestSolutionParameter.Value;
     69
    5370        DataTable volDataTable = new DataTable("Convex hull volume over generations");
    5471        DataTable nrOfPointsTable = new DataTable("Nr. of points of convex hull");
     72        DataTable centroidDistancesTable = new DataTable(CentroidMovementDistancesName);
     73        DataTable centroidMotionTable = new DataTable(CentroidMotionName);
    5574        DoubleValue overallVolume = new DoubleValue();
    5675
    5776        DataRow dtVolumeRow = new DataRow("Volume");
    5877        DataRow dtNrPointsRow = new DataRow("Nr. of points");
     78        DataRow dtCentroidDistances = new DataRow("Distances");
     79        DataRow dtCentroidMotion = new DataRow("Motion");
     80        DataRow dtCentroidDistanceFromOptimum = new DataRow("Distance from optimum");
     81        centroidMotionTable.Rows.Add(dtCentroidMotion);
     82        centroidDistancesTable.Rows.Add(dtCentroidDistances);
     83        centroidDistancesTable.Rows.Add(dtCentroidDistanceFromOptimum);
    5984        volDataTable.Rows.Add(dtVolumeRow);
    6085        nrOfPointsTable.Rows.Add(dtNrPointsRow);
    6186
    62         List<double[]> curHull = null;
     87        List<double[]> completeHull = null;
    6388        var sols = solutionCache.GetSolutionsFromGeneration(i);
    6489        while (sols.Count != 0) {
     
    7297          }
    7398          dtNrPointsRow.Values.Add(convexHull.Count);
     99          centroidList.Add(ConvexHullMeasures.CalculateCentroids(convexHull));
    74100
    75           if (curHull == null) {
    76             curHull = convexHull;
     101          //incrementally build complete convex hull
     102          if (completeHull == null) {
     103            completeHull = convexHull;
    77104          } else {
    78             var newPHull = curHull.Union(convexHull).ToArray();
    79             curHull = LPHull.Calculate(newPHull);
     105            var newPHull = completeHull.Union(convexHull).ToArray();
     106            completeHull = LPHull.Calculate(newPHull);
    80107          }
    81108
     
    83110        }
    84111
    85         if (curHull != null && curHull.Any() && curHull.First().Length < curHull.Count) {
    86           overallVolume.Value = ConvexHullMeasures.CalculateVolume(curHull);
     112        if (completeHull != null && completeHull.Any() && completeHull.First().Length < completeHull.Count) {
     113          overallVolume.Value = ConvexHullMeasures.CalculateVolume(completeHull);
    87114        } else {
    88115          overallVolume.Value = double.NaN;
    89116        }
    90117
     118        CalculateMovementDistances(dtCentroidDistances, centroidList, run);
     119        CalculateMotionMeasures(dtCentroidMotion, centroidList, run);
     120        CalculateCentroidDistanceFromOptimum(dtCentroidDistanceFromOptimum, centroidList, bestKnownSolution.ToArray());
     121
    91122        run.Results["Overall volume"] = overallVolume;
     123        run.Results["Overall diameter"] = new DoubleValue(ConvexHullMeasures.CalculateMaxDiameter(completeHull));
    92124        run.Results["Convex hull volume"] = volDataTable;
    93125        run.Results["Nr. of points on convex hull"] = nrOfPointsTable;
     126        run.Results[CentroidMovementDistancesName] = centroidDistancesTable;
     127        run.Results[CentroidMotionName] = centroidMotionTable;
    94128      }
     129    }
     130
     131    private void CalculateCentroidDistanceFromOptimum(DataRow row, List<double[]> centroidList, double[] bestKnownSolution) {
     132      foreach (var centroid in centroidList) {
     133        double distance = centroid.EuclideanDistance(bestKnownSolution);
     134        row.Values.Add(distance);
     135      }
     136    }
     137
     138    private void CalculateMovementDistances(DataRow row, List<double[]> centroidList, IRun run) {
     139      var distances = ConvexHullMeasures.CalculateMovementDistances(centroidList);
     140      foreach (var distance in distances) {
     141        row.Values.Add(distance);
     142      }
     143      run.Results["Centroid Movement Distance Avg."] = new DoubleValue(distances.Average());
     144      run.Results["Centroid Movement Distance Std.Dev."] = new DoubleValue(distances.StandardDeviation());
     145      run.Results["Centroid Movement Distance Sum"] = new DoubleValue(distances.Sum());
     146      run.Results["Centroid Movement Overall Distance"] = new DoubleValue(ConvexHullMeasures.CalculateOverallMovementDistances(centroidList));
     147    }
     148
     149    private void CalculateMotionMeasures(DataRow row, List<double[]> centroidList, IRun run) {
     150      var motions = ConvexHullMeasures.CalculateCentroidsMotion(centroidList).Select(y => Math.Abs(y)).ToList();
     151      foreach (var motion in motions) {
     152        row.Values.Add(motion);
     153      }
     154      run.Results["Centroid Motion Avg."] = new DoubleValue(motions.Average());
     155      run.Results["Centroid Motion Std.Dev."] = new DoubleValue(motions.StandardDeviation());
     156      run.Results["Centroid Motion Sum"] = new DoubleValue(motions.Sum());
    95157    }
    96158
Note: See TracChangeset for help on using the changeset viewer.