Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12283


Ignore:
Timestamp:
04/02/15 16:35:59 (10 years ago)
Author:
bburlacu
Message:

#1772: Updated genealogy graph view and worked on subtree sample count.

Location:
branches/HeuristicLab.EvolutionTracking
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymbolicDataAnalysisGenealogyGraphView.cs

    r12265 r12283  
    8484      nodeWeightLabel.Text = String.Format("{0:0.00}", graphNode.Weight);
    8585
     86      int colorCount = ColorGradient.Colors.Count - 1;
     87      const int alpha = 100;
     88      // calculate max only in the current generation
     89      var nodes = graphNode.Data.IterateNodesPrefix().Skip(1).ToList();
     90      var max = Content.GetByRank(graphNode.Rank).Max(x => ((IGenealogyGraphNode<ISymbolicExpressionTree>)x).Data.IterateNodesPrefix().Max(n => n.NodeWeight));
     91      if (max.IsAlmost(0)) max = 1;
     92      foreach (var n in nodes) {
     93        var visualSymbolicExpressionTreeNode = SymbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNode(n);
     94        visualSymbolicExpressionTreeNode.ToolTip += Environment.NewLine + String.Format("Weight: {0:0}", n.NodeWeight);
     95        var i = (int)Math.Round(n.NodeWeight / max * colorCount);
     96        var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]);
     97        treeChart_HighlightSubtree(n, null, fillColor);
     98      }
     99
    86100      if (!graphNode.InArcs.Any()) return;
    87101
     
    101115      var fragment = data as IFragment<ISymbolicExpressionTreeNode>;
    102116      var td = data as TraceData;
    103       // calculate max only in the current generation
    104       var max = Content.GetByRank(graphNode.Rank).Max(x => ((IGenealogyGraphNode<ISymbolicExpressionTree>)x).Data.IterateNodesPrefix().Max(y => y.NodeWeight));
    105       //      var max = Content.GetByRank(graphNode.Rank).Max(x => x.Weight);
    106 
    107       if (max.IsAlmost(0))
    108         max = 1;
    109 
    110       int colorCount = ColorGradient.Colors.Count - 1;
    111       const int alpha = 100;
     117
    112118      if (fragment != null) {
    113119        // highlight the fragment with a blue line color
     
    115121          treeChart_HighlightSubtree(n, Color.CornflowerBlue);
    116122        }
    117         // highlight all the nodes according to their sample count
    118         var nodes = graphNode.Data.IterateNodesPrefix().ToList();
    119         foreach (var n in nodes.Skip(1)) {
    120           var i = (int)Math.Round(n.NodeWeight / max * colorCount);
    121           var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]);
    122           treeChart_HighlightSubtree(n, null, fillColor);
    123         }
    124123      } else if (td != null) {
    125         var nodes = graphNode.Data.IterateNodesPrefix().ToList();
    126         foreach (var n in nodes.Skip(1)) { // skip program root symbol
    127           var i = (int)Math.Round(n.NodeWeight / max * colorCount);
    128           var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]);
    129           treeChart_HighlightSubtree(n, null, fillColor);
    130         }
     124        // highlight traced subtree and fragment
    131125        treeChart_HighlightSubtree(nodes[td.LastSubtreeIndex], Color.Orange);
    132126        treeChart_HighlightSubtree(nodes[td.LastFragmentIndex], Color.CornflowerBlue);
     
    141135      // check whether we are in 'trace' or 'match' mode
    142136      if (trace) {
    143         // TODO: maybe highlight based on per generation maximum
    144         //        double max = Content.Vertices.Max(x => x.Data.IterateNodesPrefix().Average(y => y.NodeWeight));
    145137        // perform fragment tracing
    146138        var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode;
    147         var max = Content.GetByRank(graphNode.Rank).Max(x => x.Weight);
    148139        var subtreeIndex = graphNode.Data.IterateNodesPrefix().ToList().IndexOf(node);
    149140        var traceGraph = TraceCalculator.TraceSubtree(graphNode, subtreeIndex, updateVertexWeights: false, updateSubtreeWeights: false, cacheTraceNodes: true);
     141        genealogyGraphChart.UpdateEnabled = false;
     142        genealogyGraphChart.ClearPrimitives(); // clear everything
     143        var rankMaximums = new Dictionary<double, double>();
     144        // fill each vertex in the graph with a grayscale color according to average subtree weight
     145        foreach (var r in Content.Ranks) {
     146          var vertices = r.Value.Cast<IGenealogyGraphNode<ISymbolicExpressionTree>>().ToList();
     147          var averages = vertices.Select(x => x.Data.IterateNodesPrefix().Average(n => n.NodeWeight)).ToList();
     148          var max = averages.Max();
     149          rankMaximums.Add(r.Key, max);
     150          if (max.IsAlmost(0.0)) continue;
     151          int colorCount = ColorGradient.GrayscaledColors.Count - 1;
     152          for (int i = 0; i < vertices.Count; ++i) {
     153            var color = ColorGradient.GrayscaledColors[(int)Math.Round(averages[i] / max * colorCount)];
     154            var vNode = genealogyGraphChart.GetMappedNode(vertices[i]);
     155            vNode.Brush = new SolidBrush(color);
     156          }
     157        }
     158        // fill vertices that are part of the trace with a rgb color according to average subtree weight
    150159        if (traceGraph.Vertices.Any()) {
    151           var vertices = traceGraph.Vertices.Select(x => Content.GetByContent(x.Data));
    152           genealogyGraphChart.UpdateEnabled = false;
    153           genealogyGraphChart.ClearPrimitives();
    154           foreach (var v in vertices) {
    155             var vNode = genealogyGraphChart.GetMappedNode(v);
    156             var wSum = v.Data.IterateNodesPrefix().Average(x => x.NodeWeight);
    157             // use a grayscale gradient
    158             var color = ColorGradient.GrayscaledColors[(int)Math.Round(wSum / max * (ColorGradient.GrayscaledColors.Count - 1))];
    159             vNode.Brush = new SolidBrush(color);
    160           }
    161           genealogyGraphChart.UpdateEnabled = true;
    162           genealogyGraphChart.EnforceUpdate();
     160          var ranks = traceGraph.Vertices.Select(x => Content.GetByContent(x.Data)).GroupBy(x => x.Rank);
     161          int colorCount = ColorGradient.Colors.Count - 1;
     162          foreach (var g in ranks) {
     163            var vertices = g.ToList();
     164            var averages = vertices.Select(x => x.Data.IterateNodesPrefix().Average(n => n.NodeWeight)).ToList();
     165            double max = rankMaximums[g.Key];
     166            if (max.IsAlmost(0.0)) continue;
     167            for (int i = 0; i < vertices.Count; ++i) {
     168              var vNode = genealogyGraphChart.GetMappedNode(vertices[i]);
     169              // use a grayscale gradient
     170              var color = ColorGradient.Colors[(int)Math.Round(averages[i] / max * colorCount)];
     171              vNode.Brush = new SolidBrush(color);
     172            }
     173          }
    163174
    164175          if (openNew_CheckBox.Checked) {
     
    166177          }
    167178        }
     179        genealogyGraphChart.UpdateEnabled = true;
     180        genealogyGraphChart.EnforceUpdate();
    168181      } else {
    169182        // perform matching like it was done before
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/BuildingBlockAnalyzers/SymbolicDataAnalysisPoly10Analyzer.cs

    r11493 r12283  
    4545    private const string BuildingBlocksFrequenciesTableName = "Building blocks frequencies";
    4646
    47 
    4847    // store evaluations of building blocks for phenotypic matching
    4948    private readonly Dictionary<string, List<double>> evaluationMap = new Dictionary<string, List<double>>();
     
    141140      var dataset = ProblemDataParameter.ActualValue.Dataset;
    142141      var rows = ProblemDataParameter.ActualValue.TrainingIndices.ToList();
    143       OnlineCalculatorError error;
    144       Dictionary<string, int> bbFrequencies = evaluationMap.Keys.ToDictionary(x => x, x => 0);
     142      var bbFrequencies = evaluationMap.Keys.ToDictionary(x => x, x => 0);
    145143
    146144      foreach (var key in evaluationMap.Keys) {
     
    154152            var s = nodes[i];
    155153            var values = interpreter.GetValues(s, dataset, rows);
     154            OnlineCalculatorError error;
    156155            var r2 = OnlinePearsonsRSquaredCalculator.Calculate(values, evaluationMap[key], out error);
    157156            if (error == OnlineCalculatorError.None && r2 >= PhenotypicSimilarityThreshold) {
     
    163162      }
    164163      var table = (DataTable)results[BuildingBlocksFrequenciesTableName].Value;
     164      double max = bbFrequencies.Max(x => x.Value);
    165165      foreach (var pair in bbFrequencies) {
     166        var formatter = new SymbolicExpressionTreeStringFormatter();
     167        //        var label = formatter.Format(fragmentMap[pair.Key]) + "(" + prettyLabels[pair.Key] + ")";
    166168        var label = prettyLabels[pair.Key];
    167         table.Rows[label].Values.Add(pair.Value);
     169        if (table.Rows.ContainsKey(label)) {
     170          var row = table.Rows[label];
     171          // scale previous values according to the new max
     172          //          if (row.Values.Count > 0) {
     173          //            var values = new List<double>(row.Values);
     174          //            var m = values.Max();
     175          //            row.Values.Replace(values.Select(x => x * m / max));
     176          //          }
     177          row.Values.Add(max > 0 ? pair.Value / max : 0);
     178        }
    168179      }
    169180
     
    227238      table.Rows.Clear();
    228239      foreach (var key in evaluationMap.Keys) {
    229         table.Rows.Add(new DataRow(prettyLabels[key]));
     240        table.Rows.Add(new DataRow(prettyLabels[key]) { VisualProperties = { StartIndexZero = true } });
    230241      }
    231242    }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/Analyzers/SymbolicDataAnalysisSubtreeSampleCountAnalyzer.cs

    r12265 r12283  
    104104          g.Weight = v.Weight;
    105105        }
     106
     107        // analyze subtree frequencies
     108        foreach (var v in PopulationGraph.GetByRank(Generation.Value)) {
     109          var g = (IGenealogyGraphNode<ISymbolicExpressionTree>)v;
     110          var t = g.Data;
     111
     112
     113        }
    106114      }
     115
    107116      return base.Apply();
    108117    }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs

    r12265 r12283  
    249249        arc = new GenealogyGraphArc(current, last) { Data = td };
    250250        TraceGraph.AddArc(arc);
    251       } else {
    252         if (UpdateVertexWeights) {
    253           arc.Weight++;
    254           current.Weight++;
    255         }
    256         if (UpdateSubtreeWeights) {
    257           var subtree = NodeAt(current.Data, td.SubtreeIndex);
    258           foreach (var s in subtree.IterateNodesPrefix())
    259             s.NodeWeight++;
    260         }
     251      }
     252      if (UpdateVertexWeights) {
     253        arc.Weight++;
     254        current.Weight++;
     255      }
     256      if (UpdateSubtreeWeights) {
     257        var subtree = NodeAt(current.Data, td.SubtreeIndex);
     258        foreach (var s in subtree.IterateNodesPrefix())
     259          s.NodeWeight++;
    261260      }
    262261    }
Note: See TracChangeset for help on using the changeset viewer.