Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2131 for trunk/sources


Ignore:
Timestamp:
07/03/09 15:56:05 (15 years ago)
Author:
gkronber
Message:

Implemented basic visualization of variable impacts in the CEDMA bubble chart. #286 (Variable-usage diagrams for the CEDMA frontend)

Location:
trunk/sources
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Charting/3.3/BubbleChart.cs

    r2047 r2131  
    3131using HeuristicLab.Core;
    3232using HeuristicLab.CEDMA.DB.Interfaces;
     33using System.Diagnostics;
    3334
    3435namespace HeuristicLab.CEDMA.Charting {
     
    5859    private Results results;
    5960    private Dictionary<IPrimitive, ResultsEntry> primitiveToEntryDictionary;
    60     private Dictionary<ResultsEntry, IPrimitive> entryToPrimitiveDictionary;
     61    //private Dictionary<ResultsEntry, IList<IPrimitive>> entryToPrimitivesDictionary;
    6162    private Random random = new Random();
    6263    private Group points;
     
    6667      records = new List<ResultsEntry>();
    6768      primitiveToEntryDictionary = new Dictionary<IPrimitive, ResultsEntry>();
    68       entryToPrimitiveDictionary = new Dictionary<ResultsEntry, IPrimitive>();
     69      // entryToPrimitivesDictionary = new Dictionary<ResultsEntry, IList<IPrimitive>>();
    6970      this.results = results;
    7071
     
    132133      Group.Clear();
    133134      primitiveToEntryDictionary.Clear();
    134       entryToPrimitiveDictionary.Clear();
     135      // entryToPrimitivesDictionary.Clear();
    135136      points = new Group(this);
    136137      Group.Add(new Axis(this, 0, 0, AxisType.Both));
    137138      UpdateViewSize(0, 0, 5);
    138139      foreach (ResultsEntry r in records) {
    139         double x, y;
     140        List<double> xs = new List<double>();
     141        List<double> ys = new List<double>();
    140142        int size;
    141143        if (results.OrdinalVariables.Contains(xDimension)) {
    142           x = Convert.ToDouble(r.Get(xDimension)) + (double)r.Get(X_JITTER) * xJitterFactor;
     144          xs.Add(Convert.ToDouble(r.Get(xDimension)) + (double)r.Get(X_JITTER) * xJitterFactor);
    143145        } else if (results.CategoricalVariables.Contains(xDimension)) {
    144           x = results.IndexOfCategoricalValue(xDimension, r.Get(xDimension)) + (double)r.Get(X_JITTER) * xJitterFactor;
     146          xs.Add(results.IndexOfCategoricalValue(xDimension, r.Get(xDimension)) + (double)r.Get(X_JITTER) * xJitterFactor);
     147        } else if (results.MultiDimensionalCategoricalVariables.Contains(xDimension)) {
     148          var path = xDimension.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim());
     149          IEnumerable<ResultsEntry> subEntries = (IEnumerable<ResultsEntry>)r.Get(path.ElementAt(0));
     150          foreach (ResultsEntry subEntry in subEntries) {
     151            xs.Add(results.IndexOfCategoricalValue(xDimension, subEntry.Get(path.ElementAt(1))) + (double)r.Get(X_JITTER) * xJitterFactor);
     152          }
     153        } else if (results.MultiDimensionalOrdinalVariables.Contains(xDimension)) {
     154          var path = xDimension.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim());
     155          IEnumerable<ResultsEntry> subEntries = (IEnumerable<ResultsEntry>)r.Get(path.ElementAt(0));
     156          foreach (ResultsEntry subEntry in subEntries) {
     157            xs.Add(Convert.ToDouble(subEntry.Get(path.ElementAt(1))) + (double)r.Get(X_JITTER) * xJitterFactor);
     158          }
    145159        } else {
    146           x = double.NaN;
     160          xs.Add(double.NaN);
    147161        }
    148162        if (results.OrdinalVariables.Contains(yDimension)) {
    149           y = Convert.ToDouble(r.Get(yDimension)) + (double)r.Get(Y_JITTER) * yJitterFactor;
     163          ys.Add(Convert.ToDouble(r.Get(yDimension)) + (double)r.Get(Y_JITTER) * yJitterFactor);
    150164        } else if (results.CategoricalVariables.Contains(yDimension)) {
    151           y = results.IndexOfCategoricalValue(yDimension, r.Get(yDimension)) + (double)r.Get(Y_JITTER) * yJitterFactor;
     165          ys.Add(results.IndexOfCategoricalValue(yDimension, r.Get(yDimension)) + (double)r.Get(Y_JITTER) * yJitterFactor);
     166        } else if (results.MultiDimensionalCategoricalVariables.Contains(yDimension)) {
     167          var path = yDimension.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim());
     168          IEnumerable<ResultsEntry> subEntries = (IEnumerable<ResultsEntry>)r.Get(path.ElementAt(0));
     169          foreach (ResultsEntry subEntry in subEntries) {
     170            ys.Add(results.IndexOfCategoricalValue(yDimension, subEntry.Get(path.ElementAt(1))) + (double)r.Get(Y_JITTER) * yJitterFactor);
     171          }
     172        } else if (results.MultiDimensionalOrdinalVariables.Contains(yDimension)) {
     173          var path = yDimension.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim());
     174          IEnumerable<ResultsEntry> subEntries = (IEnumerable<ResultsEntry>)r.Get(path.ElementAt(0));
     175          foreach (ResultsEntry subEntry in subEntries) {
     176            ys.Add(Convert.ToDouble(subEntry.Get(path.ElementAt(1))) + (double)r.Get(Y_JITTER) * yJitterFactor);
     177          }
    152178        } else {
    153           y = double.NaN;
     179          ys.Add(double.NaN);
    154180        }
    155181        size = CalculateSize(Convert.ToDouble(r.Get(sizeDimension)), minSize, maxSize);
    156 
    157         if (double.IsInfinity(x) || x == double.MaxValue || x == double.MinValue) x = double.NaN;
    158         if (double.IsInfinity(y) || y == double.MaxValue || y == double.MinValue) y = double.NaN;
    159         if (!double.IsNaN(x) && !double.IsNaN(y)) {
    160           UpdateViewSize(x, y, size);
    161           int alpha = CalculateAlpha(size);
    162           Pen pen = new Pen(Color.FromArgb(alpha, r.Selected ? selectionColor : defaultColor));
    163           Brush brush = pen.Brush;
    164           FixedSizeCircle c = new FixedSizeCircle(this, x, y, size, pen, brush);
    165           c.ToolTipText = r.GetToolTipText();
    166           points.Add(c);
    167           if (!r.Selected) c.IntoBackground();
    168           primitiveToEntryDictionary[c] = r;
    169           entryToPrimitiveDictionary[r] = c;
     182        Debug.Assert(xs.Count() == ys.Count() || xs.Count() == 1 || ys.Count() == 1);
     183        int n = Math.Max(xs.Count(), ys.Count());
     184        for (int i = 0; i < n; i++) {
     185          double x = xs[Math.Min(i, xs.Count()-1)];
     186          double y = ys[Math.Min(i, ys.Count()-1)];
     187          if (double.IsInfinity(x) || x == double.MaxValue || x == double.MinValue) x = double.NaN;
     188          if (double.IsInfinity(y) || y == double.MaxValue || y == double.MinValue) y = double.NaN;
     189          if (!double.IsNaN(x) && !double.IsNaN(y)) {
     190            UpdateViewSize(x, y, size);
     191            int alpha = CalculateAlpha(size);
     192            Pen pen = new Pen(Color.FromArgb(alpha, r.Selected ? selectionColor : defaultColor));
     193            Brush brush = pen.Brush;
     194            FixedSizeCircle c = new FixedSizeCircle(this, x, y, size, pen, brush);
     195            c.ToolTipText = r.GetToolTipText();
     196            points.Add(c);
     197            if (!r.Selected) c.IntoBackground();
     198            primitiveToEntryDictionary[c] = r;
     199            //if (!entryToPrimitivesDictionary.ContainsKey(r)) entryToPrimitivesDictionary[r] = new List<IPrimitive>();
     200            //entryToPrimitivesDictionary[r].Add(c);
     201          }
    170202        }
    171203      }
  • trunk/sources/HeuristicLab.CEDMA.Charting/3.3/BubbleChartView.cs

    r1529 r2131  
    4040      xAxisComboBox.Items.AddRange(Results.OrdinalVariables);
    4141      xAxisComboBox.Items.AddRange(Results.CategoricalVariables);
     42      xAxisComboBox.Items.AddRange(Results.MultiDimensionalCategoricalVariables);
     43      xAxisComboBox.Items.AddRange(Results.MultiDimensionalOrdinalVariables);
    4244      yAxisComboBox.Items.AddRange(Results.OrdinalVariables);
    4345      yAxisComboBox.Items.AddRange(Results.CategoricalVariables);
     46      yAxisComboBox.Items.AddRange(Results.MultiDimensionalCategoricalVariables);
     47      yAxisComboBox.Items.AddRange(Results.MultiDimensionalOrdinalVariables);
    4448      sizeComboBox.Items.Add(CONSTANT_SIZE);
    4549      sizeComboBox.Items.AddRange(Results.OrdinalVariables);
  • trunk/sources/HeuristicLab.CEDMA.Core/3.3/DataSetView.cs

    r2000 r2131  
    6060      if (dataSet.Activated) {
    6161        activateButton.Enabled = false;
    62         editorGroupBox.Enabled = false;
     62        editorGroupBox.Enabled = true;
    6363        viewComboBox.Enabled = true;
    6464        resultsButton.Enabled = true;
  • trunk/sources/HeuristicLab.CEDMA.Core/3.3/Results.cs

    r2081 r2131  
    5858    }
    5959
     60    private string[] multiDimensionalOrdinalVariables = new string[] { "VariableImpacts: EvaluationImpact", "VariableImpacts: QualityImpact" };
     61    public string[] MultiDimensionalOrdinalVariables {
     62      get { return multiDimensionalOrdinalVariables; }
     63    }
     64
     65    private string[] multiDimensionalCategoricalVariables = new string[] { "VariableImpacts: InputVariableName" };
     66    public string[] MultiDimensionalCategoricalVariables {
     67      get { return multiDimensionalCategoricalVariables; }
     68    }
     69
    6070    private IStore store;
    6171    public IStore Store {
     
    8797      entries = new List<ResultsEntry>();
    8898      do {
    89         var allBindings = store.Query("?Model <" + Ontology.InstanceOf + "> <" + Ontology.TypeModel + "> ." + Environment.NewLine +
    90           "?Model ?Attribute ?Value .", page, PAGE_SIZE);
     99        var allBindings = store.Query(
     100          "?Model <" + Ontology.InstanceOf + "> <" + Ontology.TypeModel + "> ." +
     101          "?Model ?Attribute ?Value .",
     102          page, PAGE_SIZE);
    91103        var allModelBindings = allBindings.GroupBy(x => (Entity)x.Get("Model"));
    92104        resultsReturned = allBindings.Count;
     
    100112            entries.Add(entry);
    101113            newEntry = true;
     114            entry.Set("VariableImpacts", SelectVariableImpacts(entry.Uri));
    102115          }
    103116          foreach (var binding in modelBindings) {
     
    117130      FireChanged();
    118131      cached = true;
     132    }
     133
     134    private IEnumerable<ResultsEntry> SelectVariableImpacts(string modelUri) {
     135      var allBindings = store.Query(
     136          "<" + modelUri + "> <" + Ontology.HasInputVariable + "> ?InputVariable ." +
     137          "?InputVariable <" + Ontology.Name + "> ?InputName ." +
     138          "?InputVariable <" + Ontology.QualityImpact + "> ?QualityImpact ." +
     139          "?InputVariable <" + Ontology.EvaluationImpact + "> ?EvaluationImpact .",
     140          0, PAGE_SIZE);
     141      var allInputVariableBindings = allBindings.GroupBy(x => (Entity)x.Get("InputVariable"));
     142      List<ResultsEntry> variableImpacts = new List<ResultsEntry>();
     143
     144      foreach (var inputVariableBinding in allInputVariableBindings) {
     145        ResultsEntry entry = new ResultsEntry();
     146        VariableBindings binding = inputVariableBinding.First();
     147        double evaluationImpact = (double)((Literal)binding.Get("EvaluationImpact")).Value;
     148        double qualityImpact = (double)((Literal)binding.Get("QualityImpact")).Value;
     149        if (binding.Get("InputName") != null) entry.Set("InputVariableName", ((Literal)binding.Get("InputName")).Value);
     150        if (binding.Get("QualityImpact") != null) entry.Set("QualityImpact", qualityImpact);
     151        if (binding.Get("EvaluationImpact") != null) entry.Set("EvaluationImpact", evaluationImpact);
     152        if (!IsAlmost(evaluationImpact, 0.0) && !IsAlmost(qualityImpact, 1.0)) {
     153          variableImpacts.Add(entry);
     154        }
     155      }
     156      return variableImpacts;
     157    }
     158
     159    private bool IsAlmost(double x, double y) {
     160      return (y + 1.0E-7 > x) && (y - 1.0E-7 < x);
    119161    }
    120162
Note: See TracChangeset for help on using the changeset viewer.