Changeset 10413


Ignore:
Timestamp:
01/28/14 19:12:39 (6 years ago)
Author:
bburlacu
Message:

#1837: Modified the SlidingWindowBestSolutionsCollection to use a dictionary for sliding window positions mapped to best solutions, because the last sliding window position before the algorithm reached its stop was not registered correctly.

Location:
branches/Sliding Window GP
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SlidingWindowBestSolutionsCollectionView.cs

    r10402 r10413  
    6464      var dataGridView = (DataGridView)sender;
    6565      var cell = dataGridView.SelectedCells[0];
    66       var bestSolutions = Content.BestSolutions.ToList();
     66      var bestSolutions = Content.BestSolutions.Values.ToList();
    6767      var tree = bestSolutions[cell.RowIndex];
    6868      var model = Content.CreateModel(tree, Content.Interpreter);
     
    115115
    116116    private void UpdateQualitiesMap() {
    117       var bestSolutions = Content.BestSolutions.ToList();
    118       var swPositions = Content.SlidingWindowPositions.ToList();
     117      var bestSolutions = Content.BestSolutions.Values.ToList();
     118      var swPositions = Content.BestSolutions.Keys.ToList();
    119119      var qualitiesMap = new DoubleMatrix(bestSolutions.Count, swPositions.Count + 1);
    120       qualitiesMap.ColumnNames = Content.SlidingWindowPositions.Select(x => x.Start + "-" + x.End).Concat(new List<string> { "Training" });
     120      qualitiesMap.ColumnNames = swPositions.Select(x => x.Item1 + "-" + x.Item2).Concat(new List<string> { "Training" });
    121121      qualitiesMap.RowNames = Enumerable.Range(1, bestSolutions.Count).Select(x => "M" + x);
    122122      double min = 0, max = 0;
     
    124124      for (int i = 0; i < qualitiesMap.Columns - 1; ++i) {
    125125        var pos = swPositions[i];
    126         var rows = Enumerable.Range(pos.Start, pos.End - pos.Start).ToList();
     126        var rows = Enumerable.Range(pos.Item1, pos.Item2 - pos.Item1).ToList();
    127127
    128128        for (int j = 0; j < qualitiesMap.Rows; ++j) {
  • branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/SlidingWindowAnalyzer.cs

    r10396 r10413  
    138138      }
    139139
     140      SaveBestSolution();
     141
    140142      if (!CheckForUpdate()) return base.Apply();
    141 
    142       SaveBestSolution();
    143143
    144144      //update necessary - move sliding window
     
    189189      var fitnessPartition = FitnessCalculationPartitionParameter.ActualValue;
    190190      var best = FindBestIndividual();
    191       var range = new IntRange(fitnessPartition.Start, fitnessPartition.End);
     191      var range = new Tuple<int, int>(fitnessPartition.Start, fitnessPartition.End);
    192192
    193       bestSolutionsCollection.Add(best, range);
     193      bestSolutionsCollection[range] = best;
    194194    }
    195195
  • branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/SlidingWindowBestSolutionsCollection.cs

    r10402 r10413  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 using HeuristicLab.Data;
    2625using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2726using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27
     28using SlidingWindowRange = System.Tuple<int, int>;
    2829
    2930namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    3132  [Item("SlidingWindowBestSolutionsCollection", "An object holding a collection of the best sliding window solutions.")]
    3233  public abstract class SlidingWindowBestSolutionsCollection : Item {
    33 
    34     private List<ISymbolicExpressionTree> bestSolutions;
    3534    [Storable]
    36     public IEnumerable<ISymbolicExpressionTree> BestSolutions {
     35    private Dictionary<SlidingWindowRange, ISymbolicExpressionTree> bestSolutions;
     36    public Dictionary<SlidingWindowRange, ISymbolicExpressionTree> BestSolutions {
    3737      get { return bestSolutions; }
    38       set { bestSolutions = new List<ISymbolicExpressionTree>(value); }
    39     }
    40 
    41     private List<IntRange> slidingWindowPositions;
    42     [Storable]
    43     public IEnumerable<IntRange> SlidingWindowPositions {
    44       get { return slidingWindowPositions; }
    45       set { slidingWindowPositions = new List<IntRange>(value); }
     38      set { bestSolutions = value; }
    4639    }
    4740
     
    6861      : base(original, cloner) {
    6962      this.bestSolutions = original.bestSolutions;
    70       this.slidingWindowPositions = original.slidingWindowPositions;
    7163      this.problemData = original.problemData;
    7264      this.interpreter = original.interpreter;
    7365    }
    7466    protected SlidingWindowBestSolutionsCollection() {
    75       bestSolutions = new List<ISymbolicExpressionTree>();
    76       slidingWindowPositions = new List<IntRange>();
     67      bestSolutions = new Dictionary<SlidingWindowRange, ISymbolicExpressionTree>();
    7768    }
    7869
    79     public void Add(ISymbolicExpressionTree solution, IntRange range) {
    80       if (bestSolutions == null) bestSolutions = new List<ISymbolicExpressionTree>();
    81       bestSolutions.Add(solution);
    82       if (slidingWindowPositions == null) slidingWindowPositions = new List<IntRange>();
    83       slidingWindowPositions.Add(range);
     70    public bool ContainsKey(SlidingWindowRange key) {
     71      return bestSolutions.ContainsKey(key);
     72    }
     73
     74    public ISymbolicExpressionTree this[SlidingWindowRange key] {
     75      get {
     76        return bestSolutions[key];
     77      }
     78      set {
     79        if (bestSolutions.ContainsKey(key))
     80          bestSolutions[key] = value;
     81        else
     82          bestSolutions.Add(key, value);
     83      }
     84    }
     85
     86    public void Add(SlidingWindowRange range, ISymbolicExpressionTree solution) {
     87      bestSolutions.Add(range, solution);
    8488    }
    8589
    8690    public void Clear() {
    8791      if (bestSolutions != null) bestSolutions.Clear();
    88       if (slidingWindowPositions != null) slidingWindowPositions.Clear();
    8992    }
    9093
     
    9295     double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue);
    9396
    94     public abstract ISymbolicDataAnalysisSolution CreateSolution(ISymbolicDataAnalysisModel model,
    95       IDataAnalysisProblemData problemData);
     97    public abstract ISymbolicDataAnalysisSolution CreateSolution(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData);
    9698  }
    9799}
Note: See TracChangeset for help on using the changeset viewer.