Changeset 13496


Ignore:
Timestamp:
01/11/16 21:29:25 (5 years ago)
Author:
bburlacu
Message:

#1772: Update diversification operators (add extra evaluations to the evaluation counter, add the option for strict schema matching, add additional replacement ratio update rules.

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

Legend:

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

    r13480 r13496  
    3838    private const string ResultCollectionParameterName = "Results";
    3939    private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
     40
     41    private readonly object locker = new object();
    4042
    4143    public ILookupParameter<IntValue> NumberOfChangedTreesParameter {
     
    8385        table = new DataTable();
    8486        results.Add(new Result("NumberOfChangedTrees", table));
    85         var row = new DataRow("Changed trees");
     87        var row = new DataRow("Changed trees") { VisualProperties = { StartIndexZero = true } };
    8688        table.Rows.Add(row);
    8789      }
     
    8991        table = new DataTable();
    9092        results.Add(new Result("AverageSchemaLength", table));
    91         var row = new DataRow("Average schema length");
     93        var row = new DataRow("Average schema length") { VisualProperties = { StartIndexZero = true } };
    9294        table.Rows.Add(row);
    9395      }
     
    9597        table = new DataTable();
    9698        results.Add(new Result("NumberOfSchemas", table));
    97         var row = new DataRow("Number of schemas");
     99        var row = new DataRow("Number of schemas") { VisualProperties = { StartIndexZero = true } };
    98100        table.Rows.Add(row);
    99101      }
     
    101103        table = new DataTable();
    102104        results.Add(new Result("EvaluatedSolutionsPerGeneration", table));
    103         var row = new DataRow("Evaluated solutions");
     105        var row = new DataRow("Evaluated solutions") { VisualProperties = { StartIndexZero = true } };
    104106        table.Rows.Add(row);
    105107        row.Values.Add(0);
    106108      }
    107109
    108       var evaluatedSolutions = EvaluatedSolutionsParameter.ActualValue.Value - evaluatedSolutionsTracker;
     110      lock (locker) {
     111        // count the extra evaluations performed after diversification
     112        EvaluatedSolutionsParameter.ActualValue.Value += NumberOfChangedTreesParameter.ActualValue.Value;
     113      }
     114
     115      var evaluatedSolutions = EvaluatedSolutionsParameter.ActualValue.Value;
     116      if (evaluatedSolutions > 0)
     117        evaluatedSolutions -= evaluatedSolutionsTracker;
    109118      ((DataTable)results["NumberOfChangedTrees"].Value).Rows["Changed trees"].Values.Add(NumberOfChangedTreesParameter.ActualValue.Value);
    110119      ((DataTable)results["AverageSchemaLength"].Value).Rows["Average schema length"].Values.Add(AverageSchemaLengthParameter.ActualValue.Value);
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaCreator.cs

    r13480 r13496  
    5151    private const string UseAdaptiveReplacementRatioParameterName = "UseAdaptiveReplacementRatio";
    5252    private const string ReplacementRatioUpdateRuleParameterName = "ReplacementRatioUpdateRule";
     53    private const string StrictSchemaMatchingParameterName = "StrictSchemaMatching";
    5354    #endregion
    5455
     
    6061    public IFixedValueParameter<BoolValue> UseAdaptiveReplacementRatioParameter {
    6162      get { return (IFixedValueParameter<BoolValue>)Parameters[UseAdaptiveReplacementRatioParameterName]; }
     63    }
     64    public IFixedValueParameter<BoolValue> StrictSchemaMatchingParameter {
     65      get { return (IFixedValueParameter<BoolValue>)Parameters[StrictSchemaMatchingParameterName]; }
    6266    }
    6367    public IFixedValueParameter<BoolValue> ExclusiveMatchingParameter {
     
    104108    public bool ExecuteInParallel { get { return ExecuteInParallelParameter.Value.Value; } }
    105109    public double PercentageOfPopulation { get { return PercentageOfPopulationParameter.Value.Value; } }
     110    public bool StrictSchemaMatching { get { return StrictSchemaMatchingParameter.Value.Value; } }
    106111    #endregion
    107112
    108113    private UpdateEstimatedValuesOperator updateEstimatedValuesOperator;
    109114    private DiversificationStatisticsOperator diversificationStatisticsOperator;
     115
     116    public override void ClearState() {
     117      NumberOfChangedTreesParameter.Value.Value = 0;
     118      NumberOfChangedTreesParameter.Value.Value = 0;
     119      AverageSchemaLengthParameter.Value.Value = 0;
     120      base.ClearState();
     121    }
    110122
    111123    public SchemaCreator() {
     
    121133      Parameters.Add(new FixedValueParameter<BoolValue>(ScaleEstimatedValuesParameterName, new BoolValue(true)));
    122134      Parameters.Add(new FixedValueParameter<BoolValue>(ExclusiveMatchingParameterName, new BoolValue(false)));
     135      Parameters.Add(new FixedValueParameter<BoolValue>(StrictSchemaMatchingParameterName, new BoolValue(false)));
    123136      Parameters.Add(new ValueParameter<IntValue>(NumberOfChangedTreesParameterName, new IntValue(0)));
    124137      Parameters.Add(new ValueParameter<IntValue>(NumberOfSchemasParameterName, new IntValue(0)));
     
    126139      Parameters.Add(new FixedValueParameter<BoolValue>(UseAdaptiveReplacementRatioParameterName, new BoolValue(true)));
    127140
    128       var replacementRatioUpdateRules = new ItemSet<StringValue>(new[] { new StringValue("f(x) = x"), new StringValue("f(x) = tanh(x)"), new StringValue("f(x) = tanh(2x)"), new StringValue("f(x) = tanh(3x)") });
     141      var replacementRatioUpdateRules = new ItemSet<StringValue>(new[] {
     142        new StringValue("f(x) = x"),
     143        new StringValue("f(x) = tanh(x)"),
     144        new StringValue("f(x) = tanh(2x)"),
     145        new StringValue("f(x) = tanh(3x)"),
     146        new StringValue("f(x) = tanh(4x)"),
     147        new StringValue("f(x) = 1-sqrt(1-x)")
     148      });
    129149      Parameters.Add(new ConstrainedValueParameter<StringValue>(ReplacementRatioUpdateRuleParameterName, replacementRatioUpdateRules));
    130150      #endregion
     
    146166    protected SchemaCreator(bool deserializing) : base(deserializing) { }
    147167
     168
     169    [StorableHook(HookType.AfterDeserialization)]
     170    private void AfterDeserialization() {
     171      if (!Parameters.ContainsKey(StrictSchemaMatchingParameterName))
     172        Parameters.Add(new FixedValueParameter<BoolValue>(StrictSchemaMatchingParameterName, new BoolValue(false)));
     173    }
     174
    148175    public override IOperation Apply() {
    149176      // apply only when at least one generation has passed
     
    153180
    154181      var n = (int)Math.Round(ExecutionContext.Scope.SubScopes.Count * PercentageOfPopulation);
    155       var scopes = new ScopeList(ExecutionContext.Scope.SubScopes.Take(n));
    156182
    157183      var updateEstimatedValues = new OperationCollection { Parallel = true };
     
    159185        updateEstimatedValuesOperator = new UpdateEstimatedValuesOperator();
    160186
    161       foreach (var s in scopes) {
    162         if (!s.Variables.ContainsKey("EstimatedValues"))
    163           s.Variables.Add(new Core.Variable("EstimatedValues"));
     187      foreach (var s in ExecutionContext.Scope.SubScopes.Where(s => !s.Variables.ContainsKey("EstimatedValues"))) {
    164188        updateEstimatedValues.Add(ExecutionContext.CreateChildOperation(updateEstimatedValuesOperator, s));
    165189      }
     
    185209            break;
    186210          }
     211        case "f(x) = tanh(4x)": {
     212            rule = x => Math.Tanh(4 * x);
     213            break;
     214          }
     215        case "f(x) = 1-sqrt(1-x)": {
     216            rule = x => 1 - Math.Sqrt(1 - x);
     217            break;
     218          }
    187219        default:
    188220          throw new ArgumentException("Unknown replacement rule");
     
    192224
    193225      // for now, only consider crossover offspring
     226      var scopes = new ScopeList(ExecutionContext.Scope.SubScopes.OrderByDescending(x => ((DoubleValue)x.Variables["Quality"].Value).Value).Take(n));
    194227      var vertices = from s in scopes
    195228                     let t = (ISymbolicExpressionTree)s.Variables["SymbolicExpressionTree"].Value
     
    222255    public static IEnumerable<ISymbolicExpressionTree> GenerateSchemas(IEnumerable<IGenealogyGraphNode<ISymbolicExpressionTree>> vertices, int minimumSchemaLength) {
    223256      var anySubtreeSymbol = new AnySubtreeSymbol();
    224       //      var anyNodeSymbol = new AnyNodeSymbol();
     257      //            var anyNodeSymbol = new AnyNodeSymbol();
    225258      var groups = vertices.GroupBy(x => x.Parents.First()).OrderByDescending(g => g.Count()).ToList();
    226259      var hash = new HashSet<string>();
     
    246279            continue;
    247280
    248           //          var replacement = anySubtreeSymbol.CreateTreeNode();
    249           //          ReplaceSubtree(node, replacement, false);
    250           var replacement = new AnyNodeSymbol(node.Symbol.MinimumArity, node.Symbol.MinimumArity).CreateTreeNode();
    251           ReplaceSubtree(node, replacement, true);
     281          var replacement = anySubtreeSymbol.CreateTreeNode();
     282          ReplaceSubtree(node, replacement, false);
     283          //          var replacement = new AnyNodeSymbol(node.Symbol.MinimumArity, node.Symbol.MinimumArity).CreateTreeNode();
     284          //          ReplaceSubtree(node, replacement, true);
    252285          replaced = true;
    253286        }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaEvaluator.cs

    r13480 r13496  
    5858    private const string ExclusiveMatchingParameterName = "ExclusiveMatching";
    5959    private const string UseAdaptiveReplacementRatioParameterName = "UseAdaptiveReplacementRatio";
     60    private const string StrictSchemaMatchingParameterName = "StrictSchemaMatching";
    6061    #endregion
    6162
     
    117118    public LookupParameter<IntValue> NumberOfChangedTreesParameter {
    118119      get { return (LookupParameter<IntValue>)Parameters[NumberOfChangedTreesParameterName]; }
     120    }
     121    public LookupParameter<BoolValue> StrictSchemaMatchingParameter {
     122      get { return (LookupParameter<BoolValue>)Parameters[StrictSchemaMatchingParameterName]; }
    119123    }
    120124    #endregion
     
    143147    [Storable]
    144148    private readonly UpdateEstimatedValuesOperator updateEstimatedValuesOperator;
     149
     150    [StorableHook(HookType.AfterDeserialization)]
     151    private void AfterDeserialization() {
     152      if (!Parameters.ContainsKey(StrictSchemaMatchingParameterName))
     153        Parameters.Add(new LookupParameter<BoolValue>(StrictSchemaMatchingParameterName));
     154    }
    145155
    146156    public SchemaEvaluator() {
     
    159169      Parameters.Add(new LookupParameter<DoubleLimit>(EstimationLimitsParameterName));
    160170      Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName));
     171      Parameters.Add(new LookupParameter<BoolValue>(StrictSchemaMatchingParameterName));
    161172      Parameters.Add(new LookupParameter<ISymbolicExpressionTreeManipulator>(MutatorParameterName));
    162173      Parameters.Add(new LookupParameter<ISymbolicExpressionTreeCrossover>(CrossoverParameterName));
     
    188199
    189200    public override IOperation Apply() {
     201      var strictSchemaMatching = StrictSchemaMatchingParameter.ActualValue.Value;
     202      if (strictSchemaMatching) {
     203        comp.MatchVariableWeights = true;
     204        comp.MatchConstantValues = true;
     205      } else {
     206        comp.MatchVariableWeights = false;
     207        comp.MatchConstantValues = false;
     208      }
     209
    190210      var individuals = ExecutionContext.Scope.SubScopes; // the scopes represent the individuals
    191211      var trees = individuals.Select(x => (ISymbolicExpressionTree)x.Variables["SymbolicExpressionTree"].Value).ToList();
    192       var qualities = individuals.Select(x => (DoubleValue)x.Variables["Quality"].Value).ToList();
    193212
    194213      var random = RandomParameter.ActualValue;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/UpdateEstimatedValuesOperator.cs

    r12988 r13496  
    100100        beta = 1.0;
    101101      }
    102 
    103102      var scaled = estimatedValues.Select(x => x * beta + alpha).LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray();
    104103      OnlineCalculatorError error;
     
    109108
    110109      var variables = ExecutionContext.Scope.Variables;
     110
    111111      ((DoubleValue)variables["Quality"].Value).Value = r2;
    112112
Note: See TracChangeset for help on using the changeset viewer.