public ScatterPlot CreateScatterPlot(string variableNameX, string variableNameY, string variableNameColor = "-") {
      ScatterPlot scatterPlot = new ScatterPlot();

      IList<double> xValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameX));
      IList<double> yValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameY));
      if (variableNameColor == null || variableNameColor == "-") {
        List<Point2D<double>> points = new List<Point2D<double>>();

        for (int i = 0; i < xValues.Count; i++) {
          Point2D<double> point = new Point2D<double>(xValues[i], yValues[i]);
          points.Add(point);
        }

        ScatterPlotDataRow scdr = new ScatterPlotDataRow(variableNameX + " - " + variableNameY, "", points);
        scatterPlot.Rows.Add(scdr);

      } else {
        var colorValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameColor));
        var data = xValues.Zip(yValues, (x, y) => new { x, y }).Zip(colorValues, (v, c) => new { v.x, v.y, c }).ToList();
        var gradients = ColorGradient.Colors;
        int curGradient = 0;
        int numColors = colorValues.Distinct().Count();
        foreach (var colorValue in colorValues.Distinct()) {
          var values = data.Where(x => x.c == colorValue);
          var row = new ScatterPlotDataRow(
            variableNameX + " - " + variableNameY + " (" + colorValue + ")",
            "",
            values.Select(v => new Point2D<double>(v.x, v.y)),
            new ScatterPlotDataRowVisualProperties() { Color = gradients[curGradient] });
          curGradient += gradients.Count / numColors;
          scatterPlot.Rows.Add(row);
        }
      }
      return scatterPlot;
    }
 protected virtual void DeregisterScatterPlotDataRowEvents(ScatterPlotDataRow row) {
   row.Points.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsAdded);
   row.Points.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsRemoved);
   row.Points.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsReplaced);
   row.Points.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_CollectionReset);
   pointsRowsTable.Remove(row.Points);
   row.VisualPropertiesChanged -= new EventHandler(Row_VisualPropertiesChanged);
   row.NameChanged -= new EventHandler(Row_NameChanged);
 }
    public ScatterPlot CreateScatterPlot(string variableNameX, string variableNameY) {
      ScatterPlot scatterPlot = new ScatterPlot();

      IList<double> xValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameX));
      IList<double> yValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameY));

      List<Point2D<double>> points = new List<Point2D<double>>();

      for (int i = 0; i < xValues.Count; i++) {
        Point2D<double> point = new Point2D<double>(xValues[i], yValues[i]);
        points.Add(point);
      }

      ScatterPlotDataRow scdr = new ScatterPlotDataRow(variableNameX + " - " + variableNameY, "", points);
      scatterPlot.Rows.Add(scdr);
      return scatterPlot;
    }
 protected ScatterPlotDataRow(ScatterPlotDataRow original, Cloner cloner)
     : base(original, cloner)
 {
     VisualProperties = cloner.Clone(original.visualProperties);
     points           = new ObservableList <Point2D <double> >(original.points);
 }
 protected ScatterPlotDataRow(ScatterPlotDataRow original, Cloner cloner)
   : base(original, cloner) {
   VisualProperties = cloner.Clone(original.visualProperties);
   points = new ObservableList<Point2D<double>>(original.points);
 }
        public override IOperation Apply()
        {
            int      updateInterval = UpdateIntervalParameter.Value.Value;
            IntValue updateCounter  = UpdateCounterParameter.ActualValue;

            if (updateCounter == null)
            {
                updateCounter = new IntValue(updateInterval);
                UpdateCounterParameter.ActualValue = updateCounter;
            }
            else
            {
                updateCounter.Value++;
            }

            if (updateCounter.Value == updateInterval)
            {
                updateCounter.Value = 0;

                bool          max               = MaximizationParameter.ActualValue.Value;
                ItemArray <T> solutions         = SolutionParameter.ActualValue;
                double[]      qualities         = QualityParameter.ActualValue.Select(x => x.Value).ToArray();
                T             bestKnownSolution = BestKnownSolutionParameter.ActualValue;
                bool          storeHistory      = StoreHistoryParameter.Value.Value;

                // calculate index of current best solution
                int bestIndex = -1;
                if (!max)
                {
                    bestIndex = qualities
                                .Select((x, i) => new { Index = i, Value = x })
                                .OrderBy(x => x.Value)
                                .First().Index;
                }
                else
                {
                    bestIndex = qualities
                                .Select((x, i) => new { Index = i, Value = x })
                                .OrderByDescending(x => x.Value)
                                .First().Index;
                }

                // calculate allels of current best and (if available) best known solution
                Allele[] bestAlleles      = CalculateAlleles(solutions[bestIndex]);
                Allele[] bestKnownAlleles = null;
                if (bestKnownSolution != null)
                {
                    bestKnownAlleles = CalculateAlleles(bestKnownSolution);
                }

                // calculate allele frequencies
                var frequencies = solutions.SelectMany((s, index) => CalculateAlleles(s).Select(a => new { Allele = a, Quality = qualities[index] })).
                                  GroupBy(x => x.Allele.Id).
                                  Select(x => new AlleleFrequency(x.Key,
                                                                  x.Count() / ((double)solutions.Length),
                                                                  x.Average(a => a.Allele.Impact),
                                                                  x.Average(a => a.Quality),
                                                                  bestKnownAlleles == null ? false : bestKnownAlleles.Any(a => a.Id == x.Key),
                                                                  bestAlleles.Any(a => a.Id == x.Key)));

                // calculate dummy allele frequencies of alleles of best known solution which did not occur
                if (bestKnownAlleles != null)
                {
                    var bestKnownFrequencies = bestKnownAlleles.Select(x => new AlleleFrequency(x.Id, 0, x.Impact, 0, true, false)).Except(frequencies, new AlleleFrequencyIdEqualityComparer());
                    frequencies = frequencies.Concat(bestKnownFrequencies);
                }

                // fetch results collection
                ResultCollection results;
                if (!ResultsParameter.ActualValue.ContainsKey(Name + " Results"))
                {
                    results = new ResultCollection();
                    ResultsParameter.ActualValue.Add(new Result(Name + " Results", results));
                }
                else
                {
                    results = (ResultCollection)ResultsParameter.ActualValue[Name + " Results"].Value;
                }

                // store allele frequencies
                AlleleFrequencyCollection frequenciesCollection = new AlleleFrequencyCollection(frequencies);
                if (!results.ContainsKey("Allele Frequencies"))
                {
                    results.Add(new Result("Allele Frequencies", frequenciesCollection));
                }
                else
                {
                    results["Allele Frequencies"].Value = frequenciesCollection;
                }

                // store allele frequencies history
                if (storeHistory)
                {
                    if (!results.ContainsKey("Allele Frequencies History"))
                    {
                        AlleleFrequencyCollectionHistory history = new AlleleFrequencyCollectionHistory();
                        history.Add(frequenciesCollection);
                        results.Add(new Result("Allele Frequencies History", history));
                    }
                    else
                    {
                        ((AlleleFrequencyCollectionHistory)results["Allele Frequencies History"].Value).Add(frequenciesCollection);
                    }
                }

                // store alleles data table
                DataTable allelesTable;
                if (!results.ContainsKey("Alleles"))
                {
                    allelesTable = new DataTable("Alleles");
                    allelesTable.VisualProperties.XAxisTitle       = "Iteration";
                    allelesTable.VisualProperties.YAxisTitle       = "Number of Alleles";
                    allelesTable.VisualProperties.SecondYAxisTitle = "Number of Alleles";

                    allelesTable.Rows.Add(new DataRow("Unique Alleles"));
                    allelesTable.Rows["Unique Alleles"].VisualProperties.StartIndexZero = true;

                    allelesTable.Rows.Add(new DataRow("Unique Alleles of Best Known Solution", null));
                    allelesTable.Rows["Unique Alleles of Best Known Solution"].VisualProperties.SecondYAxis    = true;
                    allelesTable.Rows["Unique Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;

                    allelesTable.Rows.Add(new DataRow("Fixed Alleles", null));
                    allelesTable.Rows["Fixed Alleles"].VisualProperties.SecondYAxis    = true;
                    allelesTable.Rows["Fixed Alleles"].VisualProperties.StartIndexZero = true;

                    allelesTable.Rows.Add(new DataRow("Fixed Alleles of Best Known Solution", null));
                    allelesTable.Rows["Fixed Alleles of Best Known Solution"].VisualProperties.SecondYAxis    = true;
                    allelesTable.Rows["Fixed Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;

                    allelesTable.Rows.Add(new DataRow("Lost Alleles of Best Known Solution", null));
                    allelesTable.Rows["Lost Alleles of Best Known Solution"].VisualProperties.SecondYAxis    = true;
                    allelesTable.Rows["Lost Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;

                    results.Add(new Result("Alleles", allelesTable));
                }
                else
                {
                    allelesTable = (DataTable)results["Alleles"].Value;
                }

                int fixedAllelesCount          = frequenciesCollection.Where(x => x.Frequency == 1).Count();
                var relevantAlleles            = frequenciesCollection.Where(x => x.ContainedInBestKnownSolution);
                int relevantAllelesCount       = relevantAlleles.Count();
                int fixedRelevantAllelesCount  = relevantAlleles.Where(x => x.Frequency == 1).Count();
                int lostRelevantAllelesCount   = relevantAlleles.Where(x => x.Frequency == 0).Count();
                int uniqueRelevantAllelesCount = relevantAllelesCount - lostRelevantAllelesCount;
                allelesTable.Rows["Unique Alleles"].Values.Add(frequenciesCollection.Count);
                allelesTable.Rows["Unique Alleles of Best Known Solution"].Values.Add(uniqueRelevantAllelesCount);
                allelesTable.Rows["Fixed Alleles"].Values.Add(fixedAllelesCount);
                allelesTable.Rows["Fixed Alleles of Best Known Solution"].Values.Add(fixedRelevantAllelesCount);
                allelesTable.Rows["Lost Alleles of Best Known Solution"].Values.Add(lostRelevantAllelesCount);

                // store alleles values
                if (!results.ContainsKey("Unique Alleles"))
                {
                    results.Add(new Result("Unique Alleles", new DoubleValue(frequenciesCollection.Count)));
                }
                else
                {
                    ((DoubleValue)results["Unique Alleles"].Value).Value = frequenciesCollection.Count;
                }

                if (!results.ContainsKey("Unique Alleles of Best Known Solution"))
                {
                    results.Add(new Result("Unique Alleles of Best Known Solution", new DoubleValue(uniqueRelevantAllelesCount)));
                }
                else
                {
                    ((DoubleValue)results["Unique Alleles of Best Known Solution"].Value).Value = uniqueRelevantAllelesCount;
                }

                if (!results.ContainsKey("Fixed Alleles"))
                {
                    results.Add(new Result("Fixed Alleles", new DoubleValue(fixedAllelesCount)));
                }
                else
                {
                    ((DoubleValue)results["Fixed Alleles"].Value).Value = fixedAllelesCount;
                }

                if (!results.ContainsKey("Fixed Alleles of Best Known Solution"))
                {
                    results.Add(new Result("Fixed Alleles of Best Known Solution", new DoubleValue(fixedRelevantAllelesCount)));
                }
                else
                {
                    ((DoubleValue)results["Fixed Alleles of Best Known Solution"].Value).Value = fixedRelevantAllelesCount;
                }

                if (!results.ContainsKey("Lost Alleles of Best Known Solution"))
                {
                    results.Add(new Result("Lost Alleles of Best Known Solution", new DoubleValue(lostRelevantAllelesCount)));
                }
                else
                {
                    ((DoubleValue)results["Lost Alleles of Best Known Solution"].Value).Value = lostRelevantAllelesCount;
                }

                // calculate contained alleles of best known solution and relative quality
                if (bestKnownAlleles != null)
                {
                    double qualityRange = Math.Abs(qualities.Max() - qualities.Min());
                    var    points       = solutions.Select((s, index) => new Point2D <double>(CalculateAlleles(s).Intersect(bestKnownAlleles, new AlleleIdEqualityComparer()).Count(),
                                                                                              Math.Abs(qualities[index] - qualities[bestIndex]) / qualityRange));
                    var avgContainedReleventAlleles = points.Select(x => x.X).Average();

                    var plot = new ScatterPlot("Contained Alleles of Best Known Solution and Relative Solution Qualtiy", null);
                    plot.VisualProperties.XAxisTitle             = "Contained Alleles of Best Known Solution";
                    plot.VisualProperties.YAxisTitle             = "Relative Solution Quality";
                    plot.VisualProperties.XAxisMinimumAuto       = false;
                    plot.VisualProperties.XAxisMinimumFixedValue = 0.0;
                    plot.VisualProperties.XAxisMaximumAuto       = false;
                    plot.VisualProperties.XAxisMaximumFixedValue = bestKnownAlleles.Length;
                    plot.VisualProperties.YAxisMinimumAuto       = false;
                    plot.VisualProperties.YAxisMinimumFixedValue = 0.0;
                    plot.VisualProperties.YAxisMaximumAuto       = false;
                    plot.VisualProperties.YAxisMaximumFixedValue = 1.0;
                    var row = new ScatterPlotDataRow("Solutions of Current Generation", null, points);
                    row.VisualProperties.PointStyle = ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Circle;
                    row.VisualProperties.PointSize  = 5;
                    plot.Rows.Add(row);

                    if (!results.ContainsKey("Scatter Plot"))
                    {
                        results.Add(new Result("Scatter Plot", plot));
                    }
                    else
                    {
                        results["Scatter Plot"].Value = plot;
                    }
                    if (storeHistory)
                    {
                        if (!results.ContainsKey("Scatter Plot History"))
                        {
                            results.Add(new Result("Scatter Plot History", new ScatterPlotHistory()));
                        }
                        ((ScatterPlotHistory)results["Scatter Plot History"].Value).Add(plot);
                    }

                    if (!allelesTable.Rows.ContainsKey("Average Contained Alleles of Best Known Solution"))
                    {
                        allelesTable.Rows.Add(new DataRow("Average Contained Alleles of Best Known Solution", null));
                        allelesTable.Rows["Average Contained Alleles of Best Known Solution"].VisualProperties.SecondYAxis    = true;
                        allelesTable.Rows["Average Contained Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;
                    }
                    allelesTable.Rows["Average Contained Alleles of Best Known Solution"].Values.Add(avgContainedReleventAlleles);

                    if (!results.ContainsKey("Average Contained Alleles of Best Known Solution"))
                    {
                        results.Add(new Result("Average Contained Alleles of Best Known Solution", new DoubleValue(avgContainedReleventAlleles)));
                    }
                    else
                    {
                        ((DoubleValue)results["Average Contained Alleles of Best Known Solution"].Value).Value = avgContainedReleventAlleles;
                    }
                }
            }
            return(base.Apply());
        }
 private void FillSeriesWithRowValues(Series series, ScatterPlotDataRow row) {
   for (int i = 0; i < row.Points.Count; i++) {
     var value = row.Points[i];
     DataPoint point = new DataPoint();
     if (IsInvalidValue(value.X) || IsInvalidValue(value.Y))
       point.IsEmpty = true;
     else {
       point.XValue = value.X;
       point.YValues = new double[] { value.Y };
     }
     series.Points.Add(point);
   }
 }
    private void ConfigureSeries(Series series, ScatterPlotDataRow row) {
      series.BorderWidth = 1;
      series.BorderDashStyle = ChartDashStyle.Solid;
      series.BorderColor = Color.Empty;

      if (row.VisualProperties.Color != Color.Empty)
        series.Color = row.VisualProperties.Color;
      else series.Color = Color.Empty;
      series.IsVisibleInLegend = row.VisualProperties.IsVisibleInLegend;
      series.ChartType = SeriesChartType.FastPoint;
      series.MarkerSize = row.VisualProperties.PointSize;
      series.MarkerStyle = ConvertPointStyle(row.VisualProperties.PointStyle);
      series.XAxisType = AxisType.Primary;
      series.YAxisType = AxisType.Primary;

      if (row.VisualProperties.DisplayName.Trim() != String.Empty) series.LegendText = row.VisualProperties.DisplayName;
      else series.LegendText = row.Name;

      string xAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.XAxisTitle)
                      ? "X"
                      : Content.VisualProperties.XAxisTitle;
      string yAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.YAxisTitle)
                            ? "Y"
                            : Content.VisualProperties.YAxisTitle;
      series.ToolTip =
        series.LegendText + Environment.NewLine +
        xAxisTitle + " = " + "#VALX," + Environment.NewLine +
        yAxisTitle + " = " + "#VAL";
    }
Exemple #9
0
 protected virtual void DeregisterRowEvents(ScatterPlotDataRow row) {
   row.Points.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsAdded);
   row.Points.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsMoved);
   row.Points.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsRemoved);
   row.Points.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsReplaced);
   row.Points.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_CollectionReset);
 }