Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6728


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
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveOverfittingAnalyzer.cs

    r5907 r6728  
    7676    public override IOperation Apply() {
    7777      double[] trainingQuality = QualityParameter.ActualValue.Select(x => x.Value).ToArray();
     78      var problemData = ProblemDataParameter.ActualValue;
     79      var evaluator = EvaluatorParameter.ActualValue;
    7880      // evaluate on validation partition
    7981      IEnumerable<int> rows = GenerateRowsToEvaluate();
    8082      if (!rows.Any()) return base.Apply();
    81 
    82       IExecutionContext childContext = (IExecutionContext)ExecutionContext.CreateChildOperation(EvaluatorParameter.ActualValue);
    83       double[] validationQuality = (from tree in SymbolicExpressionTree
    84                                     select EvaluatorParameter.ActualValue.Evaluate(childContext, tree, ProblemDataParameter.ActualValue, rows))
    85                                    .ToArray();
     83      IExecutionContext childContext = (IExecutionContext)ExecutionContext.CreateChildOperation(evaluator);
     84      double[] validationQuality = SymbolicExpressionTree
     85        .AsParallel()
     86        .Select(t => evaluator.Evaluate(childContext, t, problemData, rows))
     87        .ToArray();
    8688      double r = 0.0;
    8789      try {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveOverfittingAnalyzer.cs

    r5907 r6728  
    7979
    8080      double[] trainingQuality = QualityParameter.ActualValue.Select(x => x.Value).ToArray();
     81      var problemData = ProblemDataParameter.ActualValue;
     82      var evaluator = EvaluatorParameter.ActualValue;
    8183      // evaluate on validation partition
    82       IExecutionContext childContext = (IExecutionContext)ExecutionContext.CreateChildOperation(EvaluatorParameter.ActualValue);
    83       double[] validationQuality = (from tree in SymbolicExpressionTree
    84                                     select EvaluatorParameter.ActualValue.Evaluate(childContext, tree, ProblemDataParameter.ActualValue, rows))
    85                                    .ToArray();
     84      IExecutionContext childContext = (IExecutionContext)ExecutionContext.CreateChildOperation(evaluator);
     85      double[] validationQuality = SymbolicExpressionTree
     86        .AsParallel()
     87        .Select(t => evaluator.Evaluate(childContext, t, problemData, rows))
     88        .ToArray();
    8689      double r = 0.0;
    8790      try {
  • 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.