Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/09/11 10:45:50 (13 years ago)
Author:
gkronber
Message:

#1557 implemented parallel evaluation in analyzers using ParallelEnumerable extension methods.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisAlleleFrequencyAnalyzer.cs

    r6503 r6728  
    7070
    7171    protected override Allele[] CalculateAlleles(ISymbolicExpressionTree solution) {
    72       List<Allele> alleles = new List<Allele>();
    73 
    74       foreach (var subtree in GetAllSubtreesOfDepth(solution, AlleleTreeDepth)) {
    75         alleles.Add(GetAlleleFromSubtreeOfDepth(subtree, AlleleTreeDepth));
    76       }
    77       return alleles.ToArray();
     72      return GetAllSubtreesOfDepth(solution, AlleleTreeDepth)
     73        .AsParallel()
     74        .Select(t => GetAlleleFromSubtreeOfDepth(t, AlleleTreeDepth))
     75        .ToArray();
    7876    }
    7977
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveValidationBestSolutionAnalyzer.cs

    r5907 r6728  
    9393      IList<int> nonDominatedIndexes = new List<int>();
    9494      ISymbolicExpressionTree[] tree = SymbolicExpressionTree.ToArray();
    95       List<double[]> qualities = new List<double[]>();
    9695      bool[] maximization = Maximization.ToArray();
    9796      List<double[]> newNonDominatedQualities = new List<double[]>();
    9897      var evaluator = EvaluatorParameter.ActualValue;
     98      var problemData = ProblemDataParameter.ActualValue;
    9999      IExecutionContext childContext = (IExecutionContext)ExecutionContext.CreateChildOperation(evaluator);
     100
     101      var qualities = tree
     102        .AsParallel()
     103        .Select(t => evaluator.Evaluate(childContext, t, problemData, rows))
     104        .ToArray();
    100105      for (int i = 0; i < tree.Length; i++) {
    101         qualities.Add(evaluator.Evaluate(childContext, tree[i], ProblemDataParameter.ActualValue, rows)); // qualities[i] = ...
    102106        if (IsNonDominated(qualities[i], trainingBestQualities, maximization) &&
    103107          IsNonDominated(qualities[i], qualities, maximization)) {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationBestSolutionAnalyzer.cs

    r5907 r6728  
    7676      ISymbolicExpressionTree bestTree = null;
    7777      ISymbolicExpressionTree[] tree = SymbolicExpressionTree.ToArray();
    78       double[] quality = new double[tree.Length];
    7978      var evaluator = EvaluatorParameter.ActualValue;
     79      var problemData = ProblemDataParameter.ActualValue;
    8080      IEnumerable<int> rows = GenerateRowsToEvaluate();
    8181      if (!rows.Any()) return base.Apply();
    8282
    8383      IExecutionContext childContext = (IExecutionContext)ExecutionContext.CreateChildOperation(evaluator);
     84      var quality = tree
     85        .AsParallel()
     86        .Select(t => evaluator.Evaluate(childContext, t, problemData, rows))
     87        .ToArray();
     88
    8489      for (int i = 0; i < tree.Length; i++) {
    85         quality[i] = evaluator.Evaluate(childContext, tree[i], ProblemDataParameter.ActualValue, rows);
    8690        if (IsBetter(quality[i], bestQuality, Maximization.Value)) {
    8791          bestQuality = quality[i];
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisVariableFrequencyAnalyzer.cs

    r6709 r6728  
    131131
    132132    public static IEnumerable<KeyValuePair<string, double>> CalculateVariableFrequencies(IEnumerable<ISymbolicExpressionTree> trees, bool aggregateLaggedVariables = true) {
    133       Dictionary<string, double> variableFrequencies = new Dictionary<string, double>();
    134       int totalNumberOfSymbols = 0;
    135 
    136       foreach (var tree in trees) {
    137         var variableReferences = GetVariableReferences(tree, aggregateLaggedVariables);
    138         foreach (var pair in variableReferences) {
    139           totalNumberOfSymbols += pair.Value;
    140           if (variableFrequencies.ContainsKey(pair.Key)) {
    141             variableFrequencies[pair.Key] += pair.Value;
    142           } else {
    143             variableFrequencies.Add(pair.Key, pair.Value);
    144           }
    145         }
    146       }
     133
     134      var variableFrequencies = trees
     135        .AsParallel()
     136        .SelectMany(t => GetVariableReferences(t, aggregateLaggedVariables))
     137        .GroupBy(pair => pair.Key, pair => pair.Value)
     138        .ToDictionary(g => g.Key, g => (double)g.Sum());
     139
     140      double totalNumberOfSymbols = variableFrequencies.Values.Sum();
    147141
    148142      foreach (var pair in variableFrequencies)
Note: See TracChangeset for help on using the changeset viewer.