Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/04/19 17:37:13 (6 years ago)
Author:
mkommend
Message:

#2974: Added intermediate version of new constants optimization for profiling.

Location:
branches/2974_Constants_Optimization
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2974_Constants_Optimization

    • Property svn:ignore
      •  

        old new  
        11packages
         2TestResults
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Constants Optimization/Util.cs

    r16461 r16500  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Common;
    2526using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2627using static HeuristicLab.Problems.DataAnalysis.Symbolic.TreeToAutoDiffTermConverter;
     
    4849    }
    4950
    50     public static Dictionary<DataForVariable, AutoDiff.Variable> ExtractParameters(IDataset dataset) {
    51       var parameters = new Dictionary<DataForVariable, AutoDiff.Variable>();
     51    public static List<DataForVariable> GenerateVariables(IDataset dataset) {
     52      var variables = new List<DataForVariable>();
    5253      foreach (var doubleVariable in dataset.DoubleVariables) {
    5354        var data = new DataForVariable(doubleVariable, string.Empty, 0);
    54         var param = new AutoDiff.Variable();
    55         parameters.Add(data, param);
     55        variables.Add(data);
    5656      }
    5757
     
    5959        foreach (var stringValue in dataset.GetStringValues(stringVariable).Distinct()) {
    6060          var data = new DataForVariable(stringVariable, stringValue, 0);
    61           var param = new AutoDiff.Variable();
    62           parameters.Add(data, param);
     61          variables.Add(data);
    6362        }
    6463      }
    65       return parameters;
     64      return variables;
     65    }
     66
     67    public static List<DataForVariable> ExtractLaggedVariables(ISymbolicExpressionTree tree) {
     68      var variables = new HashSet<DataForVariable>();
     69      foreach (var laggedNode in tree.IterateNodesPrefix().OfType<ILaggedTreeNode>()) {
     70        var laggedVariableTreeNode = laggedNode as LaggedVariableTreeNode;
     71        if (laggedVariableTreeNode != null) {
     72          var data = new DataForVariable(laggedVariableTreeNode.VariableName, string.Empty, laggedVariableTreeNode.Lag);
     73          if (!variables.Contains(data)) variables.Add(data);
     74        }
     75      }
     76      return variables.ToList();
    6677    }
    6778
     
    7990          for (int j = 0; j < factorVarTreeNode.Weights.Length; j++)
    8091            constants.Add(factorVarTreeNode.Weights[j]);
    81         }        
     92        } else throw new NotSupportedException(string.Format("Terminal nodes of type {0} are not supported.", node.GetType().GetPrettyName()));
    8293      }
    8394      return constants.ToArray();
     
    97108          for (int j = 0; j < factorVarTreeNode.Weights.Length; j++)
    98109            factorVarTreeNode.Weights[j] = constants[i++];
    99         }
     110        } else throw new NotSupportedException(string.Format("Terminal nodes of type {0} are not supported.", node.GetType().GetPrettyName()));
    100111      }
    101112    }
Note: See TracChangeset for help on using the changeset viewer.