Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/09/15 00:16:03 (9 years ago)
Author:
bburlacu
Message:

#1772: Performance improvement changes

  • QueryMatch.cs: eliminate unnecessary ToList() call and expensive GetBranchLevel calls
  • Diversification: eliminated creation of shallow copies of the individual subscopes as it was either too slow (due to events being registered/deregistered when variables are added to the scope) or too leaky (if attempting to clear the scopes without clearing the variables then the code is leaking EventHandlers)
  • Aggregated diversification statistics separately with the help of some parameters set up in the SchemaCreator and SchemaEvaluator
  • Made code in the UpdateEstimatedValuesOperator perform exactly as in the evaluator (updating quality and estimated values)
  • Removed no longer needed SchemaCleanupOperator
  • Do not evaluate intermediate vertices in the genealogy analyzer if the TrimOlderGenerations flag is activated

New functionality:

  • parameter to control the fraction of the population to be considered by the diversification strategy
  • parameter to control whether individuals may be matched by any schema and mutated only once (exclusive matching)
  • parameter to control whether linear scaling should be applied to the estimated values used for the calculation of phenotypic similarity (default: yes)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaEvaluator.cs

    r12979 r12988  
    5050    private const string MutatorParameterName = "Mutator";
    5151    private const string RandomReplacementParameterName = "RandomReplacement";
    52     private const string ChangedTreesParameterName = "ChangedTrees";
     52    private const string NumberOfChangedTreesParameterName = "NumberOfChangedTrees";
    5353    private const string ExecuteInParallelParameterName = "ExecuteInParallel";
    5454    private const string MaxDegreeOfParalellismParameterName = "MaxDegreeOfParallelism";
     55    private const string ExclusiveMatchingParameterName = "ExclusiveMatching";
    5556    #endregion
    5657
    5758    #region parameters
     59    public ILookupParameter<BoolValue> ExclusiveMatchingParameter {
     60      get { return (ILookupParameter<BoolValue>)Parameters[ExclusiveMatchingParameterName]; }
     61    }
    5862    public ILookupParameter<BoolValue> ExecuteInParallelParameter {
    5963      get { return (ILookupParameter<BoolValue>)Parameters[ExecuteInParallelParameterName]; }
     
    101105      get { return (ILookupParameter<PercentValue>)Parameters[MinimumPhenotypicSimilarityParameterName]; }
    102106    }
    103     public LookupParameter<IntValue> ChangedTreesParameter {
    104       get { return (LookupParameter<IntValue>)Parameters[ChangedTreesParameterName]; }
     107    public LookupParameter<IntValue> NumberOfChangedTreesParameter {
     108      get { return (LookupParameter<IntValue>)Parameters[NumberOfChangedTreesParameterName]; }
    105109    }
    106110    #endregion
     
    111115    public PercentValue MinimumPhenotypicSimilarity { get { return MinimumPhenotypicSimilarityParameter.ActualValue; } }
    112116    public BoolValue RandomReplacement { get { return RandomReplacementParameter.ActualValue; } }
     117    public IntValue NumberOfChangedTrees { get { return NumberOfChangedTreesParameter.ActualValue; } }
    113118    #endregion
    114119
     
    122127    };
    123128
     129    public ISymbolicExpressionTree Schema { get; set; }
     130
    124131    [Storable]
    125132    private readonly UpdateEstimatedValuesOperator updateEstimatedValuesOperator;
     
    128135      qm = new QueryMatch(comp) { MatchParents = true };
    129136      this.updateEstimatedValuesOperator = new UpdateEstimatedValuesOperator();
    130 
     137      #region add parameters
    131138      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SchemaParameterName, "The current schema to be evaluated"));
    132139      Parameters.Add(new LookupParameter<PercentValue>(MinimumSchemaFrequencyParameterName));
     
    142149      Parameters.Add(new LookupParameter<ISymbolicExpressionTreeManipulator>(MutatorParameterName));
    143150      Parameters.Add(new LookupParameter<BoolValue>(RandomReplacementParameterName));
    144       Parameters.Add(new LookupParameter<IntValue>(ChangedTreesParameterName));
     151      Parameters.Add(new LookupParameter<IntValue>(NumberOfChangedTreesParameterName));
    145152      Parameters.Add(new LookupParameter<BoolValue>(ExecuteInParallelParameterName));
    146153      Parameters.Add(new LookupParameter<IntValue>(MaxDegreeOfParalellismParameterName));
     154      Parameters.Add(new LookupParameter<BoolValue>(ExclusiveMatchingParameterName));
     155      #endregion
    147156    }
    148157
     
    170179      var mutator = MutatorParameter.ActualValue;
    171180
    172       var s = SchemaParameter.ActualValue;
     181      var s = Schema;
    173182      var sRoot = s.Root.GetSubtree(0).GetSubtree(0);
    174183      int countThreshold = (int)Math.Max(2, Math.Round(MinimumSchemaFrequency.Value * individuals.Count));
    175184
    176185      // first apply the length and root equality checks in order to filter the individuals
    177       var filtered = (from ind in individuals
    178                       let t = (ISymbolicExpressionTree)ind.Variables["SymbolicExpressionTree"].Value
    179                       where t.Length >= s.Length && qm.Comparer.Equals(t.Root.GetSubtree(0).GetSubtree(0), sRoot)
    180                       select ind).ToList();
     186      var exclusiveMatching = ExclusiveMatchingParameter.ActualValue.Value;
     187      var filtered = exclusiveMatching ? (from ind in individuals
     188                                          where !ind.Variables.ContainsKey("AlreadyMatched")
     189                                          let t = (ISymbolicExpressionTree)ind.Variables["SymbolicExpressionTree"].Value
     190                                          where t.Length >= s.Length && qm.Comparer.Equals(t.Root.GetSubtree(0).GetSubtree(0), sRoot)
     191                                          select ind).ToList()
     192                                       : (from ind in individuals
     193                                          let t = (ISymbolicExpressionTree)ind.Variables["SymbolicExpressionTree"].Value
     194                                          where t.Length >= s.Length && qm.Comparer.Equals(t.Root.GetSubtree(0).GetSubtree(0), sRoot)
     195                                          select ind).ToList();
    181196
    182197      // if we don't have enough filtered individuals, then we are done
    183198      if (filtered.Count < countThreshold) {
    184         ChangedTreesParameter.ActualValue = new IntValue(0);
    185199        return base.Apply();
    186200      }
     
    210224      } else {
    211225        for (int i = 0; i < filtered.Count; ++i) {
    212 
    213226          // break early if it becomes impossible to reach the minimum threshold
    214227          if (matchingIndividuals.Count + filtered.Count - i < countThreshold)
     
    223236      }
    224237
     238      // additional condition: the average schema quality should be equal or greater than the population average quality
    225239      if (matchingIndividuals.Count < countThreshold) {
    226         ChangedTreesParameter.ActualValue = new IntValue(0);
    227240        return base.Apply();
    228241      }
     
    230243      var similarity = CalculatePhenotypicSimilarity(matchingIndividuals, calculator, executeInParallel, maxDegreeOfParallelism);
    231244      if (similarity < MinimumPhenotypicSimilarity.Value) {
    232         ChangedTreesParameter.ActualValue = new IntValue(0);
    233245        return base.Apply();
    234246      }
     
    244256        mutationOc.Add(mutatorOp);
    245257        updateEstimatedValues.Add(updateOp);
    246       }
    247       ChangedTreesParameter.ActualValue = new IntValue(individualsToReplace.Count);
     258        if (exclusiveMatching)
     259          ind.Variables.Add(new Core.Variable("AlreadyMatched"));
     260      }
     261
     262      NumberOfChangedTrees.Value += individualsToReplace.Count; // a lock is not necessary here because the SchemaEvaluators cannot be executed in parallel
     263
    248264      return new OperationCollection(mutationOc, updateEstimatedValues, base.Apply());
    249265    }
Note: See TracChangeset for help on using the changeset viewer.