Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/10/16 20:10:25 (8 years ago)
Author:
gkronber
Message:

#2650:

  • extended non-linear regression to work with factors
  • fixed bugs in constants optimizer and tree interpreter
  • improved simplification of factor variables
  • added support for factors to ERC view
  • added support for factors to solution comparison view
  • activated view for all factors
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs

    r14109 r14251  
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Parameters;
    29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    3029using HeuristicLab.Optimization;
    3130using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    9392      var parser = new InfixExpressionParser();
    9493      var tree = parser.Parse(modelStructure);
    95       var simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();
    96      
     94      // parser handles double and string variables equally by creating a VariableTreeNode
     95      // post-process to replace VariableTreeNodes by FactorVariableTreeNodes for all string variables
     96      var factorSymbol = new FactorVariable();
     97      factorSymbol.VariableNames =
     98        problemData.AllowedInputVariables.Where(name => problemData.Dataset.VariableHasType<string>(name));
     99      factorSymbol.AllVariableNames = factorSymbol.VariableNames;
     100      factorSymbol.VariableValues =
     101        factorSymbol.VariableNames.Select(name => new KeyValuePair<string, List<string>>(name, problemData.Dataset.GetReadOnlyStringValues(name).Distinct().ToList()));
     102
     103      foreach (var parent in tree.IterateNodesPrefix().ToArray()) {
     104        for (int i = 0; i < parent.SubtreeCount; i++) {
     105          var child = parent.GetSubtree(i) as VariableTreeNode;
     106          if (child != null && factorSymbol.VariableNames.Contains(child.VariableName)) {
     107            parent.RemoveSubtree(i);
     108            var factorTreeNode = (FactorVariableTreeNode)factorSymbol.CreateTreeNode();
     109            factorTreeNode.VariableName = child.VariableName;
     110            factorTreeNode.Weights =
     111              factorTreeNode.Symbol.GetVariableValues(factorTreeNode.VariableName).Select(_ => 1.0).ToArray(); // weight = 1.0 for each value
     112            parent.InsertSubtree(i, factorTreeNode);
     113          }
     114        }
     115      }
     116
    97117      if (!SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree)) throw new ArgumentException("The optimizer does not support the specified model structure.");
    98118
    99119      var interpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter();
    100       SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, problemData.TrainingIndices, 
     120      SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, problemData.TrainingIndices,
    101121        applyLinearScaling: false, maxIterations: maxIterations,
    102122        updateVariableWeights: false, updateConstantsInTree: true);
Note: See TracChangeset for help on using the changeset viewer.