Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/06/17 16:40:33 (8 years ago)
Author:
gkronber
Message:

#2650: use a dictionary of variable values instead of a list in FactorVariable (symbol) to remove sequential search for variable value in FactorVariableTreeNode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r14249 r14717  
    159159    [StorableHook(HookType.AfterDeserialization)]
    160160    private void AfterDeserialization() {
    161       if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) {
     161      if(!Parameters.ContainsKey(ApplyLinearScalingParameterName)) {
    162162        Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, ApplyLinearScalingParameterDescription, new BoolValue(false)));
    163163        ApplyLinearScalingParameter.Hidden = true;
     
    165165        //it is assumed that for all symbolic regression algorithms linear scaling was set to true
    166166        //there is no possibility to determine the previous value of the parameter as it was stored in the evaluator
    167         if (GetType().Name.Contains("SymbolicRegression"))
     167        if(GetType().Name.Contains("SymbolicRegression"))
    168168          ApplyLinearScaling.Value = true;
    169169      }
     
    213213      grammar.MaximumFunctionArguments = MaximumFunctionArguments.Value;
    214214      grammar.MaximumFunctionDefinitions = MaximumFunctionDefinitions.Value;
    215       foreach (var varSymbol in grammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableBase>()) {
    216         if (!varSymbol.Fixed) {
     215      foreach(var varSymbol in grammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableBase>()) {
     216        if(!varSymbol.Fixed) {
    217217          varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<double>(x));
    218218          varSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => ds.VariableHasType<double>(x));
    219219        }
    220220      }
    221       foreach (var factorSymbol in grammar.Symbols.OfType<BinaryFactorVariable>()) {
    222         if (!factorSymbol.Fixed) {
     221      foreach(var factorSymbol in grammar.Symbols.OfType<BinaryFactorVariable>()) {
     222        if(!factorSymbol.Fixed) {
    223223          factorSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<string>(x));
    224224          factorSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => ds.VariableHasType<string>(x));
     
    226226            .ToDictionary(varName => varName, varName => ds.GetStringValues(varName).Distinct().ToList());
    227227        }
    228       } foreach (var factorSymbol in grammar.Symbols.OfType<FactorVariable>()) {
    229         if (!factorSymbol.Fixed) {
     228      }
     229      foreach(var factorSymbol in grammar.Symbols.OfType<FactorVariable>()) {
     230        if(!factorSymbol.Fixed) {
    230231          factorSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<string>(x));
    231232          factorSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => ds.VariableHasType<string>(x));
    232233          factorSymbol.VariableValues = factorSymbol.VariableNames
    233             .ToDictionary(varName => varName, varName => ds.GetStringValues(varName).Distinct().ToList());
     234            .ToDictionary(varName => varName,
     235            varName => ds.GetStringValues(varName).Distinct()
     236            .Select((n, i) => Tuple.Create(n, i))
     237            .ToDictionary(tup => tup.Item1, tup => tup.Item2));
    234238        }
    235239      }
     
    276280
    277281    private void MaximumSymbolicExpressionTreeDepth_ValueChanged(object sender, EventArgs e) {
    278       if (MaximumSymbolicExpressionTreeDepth != null && MaximumSymbolicExpressionTreeDepth.Value < 3)
     282      if(MaximumSymbolicExpressionTreeDepth != null && MaximumSymbolicExpressionTreeDepth.Value < 3)
    279283        MaximumSymbolicExpressionTreeDepth.Value = 3;
    280284    }
     
    304308
    305309      var handler = ProblemDataChanged;
    306       if (handler != null) handler(this, EventArgs.Empty);
     310      if(handler != null) handler(this, EventArgs.Empty);
    307311
    308312      OnReset();
     
    313317      var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators).ToList();
    314318
    315       foreach (var op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
     319      foreach(var op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
    316320        op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameter.Name;
    317321      }
    318       foreach (var op in operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) {
     322      foreach(var op in operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) {
    319323        op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaximumSymbolicExpressionTreeDepthParameter.Name;
    320324        op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter.Name;
    321325      }
    322       foreach (var op in operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) {
     326      foreach(var op in operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) {
    323327        op.MaximumFunctionArgumentsParameter.ActualName = MaximumFunctionArgumentsParameter.Name;
    324328        op.MaximumFunctionDefinitionsParameter.ActualName = MaximumFunctionDefinitionsParameter.Name;
    325329      }
    326       foreach (var op in operators.OfType<ISymbolicDataAnalysisEvaluator<T>>()) {
     330      foreach(var op in operators.OfType<ISymbolicDataAnalysisEvaluator<T>>()) {
    327331        op.ProblemDataParameter.ActualName = ProblemDataParameterName;
    328332        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     
    331335        op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
    332336      }
    333       foreach (var op in operators.OfType<ISymbolicExpressionTreeCrossover>()) {
     337      foreach(var op in operators.OfType<ISymbolicExpressionTreeCrossover>()) {
    334338        op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    335339        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    336340      }
    337       foreach (var op in operators.OfType<ISymbolicExpressionTreeManipulator>()) {
    338         op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    339       }
    340       foreach (var op in operators.OfType<ISymbolicExpressionTreeAnalyzer>()) {
    341         op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    342       }
    343       foreach (var op in operators.OfType<ISymbolicDataAnalysisSingleObjectiveAnalyzer>()) {
     341      foreach(var op in operators.OfType<ISymbolicExpressionTreeManipulator>()) {
     342        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     343      }
     344      foreach(var op in operators.OfType<ISymbolicExpressionTreeAnalyzer>()) {
     345        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     346      }
     347      foreach(var op in operators.OfType<ISymbolicDataAnalysisSingleObjectiveAnalyzer>()) {
    344348        op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
    345349      }
    346       foreach (var op in operators.OfType<ISymbolicDataAnalysisMultiObjectiveAnalyzer>()) {
     350      foreach(var op in operators.OfType<ISymbolicDataAnalysisMultiObjectiveAnalyzer>()) {
    347351        op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
    348352      }
    349       foreach (var op in operators.OfType<ISymbolicDataAnalysisAnalyzer>()) {
    350         op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    351       }
    352       foreach (var op in operators.OfType<ISymbolicDataAnalysisValidationAnalyzer<U, T>>()) {
     353      foreach(var op in operators.OfType<ISymbolicDataAnalysisAnalyzer>()) {
     354        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     355      }
     356      foreach(var op in operators.OfType<ISymbolicDataAnalysisValidationAnalyzer<U, T>>()) {
    353357        op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name;
    354358        op.ValidationPartitionParameter.ActualName = ValidationPartitionParameter.Name;
    355359      }
    356       foreach (var op in operators.OfType<ISymbolicDataAnalysisInterpreterOperator>()) {
     360      foreach(var op in operators.OfType<ISymbolicDataAnalysisInterpreterOperator>()) {
    357361        op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
    358362      }
    359       foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) {
     363      foreach(var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) {
    360364        op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
    361365        op.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
Note: See TracChangeset for help on using the changeset viewer.