private void AddAverageTableEntry(IntValue[] values, string tableName) {
      if (!ResultCollection.ContainsKey(tableName)) {
        var newTable = new DataTable(tableName, "");
        newTable.VisualProperties.YAxisTitle = "Average";
        newTable.VisualProperties.YAxisMaximumAuto = false;

        DataRow row = new DataRow("Average");
        row.VisualProperties.StartIndexZero = true;
        newTable.Rows.Add(row);

        ResultCollection.Add(new Result(tableName, newTable));
      }
      var table = ((DataTable)ResultCollection[tableName].Value);
      table.Rows["Average"].Values.Add(values.Select(x => x.Value).Average());
    }
    public override IOperation Apply() {
      ItemArray<ISymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue;
      ResultCollection results = ResultsParameter.ActualValue;
      DataTable symbolFrequencies = SymbolFrequenciesParameter.ActualValue;
      if (symbolFrequencies == null) {
        symbolFrequencies = new DataTable("Symbol frequencies", "Relative frequency of symbols aggregated over the whole population.");
        symbolFrequencies.VisualProperties.YAxisTitle = "Relative Symbol Frequency";

        SymbolFrequenciesParameter.ActualValue = symbolFrequencies;
        results.Add(new Result("Symbol frequencies", symbolFrequencies));
      }

      // all rows must have the same number of values so we can just take the first
      int numberOfValues = symbolFrequencies.Rows.Select(r => r.Values.Count).DefaultIfEmpty().First();

      foreach (var pair in SymbolicExpressionSymbolFrequencyAnalyzer.CalculateSymbolFrequencies(expressions, AggregrateSymbolsWithDifferentSubtreeCount.Value)) {
        if (!symbolFrequencies.Rows.ContainsKey(pair.Key)) {
          // initialize a new row for the symbol and pad with zeros
          DataRow row = new DataRow(pair.Key, "", Enumerable.Repeat(0.0, numberOfValues));
          row.VisualProperties.StartIndexZero = true;
          symbolFrequencies.Rows.Add(row);
        }
        symbolFrequencies.Rows[pair.Key].Values.Add(Math.Round(pair.Value, 3));
      }

      // add a zero for each data row that was not modified in the previous loop 
      foreach (var row in symbolFrequencies.Rows.Where(r => r.Values.Count != numberOfValues + 1))
        row.Values.Add(0.0);

      return base.Apply();
    }
예제 #3
0
    public override IOperation Apply() {
      ItemArray<BoolArray> cases = CasesParameter.ActualValue;
      ItemArray<DoubleArray> caseQualities = CaseQualitiesParameter.ActualValue;
      int length = cases.First().Length;
      if (cases.Any(x => x.Length != length) || caseQualities.Any(x => x.Length != length)) {
        throw new ArgumentException("Every individual has to have the same number of cases.");
      }

      double count = cases.Count();
      int rows = cases.First().Length;
      ResultCollection results = ResultsParameter.ActualValue;
      DataTable casesSolvedFrequencies = CasesSolvedFrequenciesParameter.ActualValue;
      DataTable summedCaseQualities = SummedCaseQualitiesParameter.ActualValue;
      if (casesSolvedFrequencies == null || summedCaseQualities == null) {
        casesSolvedFrequencies = new DataTable("Cases solved", "Absolute frequency of cases solved aggregated over the whole population.");
        casesSolvedFrequencies.VisualProperties.YAxisTitle = "Absolute Cases Solved Frequency";
        summedCaseQualities = new DataTable("Summed case qualities", "Absolute frequency of cases solved aggregated over the whole population.");
        summedCaseQualities.VisualProperties.YAxisTitle = "Summed Cases Qualities";


        CasesSolvedFrequenciesParameter.ActualValue = casesSolvedFrequencies;
        SummedCaseQualitiesParameter.ActualValue = summedCaseQualities;
        results.Add(new Result("Cases solved", casesSolvedFrequencies));
        results.Add(new Result("Summed cases qualities", summedCaseQualities));
      }

      // all rows must have the same number of values so we can just take the first
      int numberOfValues = casesSolvedFrequencies.Rows.Select(r => r.Values.Count).DefaultIfEmpty().First();

      foreach (var triple in Enumerable.Range(0, cases[0].Length).Select(i => new Tuple<string, int, double>("Case " + i, cases.Count(caseArray => caseArray[i]), caseQualities.Sum(casesQualityArray => casesQualityArray[i])))) {
        if (!casesSolvedFrequencies.Rows.ContainsKey(triple.Item1)) {
          // initialize a new row for the symbol and pad with zeros
          DataRow row = new DataRow(triple.Item1, "", Enumerable.Repeat(0.0, numberOfValues));
          row.VisualProperties.StartIndexZero = true;
          casesSolvedFrequencies.Rows.Add(row);

          row = new DataRow(triple.Item1, "", Enumerable.Repeat(0.0, numberOfValues));
          row.VisualProperties.StartIndexZero = true;
          summedCaseQualities.Rows.Add(row);
        }
        casesSolvedFrequencies.Rows[triple.Item1].Values.Add(triple.Item2);
        summedCaseQualities.Rows[triple.Item1].Values.Add(triple.Item3);
      }
      return base.Apply();
    }
    private void UpdateDataTable(IEnumerable<IRun> runs) {
      combinedDataTable.Rows.Clear();

      var visibleRuns = runs.Where(r => r.Visible);

      var resultName = (string)dataTableComboBox.SelectedItem;
      if (string.IsNullOrEmpty(resultName)) return;

      var dataTables = visibleRuns.Where(r => r.Results.ContainsKey(resultName)).Select(r => (DataTable)r.Results[resultName]);
      if (dataTables.Count() != visibleRuns.Count()) {
        using (InfoBox dialog = new InfoBox(String.Format("One or more runs do not contain a data table {0}", resultName), this.Name, this)) {
          dialog.ShowDialog(this);
          return;
        }
      }

      var dataRows = dataTables.SelectMany(dt => dt.Rows).GroupBy(r => r.Name, r => r);

      int tableCount = dataTables.Count();
      foreach (var row in dataRows) {
        var aggreateRows = row.Select(r => (IEnumerable<double>)r.Values).ToList();
        // check if all rows have the same length
        if (row.Any(r => r.Values.Count != row.First().Values.Count)) {
          using (InfoBox dialog = new InfoBox(String.Format("One or more runs do not contain the same number of entries per row {0}", resultName), this.Name, this)) {
            dialog.ShowDialog(this);
            return;
          }
        }

        // add zero rows for missing rows, otherwise the aggragation is off
        if (row.Count() < tableCount) {
          var zeroRows = Enumerable.Repeat(Enumerable.Repeat(0.0, row.First().Values.Count), tableCount - row.Count());
          aggreateRows.AddRange(zeroRows);
        }

        var averageValues = DataRowsAggregate(Enumerable.Average, aggreateRows);
        DataRow averageRow = new DataRow(row.Key, "Average of Values", averageValues);
        combinedDataTable.Rows.Add(averageRow);
      }
    }
    private void AddPointsToHistogramSeries(Series series, DataRow row, List<double> values) {
      if (!row.Values.Any()) return;
      int bins = row.VisualProperties.Bins;

      double minValue = GetMinimum(row.Values);
      double maxValue = GetMaximum(row.Values);
      double intervalWidth = (maxValue - minValue) / bins;
      if (intervalWidth < 0) return;
      if (intervalWidth == 0) {
        series.Points.AddXY(minValue, row.Values.Count);
        return;
      }


      if (!row.VisualProperties.ExactBins) {
        intervalWidth = HumanRoundRange(intervalWidth);
        minValue = Math.Floor(minValue / intervalWidth) * intervalWidth;
        maxValue = Math.Ceiling(maxValue / intervalWidth) * intervalWidth;
      }

      double intervalCenter = intervalWidth / 2;

      double min = 0.0, max = 0.0;
      if (!Double.IsNaN(Content.VisualProperties.XAxisMinimumFixedValue) && !Content.VisualProperties.XAxisMinimumAuto)
        min = Content.VisualProperties.XAxisMinimumFixedValue;
      else min = minValue;
      if (!Double.IsNaN(Content.VisualProperties.XAxisMaximumFixedValue) && !Content.VisualProperties.XAxisMaximumAuto)
        max = Content.VisualProperties.XAxisMaximumFixedValue;
      else max = maxValue + intervalWidth;

      double axisInterval = intervalWidth / row.VisualProperties.ScaleFactor;

      var area = chart.ChartAreas[0];
      area.AxisX.Interval = axisInterval;

      series.SetCustomProperty("PointWidth", "1"); // 0.8 is the default value

      // get the range or intervals which define the grouping of the frequency values
      var doubleRange = DoubleRange(min, max, intervalWidth).Skip(1).ToList();


      if (values == null) {
        values = row.Values.ToList(); ;
      }

      // aggregate the row values by unique key and frequency value
      var valueFrequencies = (from v in values
                              where !IsInvalidValue(v)
                              orderby v
                              group v by v into g
                              select new Tuple<double, double>(g.First(), g.Count())).ToList();

      //  shift the chart to the left so the bars are placed on the intervals
      if (Classification != null || valueFrequencies.First().Item1 < doubleRange.First()) {
        series.Points.Add(new DataPoint(min - intervalWidth, 0));
        series.Points.Add(new DataPoint(max + intervalWidth, 0));
      }

      // add data points
      int j = 0;
      foreach (var d in doubleRange) {
        double sum = 0.0;
        // sum the frequency values that fall within the same interval
        while (j < valueFrequencies.Count && valueFrequencies[j].Item1 < d) {
          sum += valueFrequencies[j].Item2;
          ++j;
        }
        string xAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.XAxisTitle)
                              ? "X"
                              : Content.VisualProperties.XAxisTitle;
        string yAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.YAxisTitle)
                              ? "Y"
                              : Content.VisualProperties.YAxisTitle;
        DataPoint newDataPoint = new DataPoint(d - intervalCenter, sum);
        newDataPoint.ToolTip =
          xAxisTitle + ": [" + (d - intervalWidth) + "-" + d + ")" + Environment.NewLine +
          yAxisTitle + ": " + sum;
        int overallValueCount = row.Values.Count();
        if (overallValueCount > 0)
          newDataPoint.ToolTip += string.Format(" ({0:F2}%)", (sum / overallValueCount) * 100);
        series.Points.Add(newDataPoint);
      }
    }
    protected override void Run(CancellationToken cancellationToken) {
      // Set up the algorithm
      if (SetSeedRandomly) Seed = new System.Random().Next();
      pyramid = new List<Population>();
      seen.Clear();
      random.Reset(Seed);
      tracker = new EvaluationTracker(Problem, MaximumEvaluations);

      // Set up the results display
      Results.Add(new Result("Iterations", new IntValue(0)));
      Results.Add(new Result("Evaluations", new IntValue(0)));
      Results.Add(new Result("Best Solution", new BinaryVector(tracker.BestSolution)));
      Results.Add(new Result("Best Quality", new DoubleValue(tracker.BestQuality)));
      Results.Add(new Result("Evaluation Best Solution Was Found", new IntValue(tracker.BestFoundOnEvaluation)));
      var table = new DataTable("Qualities");
      table.Rows.Add(new DataRow("Best Quality"));
      var iterationRows = new DataRow("Iteration Quality");
      iterationRows.VisualProperties.LineStyle = DataRowVisualProperties.DataRowLineStyle.Dot;
      table.Rows.Add(iterationRows);
      Results.Add(new Result("Qualities", table));

      table = new DataTable("Pyramid Levels");
      table.Rows.Add(new DataRow("Levels"));
      Results.Add(new Result("Pyramid Levels", table));

      table = new DataTable("Stored Solutions");
      table.Rows.Add(new DataRow("Solutions"));
      Results.Add(new Result("Stored Solutions", table));

      // Loop until iteration limit reached or canceled.
      for (ResultsIterations = 0; ResultsIterations < MaximumIterations; ResultsIterations++) {
        double fitness = double.NaN;

        try {
          fitness = iterate();
          cancellationToken.ThrowIfCancellationRequested();
        } finally {
          ResultsEvaluations = tracker.Evaluations;
          ResultsBestSolution = new BinaryVector(tracker.BestSolution);
          ResultsBestQuality = tracker.BestQuality;
          ResultsBestFoundOnEvaluation = tracker.BestFoundOnEvaluation;
          ResultsQualitiesBest.Values.Add(tracker.BestQuality);
          ResultsQualitiesIteration.Values.Add(fitness);
          ResultsLevels.Values.Add(pyramid.Count);
          ResultsSolutions.Values.Add(seen.Count);
        }
      }
    }
예제 #7
0
 protected DataRow(DataRow original, Cloner cloner)
   : base(original, cloner) {
   this.VisualProperties = (DataRowVisualProperties)cloner.Clone(original.visualProperties);
   this.values = new ObservableList<double>(original.values);
 }
 private void FillSeriesWithRowValues(Series series, DataRow row) {
   switch (row.VisualProperties.ChartType) {
     case DataRowVisualProperties.DataRowChartType.Histogram:
       CalculateHistogram(series, row);
       break;
     default: {
         bool yLogarithmic = series.YAxisType == AxisType.Primary
                               ? Content.VisualProperties.YAxisLogScale
                               : Content.VisualProperties.SecondYAxisLogScale;
         bool xLogarithmic = series.XAxisType == AxisType.Primary
                               ? Content.VisualProperties.XAxisLogScale
                               : Content.VisualProperties.SecondXAxisLogScale;
         for (int i = 0; i < row.Values.Count; i++) {
           var value = row.Values[i];
           var point = new DataPoint();
           point.XValue = row.VisualProperties.StartIndexZero && !xLogarithmic ? i : i + 1;
           if (IsInvalidValue(value) || (yLogarithmic && value <= 0))
             point.IsEmpty = true;
           else
             point.YValues = new double[] { value };
           series.Points.Add(point);
         }
       }
       break;
   }
 }
    private void AddConstructiveEffectTableEntry(IntValue[] constructiveEffect) {
      if (ConstructiveEffectDataTable == null) {
        var table = new DataTable(ConstructiveEffectParameterName, "");
        table.VisualProperties.YAxisTitle = "Percentage";
        table.VisualProperties.YAxisMaximumFixedValue = 100.0;
        table.VisualProperties.YAxisMaximumAuto = false;

        DataRow worseThanRootedRow = new DataRow("Worse than rooted");
        worseThanRootedRow.VisualProperties.StartIndexZero = true;
        table.Rows.Add(worseThanRootedRow);

        DataRow betterThanRootedRow = new DataRow("Better than rooted");
        betterThanRootedRow.VisualProperties.StartIndexZero = true;
        table.Rows.Add(betterThanRootedRow);

        DataRow betterThanBothRow = new DataRow("Better than both");
        betterThanBothRow.VisualProperties.StartIndexZero = true;
        table.Rows.Add(betterThanBothRow);

        ConstructiveEffectDataTable = table;
      }
      List<double> constructiveEffectCount = new List<double>() { 0.0, 0.0, 0.0 };
      for (int i = 0; i < constructiveEffect.Length; i++) {
        constructiveEffectCount[constructiveEffect[i].Value]++;
      }

      ConstructiveEffectDataTable.Rows["Worse than rooted"].Values.Add(constructiveEffectCount[0] / constructiveEffect.Length * 100.0);
      ConstructiveEffectDataTable.Rows["Better than rooted"].Values.Add((constructiveEffectCount[1] + constructiveEffectCount[2]) / constructiveEffect.Length * 100.0);
      ConstructiveEffectDataTable.Rows["Better than both"].Values.Add(constructiveEffectCount[2] / constructiveEffect.Length * 100.0);
    }
    private static DataTable CalcAverage(RunCollection runs, string tableName) {
      DataTable temptable = new DataTable();

      var visibleRuns = runs.Where(r => r.Visible);

      var resultName = (string)tableName;

      var dataTables = visibleRuns.Where(r => r.Results.ContainsKey(resultName)).Select(r => (DataTable)r.Results[resultName]);
      if (dataTables.Count() != visibleRuns.Count()) {
        throw new ArgumentException("Should not happen");
      }

      var dataRows = dataTables.SelectMany(dt => dt.Rows).GroupBy(r => r.Name, r => r);

      foreach (var row in dataRows) {
        var averageValues = DataRowsAggregate(Enumerable.Average, row.Select(r => r.Values));
        DataRow averageRow = new DataRow(row.Key, "Average of Values", averageValues);
        temptable.Rows.Add(averageRow);
      }
      return temptable;
    }
    private void AddSemanticLocalityTableEntry(double average) {
      if (SemanticLocalityDataTable == null) {
        var table = new DataTable(SemanticLocalityParameterName, "");
        table.VisualProperties.YAxisTitle = "Average Fitness Change";

        DataRow row = new DataRow("Sematic Locality");
        row.VisualProperties.StartIndexZero = true;
        table.Rows.Add(row);

        SemanticLocalityDataTable = table;
      }
      SemanticLocalityDataTable.Rows["Sematic Locality"].Values.Add(average);
    }
    private void AddSemanticallyDifferentFromRootedParentTableEntry(BoolValue[] semanticallyDifferentFromRootedParent) {
      if (SemanticallyDifferentFromRootedParentDataTable == null) {
        var table = new DataTable(SemanticallyDifferentFromRootedParentParameterName, "");
        table.VisualProperties.YAxisTitle = "Percentage";
        table.VisualProperties.YAxisMaximumFixedValue = 100.0;
        table.VisualProperties.YAxisMaximumAuto = false;

        DataRow differentRow = new DataRow("Different From Parent");
        differentRow.VisualProperties.StartIndexZero = true;
        table.Rows.Add(differentRow);

        DataRow sameRow = new DataRow("Same As Parent");
        sameRow.VisualProperties.StartIndexZero = true;
        table.Rows.Add(sameRow);

        SemanticallyDifferentFromRootedParentDataTable = table;
      }
      double different = semanticallyDifferentFromRootedParent.Count(x => x.Value);

      SemanticallyDifferentFromRootedParentDataTable.Rows["Different From Parent"].Values.Add(different / semanticallyDifferentFromRootedParent.Length * 100.0);
      SemanticallyDifferentFromRootedParentDataTable.Rows["Same As Parent"].Values.Add((semanticallyDifferentFromRootedParent.Length - different) / semanticallyDifferentFromRootedParent.Length * 100.0);
    }
    private void AddSemanticallyEquivalentCrossoverTableEntry(IntValue[] semanticallyEquivalentCrossover) {
      if (SemanticallyEquivalentCrossoverDataTable == null) {
        var table = new DataTable(SemanticallyEquivalentCrossoverParameterName, "");
        table.VisualProperties.YAxisTitle = "Percentage";
        table.VisualProperties.YAxisMaximumFixedValue = 100.0;
        table.VisualProperties.YAxisMaximumAuto = false;

        DataRow noCrossoverRow = new DataRow("No Crossover");
        noCrossoverRow.VisualProperties.StartIndexZero = true;
        table.Rows.Add(noCrossoverRow);

        DataRow equivalentRow = new DataRow("Equivalent");
        equivalentRow.VisualProperties.StartIndexZero = true;
        table.Rows.Add(equivalentRow);

        DataRow equivalentOrNoCrossoverRow = new DataRow("Equivalent + No Crossover");
        equivalentOrNoCrossoverRow.VisualProperties.StartIndexZero = true;
        table.Rows.Add(equivalentOrNoCrossoverRow);

        DataRow differentRow = new DataRow("Different");
        differentRow.VisualProperties.StartIndexZero = true;
        table.Rows.Add(differentRow);

        SemanticallyEquivalentCrossoverDataTable = table;
      }
      List<int> semanticallyEquivalentCrossoverCount = new List<int>() { 0, 0, 0 };
      for (int i = 0; i < semanticallyEquivalentCrossover.Length; i++) {
        semanticallyEquivalentCrossoverCount[semanticallyEquivalentCrossover[i].Value]++;
      }
      double total = semanticallyEquivalentCrossover.Length;
      SemanticallyEquivalentCrossoverDataTable.Rows["No Crossover"].Values.Add(semanticallyEquivalentCrossoverCount[0] / total * 100.0);
      SemanticallyEquivalentCrossoverDataTable.Rows["Equivalent"].Values.Add(semanticallyEquivalentCrossoverCount[1] / total * 100.0);
      SemanticallyEquivalentCrossoverDataTable.Rows["Equivalent + No Crossover"].Values.Add((semanticallyEquivalentCrossoverCount[0] + semanticallyEquivalentCrossoverCount[1]) / total * 100.0);
      SemanticallyEquivalentCrossoverDataTable.Rows["Different"].Values.Add(semanticallyEquivalentCrossoverCount[2] / total * 100.0);
    }
예제 #14
0
 protected virtual void DeregisterRowEvents(DataRow row) {
   row.Values.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsAdded);
   row.Values.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsMoved);
   row.Values.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsRemoved);
   row.Values.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsReplaced);
   row.Values.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_CollectionReset);
 }
    public override IOperation Apply() {
      DataTable ageDistribution = null;
      ResultCollection results = ResultsParameter.ActualValue;
      string description = "Shows the age distributions in the current population.";
      if (results.ContainsKey(HistogramName)) {
        ageDistribution = results[HistogramName].Value as DataTable;
      } else {
        ageDistribution = new DataTable("Population Age Distribution", description);
        ageDistribution.VisualProperties.XAxisTitle = AgeParameter.ActualName;
        ageDistribution.VisualProperties.YAxisTitle = "Frequency";
        results.Add(new Result(HistogramName, description, ageDistribution));
      }
      DataRow row;
      if (!ageDistribution.Rows.TryGetValue("AgeDistribution", out row)) {
        row = new DataRow("AgeDistribution");
        row.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
        ageDistribution.Rows.Add(row);
      }
      var ages = AgeParameter.ActualValue;
      row.Values.Replace(ages.Select(x => x.Value));

      if (StoreHistory) {
        string historyResultName = HistogramName + " History";
        DataTableHistory adHistory = null;
        if (results.ContainsKey(historyResultName)) {
          adHistory = results[historyResultName].Value as DataTableHistory;
        } else {
          adHistory = new DataTableHistory();
          results.Add(new Result(historyResultName, adHistory));
        }
        DataTable table = (DataTable)ageDistribution.Clone();
        IntValue iteration = IterationsParameter.ActualValue;
        if (iteration != null) {
          string iterationName = IterationsParameter.ActualName;
          if (iterationName.EndsWith("s")) iterationName = iterationName.Remove(iterationName.Length - 1);
          string appendix = " at " + iterationName + " " + iteration.Value.ToString();
          table.Name += appendix;
          table.Rows["AgeDistribution"].VisualProperties.DisplayName += appendix;
        }
        adHistory.Add(table);
      }
      return base.Apply();
    }
    private void ConfigureSeries(Series series, DataRow row) {
      RemoveCustomPropertyIfExists(series, "PointWidth");
      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;

      switch (row.VisualProperties.ChartType) {
        case DataRowVisualProperties.DataRowChartType.Line:
          series.ChartType = SeriesChartType.FastLine;
          series.BorderWidth = row.VisualProperties.LineWidth;
          series.BorderDashStyle = ConvertLineStyle(row.VisualProperties.LineStyle);
          break;
        case DataRowVisualProperties.DataRowChartType.Bars:
          // Bar is incompatible with anything but Bar and StackedBar*
          if (!chart.Series.Any(x => x.ChartType != SeriesChartType.Bar && x.ChartType != SeriesChartType.StackedBar && x.ChartType != SeriesChartType.StackedBar100))
            series.ChartType = SeriesChartType.Bar;
          else {
            series.ChartType = SeriesChartType.FastPoint; //default
            row.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points;
          }
          break;
        case DataRowVisualProperties.DataRowChartType.Columns:
          series.ChartType = SeriesChartType.Column;
          break;
        case DataRowVisualProperties.DataRowChartType.Points:
          series.ChartType = SeriesChartType.FastPoint;
          break;
        case DataRowVisualProperties.DataRowChartType.Histogram:
          series.ChartType = SeriesChartType.StackedColumn;
          series.SetCustomProperty("PointWidth", "1");
          if (!series.Color.IsEmpty && series.Color.GetBrightness() < 0.25)
            series.BorderColor = Color.White;
          else series.BorderColor = Color.Black;
          break;
        case DataRowVisualProperties.DataRowChartType.StepLine:
          series.ChartType = SeriesChartType.StepLine;
          series.BorderWidth = row.VisualProperties.LineWidth;
          series.BorderDashStyle = ConvertLineStyle(row.VisualProperties.LineStyle);
          break;
        default:
          series.ChartType = SeriesChartType.FastPoint;
          break;
      }
      series.YAxisType = row.VisualProperties.SecondYAxis ? AxisType.Secondary : AxisType.Primary;
      series.XAxisType = row.VisualProperties.SecondXAxis ? AxisType.Secondary : 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 + " = " + "#INDEX," + Environment.NewLine +
        yAxisTitle + " = " + "#VAL";
    }
    public DataRow CreateDataRowRange(string variableName, int start, int end, DataRowVisualProperties.DataRowChartType chartType) {
      IList<double> values = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableName));
      IList<double> valuesRange = new List<double>();
      for (int i = 0; i < values.Count; i++) {
        if (i >= start && i <= end)
          valuesRange.Add(values[i]);
        else
          valuesRange.Add(Double.NaN);
      }

      DataRow row = new DataRow(variableName, "", valuesRange);
      row.VisualProperties.ChartType = chartType;
      return row;
    }
    protected virtual void CalculateHistogram(Series series, DataRow row) {
      if (Classification != null) {

        var valuesPerClass = row.Values.Select((i, index) => new { i, j = Classification.ToList()[index] })
                                       .GroupBy((x) => x.j)
                                       .ToDictionary(x => x.Key, x => x.Select(v => v.i)
                                       .ToList());

        chart.Titles.Add(row.Name);
        int featureOverallValueCount = 0;
        if (IsDetailedChartViewEnabled)
          featureOverallValueCount = row.Values.Count(x => !IsInvalidValue(x));
        foreach (KeyValuePair<double, List<double>> entry in valuesPerClass) {
          var s = new Series(row.Name + entry.Key);

          ConfigureSeries(s, row);
          AddPointsToHistogramSeries(s, row, entry.Value);

          s.LegendText = entry.Key.ToString();
          if (IsDetailedChartViewEnabled) {
            int featureValueCount = entry.Value.Count(x => !IsInvalidValue(x));
            s.LegendText += " Values: ";
            s.LegendText += (featureOverallValueCount > 0) ?
              string.Format("{0} ({1:F2}%)", featureValueCount, (featureValueCount / (double)featureOverallValueCount) * 100)
            : "0";
          }
          chart.Series.Add(s);
        }
      } else {
        series.Points.Clear();
        ConfigureSeries(series, row);
        AddPointsToHistogramSeries(series, row, null);
      }
    }
 public DataRow CreateDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
   IList<double> values = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableName));
   DataRow row = new DataRow(variableName, "", values);
   row.VisualProperties.ChartType = chartType;
   return row;
 }
 protected virtual void DeregisterDataRowEvents(DataRow row) {
   row.Values.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsAdded);
   row.Values.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsRemoved);
   row.Values.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsReplaced);
   row.Values.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsMoved);
   row.Values.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_CollectionReset);
   valuesRowsTable.Remove(row.Values);
   row.VisualPropertiesChanged -= new EventHandler(Row_VisualPropertiesChanged);
   row.NameChanged -= new EventHandler(Row_NameChanged);
 }
    public override IOperation Apply() {
      ItemArray<ISymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue;
      ResultCollection results = ResultCollection;
      DataTable datatable;
      if (VariableFrequenciesParameter.ActualValue == null) {
        datatable = new DataTable("Variable frequencies", "Relative frequency of variable references aggregated over the whole population.");
        datatable.VisualProperties.XAxisTitle = "Generation";
        datatable.VisualProperties.YAxisTitle = "Relative Variable Frequency";
        VariableFrequenciesParameter.ActualValue = datatable;
        results.Add(new Result("Variable frequencies", "Relative frequency of variable references aggregated over the whole population.", datatable));
        results.Add(new Result("Variable impacts", "The relative variable relevance calculated as the average relative variable frequency over the whole run.", new DoubleMatrix()));
      }

      datatable = VariableFrequenciesParameter.ActualValue;
      // all rows must have the same number of values so we can just take the first
      int numberOfValues = datatable.Rows.Select(r => r.Values.Count).DefaultIfEmpty().First();

      foreach (var pair in SymbolicDataAnalysisVariableFrequencyAnalyzer.CalculateVariableFrequencies(expressions, AggregateLaggedVariables.Value)) {
        if (!datatable.Rows.ContainsKey(pair.Key)) {
          // initialize a new row for the variable and pad with zeros
          DataRow row = new DataRow(pair.Key, "", Enumerable.Repeat(0.0, numberOfValues));
          row.VisualProperties.StartIndexZero = true;
          datatable.Rows.Add(row);
        }
        datatable.Rows[pair.Key].Values.Add(Math.Round(pair.Value, 3));
      }

      // add a zero for each data row that was not modified in the previous loop 
      foreach (var row in datatable.Rows.Where(r => r.Values.Count != numberOfValues + 1))
        row.Values.Add(0.0);

      // update variable impacts matrix
      var orderedImpacts = (from row in datatable.Rows
                            select new { Name = row.Name, Impact = Math.Round(datatable.Rows[row.Name].Values.Average(), 3) })
                           .OrderByDescending(p => p.Impact)
                           .ToList();
      var impacts = new DoubleMatrix();
      var matrix = impacts as IStringConvertibleMatrix;
      matrix.Rows = orderedImpacts.Count;
      matrix.RowNames = orderedImpacts.Select(x => x.Name);
      matrix.Columns = 1;
      matrix.ColumnNames = new string[] { "Relative variable relevance" };
      int i = 0;
      foreach (var p in orderedImpacts) {
        matrix.SetValue(p.Impact.ToString(), i++, 0);
      }

      VariableImpactsParameter.ActualValue = impacts;
      results["Variable impacts"].Value = impacts;
      return base.Apply();
    }
 private void AddValue(DataTable table, double data, string name, string description) {
   DataRow row;
   table.Rows.TryGetValue(name, out row);
   if (row == null) {
     row = new DataRow(name, description);
     row.VisualProperties.StartIndexZero = StartIndexZero;
     row.Values.Add(data);
     table.Rows.Add(row);
   } else {
     row.Values.Add(data);
   }
 }
    public override IOperation Apply() {
      ResultCollection results = ResultsParameter.ActualValue;

      List<IScope> scopes = new List<IScope>() { ExecutionContext.Scope };
      for (int i = 0; i < DepthParameter.Value.Value; i++)
        scopes = scopes.Select(x => (IEnumerable<IScope>)x.SubScopes).Aggregate((a, b) => a.Concat(b)).ToList();

      ItemCollection<StringValue> collectedValues = CollectedValuesParameter.Value;
      foreach (StringValue collected in collectedValues) {
        //collect the values of the successful offspring
        Dictionary<String, int> counts = new Dictionary<String, int>();
        for (int i = 0; i < scopes.Count; i++) {
          IScope child = scopes[i];
          string successfulOffspringFlag = SuccessfulOffspringFlagParameter.Value.Value;
          if (child.Variables.ContainsKey(collected.Value) &&
              child.Variables.ContainsKey(successfulOffspringFlag) &&
              (child.Variables[successfulOffspringFlag].Value is BoolValue) &&
              (child.Variables[successfulOffspringFlag].Value as BoolValue).Value) {
            String key = child.Variables[collected.Value].Value.ToString();

            if (!counts.ContainsKey(key))
              counts.Add(key, 1);
            else
              counts[key]++;
          }
        }

        if (counts.Count > 0) {
          //create a data table containing the collected values
          ResultCollection successfulOffspringAnalysis;

          if (SuccessfulOffspringAnalysisParameter.ActualValue == null) {
            successfulOffspringAnalysis = new ResultCollection();
            SuccessfulOffspringAnalysisParameter.ActualValue = successfulOffspringAnalysis;
          } else {
            successfulOffspringAnalysis = SuccessfulOffspringAnalysisParameter.ActualValue;
          }

          string resultKey = "SuccessfulOffspringAnalyzer Results";
          if (!results.ContainsKey(resultKey)) {
            results.Add(new Result(resultKey, successfulOffspringAnalysis));
          } else {
            results[resultKey].Value = successfulOffspringAnalysis;
          }

          DataTable successProgressAnalysis;
          if (!successfulOffspringAnalysis.ContainsKey(collected.Value)) {
            successProgressAnalysis = new DataTable();
            successProgressAnalysis.Name = collected.Value;
            successfulOffspringAnalysis.Add(new Result(collected.Value, successProgressAnalysis));
          } else {
            successProgressAnalysis = successfulOffspringAnalysis[collected.Value].Value as DataTable;
          }

          int successfulCount = 0;
          foreach (string key in counts.Keys) {
            successfulCount += counts[key];
          }

          foreach (String value in counts.Keys) {
            DataRow row;
            if (!successProgressAnalysis.Rows.ContainsKey(value)) {
              row = new DataRow(value);
              int iterations = GenerationsParameter.ActualValue.Value;

              //fill up all values seen the first time
              for (int i = 1; i < iterations; i++)
                row.Values.Add(0);

              successProgressAnalysis.Rows.Add(row);
            } else {
              row = successProgressAnalysis.Rows[value];
            }

            row.Values.Add(counts[value] / (double)successfulCount);
          }

          //fill up all values that are not present in the current generation
          foreach (DataRow row in successProgressAnalysis.Rows) {
            if (!counts.ContainsKey(row.Name))
              row.Values.Add(0);
          }
        }
      }

      return base.Apply();
    }
    public override IOperation Apply() {
      UpdateCounter.Value++;
      // the analyzer runs periodically, every 'updateInterval' times
      if (UpdateCounter.Value == UpdateInterval.Value) {
        UpdateCounter.Value = 0; // reset counter

        // compute all tree lengths and store them in the lengthsTable
        var solutions = SymbolicExpressionTreeParameter.ActualValue;

        var treeLengthsTable = SymbolicExpressionTreeLengthsParameter.ActualValue;
        // if the table was not created yet, we create it here
        if (treeLengthsTable == null) {
          treeLengthsTable = new DataTable("Tree Length Histogram");
          SymbolicExpressionTreeLengthsParameter.ActualValue = treeLengthsTable;
        }

        // data table which stores tree length values
        DataRow treeLengthsTableRow;

        const string treeLengthsTableRowName = "Symbolic expression tree lengths";
        const string treeLengthsTableRowDesc = "The distribution of symbolic expression tree lengths";
        const string xAxisTitle = "Symbolic expression tree lengths";
        const string yAxisTitle = "Frequency / Number of tree individuals";

        var treeLengths = solutions.Select(s => (int)s.Length).ToList();

        int maxLength = treeLengths.Max(t => t);
        int minLength = treeLengths.Min(t => t);

        if (!treeLengthsTable.Rows.ContainsKey(treeLengthsTableRowName)) {
          treeLengthsTableRow = new DataRow(treeLengthsTableRowName, treeLengthsTableRowDesc, treeLengths.Select(x => (double)x));
          treeLengthsTable.Rows.Add(treeLengthsTableRow);
        } else {
          treeLengthsTableRow = treeLengthsTable.Rows[treeLengthsTableRowName];
          treeLengthsTableRow.Values.Replace(treeLengths.Select(x => (double)x));
        }

        double maximumAllowedTreeLength = MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value;

        treeLengthsTableRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
        treeLengthsTableRow.VisualProperties.ExactBins = false;

        int range = maxLength - minLength;
        if (range == 0) range = 1;
        // the following trick should result in an integer intervalWidth of 1,2,4,...
        treeLengthsTableRow.VisualProperties.Bins = range;

        if (maxLength <= 25) // [0,25]
          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0;
        else if (maxLength <= 100) // [26,100]
          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 2.0;
        else if (maxLength <= 250) // [101,250]
          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 5.0;
        else if (maxLength <= 500) // [251,500]
          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 10.0;
        else
          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 20.0; // [501,inf]

        treeLengthsTableRow.VisualProperties.IsVisibleInLegend = false;

        // visual properties for the X-axis
        treeLengthsTable.VisualProperties.XAxisMinimumAuto = false;
        treeLengthsTable.VisualProperties.XAxisMaximumAuto = false;
        treeLengthsTable.VisualProperties.XAxisMinimumFixedValue = 0.0;
        if (maxLength > maximumAllowedTreeLength + 1)
          treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = maxLength + 1; // +1 so the histogram column for the maximum length won't get trimmed
        else
          treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = maximumAllowedTreeLength + 1;
        treeLengthsTable.VisualProperties.XAxisTitle = xAxisTitle;
        //visual properties for the Y-axis
        treeLengthsTable.VisualProperties.YAxisMinimumAuto = false;
        treeLengthsTable.VisualProperties.YAxisMaximumAuto = false;
        treeLengthsTable.VisualProperties.YAxisMinimumFixedValue = 0.0;
        int maxFreq = (int)Math.Round(solutions.GroupBy(s => s.Length).Max(g => g.Count()) / treeLengthsTableRow.VisualProperties.ScaleFactor);
        if (maxFreq % 5 != 0)
          maxFreq += (5 - maxFreq % 5);
        double yAxisMaximumFixedValue = maxFreq;

        treeLengthsTable.VisualProperties.YAxisMaximumFixedValue = yAxisMaximumFixedValue;
        treeLengthsTable.VisualProperties.YAxisTitle = yAxisTitle;

        var results = ResultsParameter.ActualValue;

        if (!results.ContainsKey(treeLengthsTableRowName)) {
          results.Add(new Result(treeLengthsTableRowName, treeLengthsTable));
        } else {
          results[treeLengthsTableRowName].Value = treeLengthsTable;
        }

        bool storeHistory = StoreHistoryParameter.Value.Value;
        const string treeLengthHistoryTableName = "Tree lengths history";

        if (storeHistory) {
          var treeLengthsHistory = SymbolicExpressionTreeLengthsHistoryParameter.ActualValue;
          if (treeLengthsHistory == null) {
            treeLengthsHistory = new DataTableHistory();
            SymbolicExpressionTreeLengthsHistoryParameter.ActualValue = treeLengthsHistory;
          }
          treeLengthsHistory.Add((DataTable)treeLengthsTable.Clone());

          if (!results.ContainsKey(treeLengthHistoryTableName)) {
            results.Add(new Result(treeLengthHistoryTableName, treeLengthsHistory));
          } else {
            results[treeLengthHistoryTableName].Value = treeLengthsHistory;
          }
        }
      }
      return base.Apply();
    }
    public override IOperation Apply() {
      ItemArray<StringValue> exceptions = ExceptionTreeParameter.ActualValue;
      double count = exceptions.Count();
      ResultCollection results = ResultsParameter.ActualValue;
      DataTable exceptionFrequencies = ExceptionFrequenciesParameter.ActualValue;
      if (exceptionFrequencies == null) {
        exceptionFrequencies = new DataTable("Exception frequencies", "Relative frequency of exception aggregated over the whole population.");
        exceptionFrequencies.VisualProperties.YAxisTitle = "Relative Exception Frequency";

        ExceptionFrequenciesParameter.ActualValue = exceptionFrequencies;
        results.Add(new Result("Exception frequencies", exceptionFrequencies));
      }

      // all rows must have the same number of values so we can just take the first
      int numberOfValues = exceptionFrequencies.Rows.Select(r => r.Values.Count).DefaultIfEmpty().First();

      foreach (var pair in exceptions.GroupBy(x => x.Value).ToDictionary(g => g.Key, g => (double)g.Count() / count)) {
        string key = String.IsNullOrEmpty(pair.Key) ? "No Exception" : pair.Key;
        if (!exceptionFrequencies.Rows.ContainsKey(key)) {
          // initialize a new row for the symbol and pad with zeros
          DataRow row = new DataRow(key, "", Enumerable.Repeat(0.0, numberOfValues));
          row.VisualProperties.StartIndexZero = true;
          exceptionFrequencies.Rows.Add(row);
        }
        exceptionFrequencies.Rows[key].Values.Add(Math.Round(pair.Value, 3));
      }

      // add a zero for each data row that was not modified in the previous loop 
      foreach (var row in exceptionFrequencies.Rows.Where(r => r.Values.Count != numberOfValues + 1))
        row.Values.Add(0.0);
      return base.Apply();
    }
예제 #26
0
 private void AddValues(double[] x, DataTable dataTable) {
   if (!dataTable.Rows.Any()) {
     for (int i = 0; i < x.Length; i++) {
       var newRow = new DataRow("x" + i);
       newRow.Values.Add(x[i]);
       dataTable.Rows.Add(newRow);
     }
   } else {
     for (int i = 0; i < x.Length; i++) {
       dataTable.Rows.ElementAt(i).Values.Add(x[i]);
     }
   }
 }
    private void AddTypeSelectedForSimilarityTableEntry(StringValue[] typeSelectedForSimilarity) {
      if (!ResultCollection.ContainsKey(TypeSelectedForSimilarityParameterName)) {
        var newTable = new DataTable(TypeSelectedForSimilarityParameterName, "");
        newTable.VisualProperties.YAxisTitle = "Percentage";
        newTable.VisualProperties.YAxisMaximumAuto = false;

        ResultCollection.Add(new Result(TypeSelectedForSimilarityParameterName, newTable));
      }
      var table = ((DataTable)ResultCollection[TypeSelectedForSimilarityParameterName].Value);

      // all rows must have the same number of values so we can just take the first
      int numberOfValues = table.Rows.Select(r => r.Values.Count).DefaultIfEmpty().First();

      double count = typeSelectedForSimilarity.Count();
      var groupedValues = typeSelectedForSimilarity.Select(x => x.Value).GroupBy(x => x);
      foreach (var type in groupedValues) {
        if (!table.Rows.ContainsKey(type.Key)) {
          // initialize a new row for the symbol and pad with zeros
          DataRow row = new DataRow(type.Key, "", Enumerable.Repeat(0.0, numberOfValues));
          row.VisualProperties.StartIndexZero = true;
          table.Rows.Add(row);
        }
        table.Rows[type.Key].Values.Add(type.Count() / count * 100);
      }

      // add a zero for each data row that was not modified in the previous loop 
      foreach (var row in table.Rows.Where(r => r.Values.Count != numberOfValues + 1))
        row.Values.Add(0.0);
    }