Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/14/14 01:37:43 (10 years ago)
Author:
bburlacu
Message:

#1772: Fixed bug and improved the SymbolicDataAnalysisUsefulGenesAnalyzer. Fixed very minor typo in the SymbolicDataAnalysisPoly10Analyzer.

Location:
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers

    • Property svn:ignore set to
      BuidingBlocks
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisUsefulGenesAnalyzer.cs

    r11461 r11462  
    4545    private const string UpdateCounterParameterName = "UpdateCounter";
    4646    private const string UpdateIntervalParameterName = "UpdateInterval";
     47    private const string MinimumGenerationsParameterName = "MinimumGenerations";
    4748    private const string PruningProbabilityParameterName = "PruningProbability";
    4849    private const string PercentageOfBestSolutionsParameterName = "PercentageOfBestSolutions";
    4950    private const string PromotedSubtreesResultName = "Promoted subtrees";
     51    private const string AverageQualityImprovementResultName = "Average quality improvement";
     52    private const string AverageLengthReductionResultName = "Average length reduction";
    5053    private const string RandomParameterName = "Random";
    5154
     
    8588    public ValueParameter<IntValue> UpdateIntervalParameter {
    8689      get { return (ValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; }
     90    }
     91
     92    public ValueParameter<IntValue> MinimumGenerationsParameter {
     93      get { return (ValueParameter<IntValue>)Parameters[MinimumGenerationsParameterName]; }
    8794    }
    8895
     
    105112      get { return UpdateIntervalParameter.Value.Value; }
    106113      set { UpdateIntervalParameter.Value.Value = value; }
     114    }
     115
     116    public int MinimumGenerations {
     117      get { return MinimumGenerationsParameter.Value.Value; }
     118      set { MinimumGenerationsParameter.Value.Value = value; }
    107119    }
    108120
     
    129141      Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, new IntValue(0)));
    130142      Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, new IntValue(1)));
    131       Parameters.Add(new ValueParameter<PercentValue>(PercentageOfBestSolutionsParameterName, "How many of the best individuals should be pruned using this method."));
    132       Parameters.Add(new ValueParameter<PercentValue>(PruningProbabilityParameterName, "The probability to apply pruning"));
     143      Parameters.Add(new ValueParameter<IntValue>(MinimumGenerationsParameterName, "The minimum number of generations the algorithm must be let to evolve before applying this analyzer.", new IntValue(50)));
     144      Parameters.Add(new ValueParameter<PercentValue>(PercentageOfBestSolutionsParameterName, "How many of the best individuals should be pruned using this method.", new PercentValue(1.0)));
     145      Parameters.Add(new ValueParameter<PercentValue>(PruningProbabilityParameterName, "The probability to apply pruning", new PercentValue(0.1)));
    133146      #endregion
    134147    }
     
    150163    }
    151164
     165    public override void InitializeState() {
     166      UpdateCounter = 0;
     167      base.InitializeState();
     168    }
     169
    152170    public override IOperation Apply() {
     171      int generations = GenerationsParameter.ActualValue.Value;
    153172      #region Update counter & update interval
     173      if (generations < MinimumGenerations)
     174        return base.Apply();
    154175      UpdateCounter++;
    155176      if (UpdateCounter != UpdateInterval) {
     
    162183      var qualities = QualityParameter.ActualValue.ToArray();
    163184
    164       // order trees by quality
    165       Array.Sort(qualities, trees);
     185      Array.Sort(qualities, trees); // sort trees array based on qualities
    166186
    167187      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     
    171191
    172192      int replacedTrees = 0;
     193      int avgLengthReduction = 0;
     194      double avgQualityImprovement = 0;
    173195
    174196      var count = (int)Math.Floor(trees.Length * PercentageOfBestSolutions);
    175197
    176       for (int i = 0; i < count; ++i) {
     198      for (int i = trees.Length - 1; i >= trees.Length - count; --i) {
     199        if (random.NextDouble() > PruningProbability) continue;
    177200        var tree = trees[i];
    178201        var quality = qualities[i].Value;
    179202        var root = tree.Root.GetSubtree(0).GetSubtree(0);
    180203
    181         foreach (var s in root.IterateNodesPrefix()) {
    182           if (random.NextDouble() < PruningProbability) continue;
     204        foreach (var s in root.IterateNodesPrefix().Skip(1)) {
    183205          var r2 = EvaluateSubtree(s, interpreter, problemData, rows);
    184           if (s == root || r2 < quality) continue;
     206          if (double.IsNaN(r2) || r2 <= quality) continue;
     207          avgQualityImprovement += (r2 - quality);
     208          avgLengthReduction += (tree.Length - s.GetLength());
     209          replacedTrees++;
     210          // replace tree with its own subtree
    185211          var startNode = tree.Root.GetSubtree(0);
    186212          startNode.RemoveSubtree(0);
    187213          startNode.AddSubtree(s);
    188           replacedTrees++;
     214          // update tree quality
     215          qualities[i].Value = r2;
     216
    189217          break;
    190218        }
    191219      }
     220
     221      avgQualityImprovement /= replacedTrees;
     222      avgLengthReduction = (int)Math.Round((double)avgLengthReduction / replacedTrees);
    192223
    193224      var results = ResultCollectionParameter.ActualValue;
     
    202233      table.Rows[PromotedSubtreesResultName].Values.Add(replacedTrees);
    203234
     235      if (results.ContainsKey(AverageQualityImprovementResultName)) {
     236        table = (DataTable)results[AverageQualityImprovementResultName].Value;
     237      } else {
     238        table = new DataTable(AverageQualityImprovementResultName);
     239        table.Rows.Add(new DataRow(AverageQualityImprovementResultName));
     240        results.Add(new Result(AverageQualityImprovementResultName, table));
     241      }
     242      table.Rows[AverageQualityImprovementResultName].Values.Add(avgQualityImprovement);
     243
     244      if (results.ContainsKey(AverageLengthReductionResultName)) {
     245        table = (DataTable)results[AverageLengthReductionResultName].Value;
     246      } else {
     247        table = new DataTable(AverageLengthReductionResultName);
     248        table.Rows.Add(new DataRow(AverageLengthReductionResultName));
     249        results.Add(new Result(AverageLengthReductionResultName, table));
     250      }
     251      table.Rows[AverageLengthReductionResultName].Values.Add(avgLengthReduction);
     252
    204253      return base.Apply();
    205254    }
Note: See TracChangeset for help on using the changeset viewer.