Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8828 for trunk/sources


Ignore:
Timestamp:
10/22/12 16:01:16 (12 years ago)
Author:
mkommend
Message:

#1976: Allowed constant optimization for variable with a weight of 1.0 and made the constant optimization thread-safe (access to evaluated node results).

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs

    r8823 r8828  
    134134      }
    135135      QualityParameter.ActualValue = new DoubleValue(quality);
    136       EvaluatedTreesParameter.ActualValue.Value += 1;
    137       EvaluatedTreeNodesParameter.ActualValue.Value += solution.Length;
     136      lock (locker) {
     137        EvaluatedTreesParameter.ActualValue.Value += 1;
     138        EvaluatedTreeNodesParameter.ActualValue.Value += solution.Length;
     139      }
    138140
    139141      if (Successor != null)
     
    143145    }
    144146
     147    private object locker = new object();
    145148    private void AddResults() {
    146       if (EvaluatedTreesParameter.ActualValue == null) {
    147         var scope = ExecutionContext.Scope;
    148         while (scope.Parent != null)
    149           scope = scope.Parent;
    150         scope.Variables.Add(new Core.Variable(EvaluatedTreesResultName, new IntValue()));
    151       }
    152       if (EvaluatedTreeNodesParameter.ActualValue == null) {
    153         var scope = ExecutionContext.Scope;
    154         while (scope.Parent != null)
    155           scope = scope.Parent;
    156         scope.Variables.Add(new Core.Variable(EvaluatedTreeNodesResultName, new IntValue()));
     149      lock (locker) {
     150        if (EvaluatedTreesParameter.ActualValue == null) {
     151          var scope = ExecutionContext.Scope;
     152          while (scope.Parent != null)
     153            scope = scope.Parent;
     154          scope.Variables.Add(new Core.Variable(EvaluatedTreesResultName, new IntValue()));
     155        }
     156        if (EvaluatedTreeNodesParameter.ActualValue == null) {
     157          var scope = ExecutionContext.Scope;
     158          while (scope.Parent != null)
     159            scope = scope.Parent;
     160          scope.Variables.Add(new Core.Variable(EvaluatedTreeNodesResultName, new IntValue()));
     161        }
    157162      }
    158163    }
     
    206211
    207212      AutoDiff.Term func;
    208       if (!TryTransformToAutoDiff(tree.Root.GetSubtree(0), variables, parameters, variableNames, out func)) return 0.0;
     213      if (!TryTransformToAutoDiff(tree.Root.GetSubtree(0), variables, parameters, variableNames, out func))
     214        throw new NotSupportedException("Could not optimize constants of symbolic expression tree due to not supported symbols used in the tree.");
    209215      if (variableNames.Count == 0) return 0.0;
    210216
     
    224230          if (constantTreeNode != null)
    225231            c[i++] = constantTreeNode.Value;
    226           else if (variableTreeNode != null && !variableTreeNode.Weight.IsAlmost(1.0))
     232          else if (variableTreeNode != null)
    227233            c[i++] = variableTreeNode.Weight;
    228234        }
     
    274280          if (constantTreeNode != null)
    275281            constantTreeNode.Value = c[i++];
    276           else if (variableTreeNode != null && !variableTreeNode.Weight.IsAlmost(1.0))
     282          else if (variableTreeNode != null)
    277283            variableTreeNode.Weight = c[i++];
    278284        }
     
    304310      }
    305311      if (node.Symbol is Variable) {
    306         // don't tune weights with a value of 1.0 because it was probably set by the simplifier
    307312        var varNode = node as VariableTreeNode;
    308313        var par = new AutoDiff.Variable();
    309314        parameters.Add(par);
    310315        variableNames.Add(varNode.VariableName);
    311         if (!varNode.Weight.IsAlmost(1.0)) {
    312           var w = new AutoDiff.Variable();
    313           variables.Add(w);
    314           term = AutoDiff.TermBuilder.Product(w, par);
    315         } else {
    316           term = par;
    317         }
     316        var w = new AutoDiff.Variable();
     317        variables.Add(w);
     318        term = AutoDiff.TermBuilder.Product(w, par);
    318319        return true;
    319320      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationAnalyzer.cs

    r8793 r8828  
    7676      : base(original, cloner) {
    7777    }
    78     public SymbolicDataAnalysisSingleObjectiveValidationAnalyzer()
    79       : base() {
     78
     79    protected SymbolicDataAnalysisSingleObjectiveValidationAnalyzer(): base() {
    8080      Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random generator."));
    8181      Parameters.Add(new LookupParameter<U>(ProblemDataParameterName, "The problem data of the symbolic data analysis problem."));
Note: See TracChangeset for help on using the changeset viewer.