Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12952


Ignore:
Timestamp:
09/17/15 00:31:53 (9 years ago)
Author:
bburlacu
Message:

#1772: Add tracking of the number of trees that are mutated during the diversification phase by the SchemaEvaluator.

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

Legend:

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

    r12951 r12952  
    2222using System;
    2323using System.Linq;
     24using HeuristicLab.Analysis;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    2728using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2829using HeuristicLab.EvolutionTracking;
     30using HeuristicLab.Operators;
     31using HeuristicLab.Optimization.Operators;
    2932using HeuristicLab.Parameters;
    3033using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    99102      var schemaCleanupOperator = new SchemaCleanupOperator();
    100103
     104      var changedTreesReducer = new DataReducer();
     105      changedTreesReducer.ParameterToReduce.ActualName = schemaEvaluator.ChangedTreesParameter.ActualName;
     106      changedTreesReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
     107      changedTreesReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); // asign the sum to the target parameter
     108      changedTreesReducer.TargetParameter.ActualName = "NumberOfChangedTrees";
     109
     110      var valuesCollector = new DataTableValuesCollector();
     111      valuesCollector.CollectedValues.Add(new LookupParameter<IntValue>("NumberOfChangedTrees"));
     112      valuesCollector.DataTableParameter.ActualName = "Diversification";
     113
     114      var resultCollector = new ResultsCollector();
     115      resultCollector.CollectedValues.Add(new LookupParameter<DataTable>("Diversification"));
     116
     117      var reduceChangedTrees = ExecutionContext.CreateChildOperation(changedTreesReducer);
     118      var collectValues = ExecutionContext.CreateChildOperation(valuesCollector);
     119      var collectResults = ExecutionContext.CreateChildOperation(resultCollector);
     120
    101121      var oc = new OperationCollection();
    102122
     
    114134        var nodesToReplace = indices.Where(x => x >= 2).Select(x => nodes[x]).ToList();
    115135        for (int i = nodesToReplace.Count - 1; i >= 0; --i) {
     136          var node = nodesToReplace[i];
     137
     138          // do not replace the node with a wildcard if it would result in a length < MinimumSchemaLength
     139          if ((schema.Length - node.GetLength() + 1) < MinimumSchemaLength)
     140            continue;
     141
    116142          var replacement = anySubtreeSymbol.CreateTreeNode();
    117           ReplaceSubtree(nodesToReplace[i], replacement, false);
     143          ReplaceSubtree(node, replacement, false);
    118144          replaced = true;
    119145        }
     
    131157      var cleanup = ExecutionContext.CreateChildOperation(schemaCleanupOperator);
    132158      // return an operation collection containing all the scope operations + base.Apply()
    133       return new OperationCollection { oc, cleanup, base.Apply() };
     159      return new OperationCollection { oc, reduceChangedTrees, collectValues, collectResults, cleanup, base.Apply() };
    134160    }
    135161
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaEvaluator.cs

    r12951 r12952  
    3535  [StorableClass]
    3636  public class SchemaEvaluator : EvolutionTrackingOperator<ISymbolicExpressionTree> {
     37    #region parameter names
    3738    private const string MinimumSchemaFrequencyParameterName = "MinimumSchemaFrequency";
    3839    private const string MinimumPhenotypicSimilarityParameterName = "MinimumPhenotypicSimilarity";
     
    4849    private const string MutatorParameterName = "Mutator";
    4950    private const string RandomReplacementParameterName = "RandomReplacement";
     51    private const string ChangedTreesParameterName = "ChangedTrees";
     52    #endregion
     53
     54    #region parameters
     55    public ILookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>> EvaluatorParameter {
     56      get { return (ILookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>>)Parameters[EvaluatorParameterName]; }
     57    }
     58    public ILookupParameter<IRegressionProblemData> ProblemDataParameter {
     59      get { return (ILookupParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; }
     60    }
     61    public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> InterpreterParameter {
     62      get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[InterpreterParameterName]; }
     63    }
     64    public ILookupParameter<DoubleLimit> EstimationLimitsParameter {
     65      get { return (ILookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
     66    }
     67    public ILookupParameter<BoolValue> ApplyLinearScalingParameter {
     68      get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     69    }
     70    public ILookupParameter<BoolValue> RandomReplacementParameter {
     71      get { return (ILookupParameter<BoolValue>)Parameters[RandomReplacementParameterName]; }
     72    }
     73    public ILookupParameter<ISymbolicExpressionTreeManipulator> MutatorParameter {
     74      get { return (ILookupParameter<ISymbolicExpressionTreeManipulator>)Parameters[MutatorParameterName]; }
     75    }
     76    public ILookupParameter<IRandom> RandomParameter {
     77      get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
     78    }
     79    public ILookupParameter<IntValue> PopulationSizeParameter {
     80      get { return (ILookupParameter<IntValue>)Parameters[PopulationSizeParameterName]; }
     81    }
     82    public ILookupParameter<ISymbolicExpressionTree> SchemaParameter {
     83      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SchemaParameterName]; }
     84    }
     85    public ILookupParameter<PercentValue> MinimumSchemaFrequencyParameter {
     86      get { return (ILookupParameter<PercentValue>)Parameters[MinimumSchemaFrequencyParameterName]; }
     87    }
     88    public ILookupParameter<PercentValue> ReplacementRatioParameter {
     89      get { return (ILookupParameter<PercentValue>)Parameters[ReplacementRatioParameterName]; }
     90    }
     91    public ILookupParameter<PercentValue> MinimumPhenotypicSimilarityParameter {
     92      get { return (ILookupParameter<PercentValue>)Parameters[MinimumPhenotypicSimilarityParameterName]; }
     93    }
     94    public LookupParameter<IntValue> ChangedTreesParameter {
     95      get { return (LookupParameter<IntValue>)Parameters[ChangedTreesParameterName]; }
     96    }
     97
     98    #endregion
     99
     100    #region parameter properties
     101    public PercentValue MinimumSchemaFrequency {
     102      get { return MinimumSchemaFrequencyParameter.ActualValue; }
     103    }
     104
     105    public PercentValue ReplacementRatio {
     106      get { return ReplacementRatioParameter.ActualValue; }
     107    }
     108
     109    public PercentValue MinimumPhenotypicSimilarity {
     110      get { return MinimumPhenotypicSimilarityParameter.ActualValue; }
     111    }
     112
     113    public BoolValue RandomReplacement {
     114      get { return RandomReplacementParameter.ActualValue; }
     115    }
     116    #endregion
    50117
    51118    private readonly SymbolicExpressionTreePhenotypicSimilarityCalculator calculator = new SymbolicExpressionTreePhenotypicSimilarityCalculator();
     119    private readonly QueryMatch qm;
    52120
    53121    private readonly ISymbolicExpressionTreeNodeEqualityComparer comp = new SymbolicExpressionTreeNodeEqualityComparer {
     
    57125    };
    58126
    59     private readonly QueryMatch qm;
    60 
    61     #region parameters
    62     public ILookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>> EvaluatorParameter {
    63       get { return (ILookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>>)Parameters[EvaluatorParameterName]; }
    64     }
    65     public ILookupParameter<IRegressionProblemData> ProblemDataParameter {
    66       get { return (ILookupParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; }
    67     }
    68     public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> InterpreterParameter {
    69       get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[InterpreterParameterName]; }
    70     }
    71     public ILookupParameter<DoubleLimit> EstimationLimitsParameter {
    72       get { return (ILookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    73     }
    74     public ILookupParameter<BoolValue> ApplyLinearScalingParameter {
    75       get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    76     }
    77     public ILookupParameter<BoolValue> RandomReplacementParameter {
    78       get { return (ILookupParameter<BoolValue>)Parameters[RandomReplacementParameterName]; }
    79     }
    80     public ILookupParameter<ISymbolicExpressionTreeManipulator> MutatorParameter {
    81       get { return (ILookupParameter<ISymbolicExpressionTreeManipulator>)Parameters[MutatorParameterName]; }
    82     }
    83     public ILookupParameter<IRandom> RandomParameter {
    84       get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
    85     }
    86     public ILookupParameter<IntValue> PopulationSizeParameter {
    87       get { return (ILookupParameter<IntValue>)Parameters[PopulationSizeParameterName]; }
    88     }
    89     public ILookupParameter<ISymbolicExpressionTree> SchemaParameter {
    90       get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SchemaParameterName]; }
    91     }
    92     public ILookupParameter<PercentValue> MinimumSchemaFrequencyParameter {
    93       get { return (ILookupParameter<PercentValue>)Parameters[MinimumSchemaFrequencyParameterName]; }
    94     }
    95     public ILookupParameter<PercentValue> ReplacementRatioParameter {
    96       get { return (ILookupParameter<PercentValue>)Parameters[ReplacementRatioParameterName]; }
    97     }
    98     public ILookupParameter<PercentValue> MinimumPhenotypicSimilarityParameter {
    99       get { return (ILookupParameter<PercentValue>)Parameters[MinimumPhenotypicSimilarityParameterName]; }
    100     }
    101     #endregion
    102 
    103     #region parameter properties
    104     public PercentValue MinimumSchemaFrequency {
    105       get { return MinimumSchemaFrequencyParameter.ActualValue; }
    106     }
    107 
    108     public PercentValue ReplacementRatio {
    109       get { return ReplacementRatioParameter.ActualValue; }
    110     }
    111 
    112     public PercentValue MinimumPhenotypicSimilarity {
    113       get { return MinimumPhenotypicSimilarityParameter.ActualValue; }
    114     }
    115 
    116     public BoolValue RandomReplacement {
    117       get { return RandomReplacementParameter.ActualValue; }
    118     }
    119     #endregion
     127
     128    [StorableHook(HookType.AfterDeserialization)]
     129    private void AfterDeserialization() {
     130      if (!Parameters.ContainsKey(ChangedTreesParameterName))
     131        Parameters.Add(new LookupParameter<IntValue>(ChangedTreesParameterName));
     132    }
    120133
    121134    public SchemaEvaluator() {
     
    135148      Parameters.Add(new LookupParameter<ISymbolicExpressionTreeManipulator>(MutatorParameterName));
    136149      Parameters.Add(new LookupParameter<BoolValue>(RandomReplacementParameterName));
     150      Parameters.Add(new LookupParameter<IntValue>(ChangedTreesParameterName));
    137151    }
    138152
     
    171185                                              select ind);
    172186
    173       if (matchingIndividuals.Count < MinimumSchemaFrequency.Value * individuals.Count)
     187      if (matchingIndividuals.Count < MinimumSchemaFrequency.Value * individuals.Count) {
     188        ChangedTreesParameter.ActualValue = new IntValue(0);
    174189        return base.Apply();
     190      }
    175191
    176192      var similarity = CalculatePhenotypicSimilarity(matchingIndividuals, calculator);
    177       if (similarity < MinimumPhenotypicSimilarity.Value)
     193      if (similarity < MinimumPhenotypicSimilarity.Value) {
     194        ChangedTreesParameter.ActualValue = new IntValue(0);
    178195        return base.Apply();
     196      }
    179197
    180198      var oc = new OperationCollection();
    181 
    182199      int n = (int)Math.Round(matchingIndividuals.Count * ReplacementRatio.Value);
    183       var individualsToReplace = RandomReplacement.Value ? matchingIndividuals.SampleRandomWithoutRepetition(random, n)
    184                                                          : matchingIndividuals.OrderBy(x => (DoubleValue)x.Variables["Quality"].Value).Take(n);
     200      var individualsToReplace = RandomReplacement.Value ? matchingIndividuals.SampleRandomWithoutRepetition(random, n).ToList()
     201                                                         : matchingIndividuals.OrderBy(x => (DoubleValue)x.Variables["Quality"].Value).Take(n).ToList();
    185202      foreach (var ind in individualsToReplace) {
    186203        var mutatorOp = ExecutionContext.CreateChildOperation(mutator, ind);
     
    191208        oc.Add(updateEstimatedValuesOp);
    192209      }
    193 
     210      ChangedTreesParameter.ActualValue = new IntValue(individualsToReplace.Count);
    194211      return new OperationCollection(oc, base.Apply());
    195212    }
Note: See TracChangeset for help on using the changeset viewer.