protected override void Analyze(ItemArray <DoubleArray> qualities, ResultCollection results)
        {
            ItemArray <IntValue> ranks = RankParameter.ActualValue;

            bool populationLevel = RankParameter.Depth == 1;

            int objectives = qualities[0].Length;
            int frontSize  = ranks.Count(x => x.Value == 0);
            ItemArray <IScope> paretoArchive = null;

            if (populationLevel)
            {
                paretoArchive = new ItemArray <IScope>(frontSize);
            }

            DoubleMatrix front   = new DoubleMatrix(frontSize, objectives);
            int          counter = 0;

            for (int i = 0; i < ranks.Length; i++)
            {
                if (ranks[i].Value == 0)
                {
                    for (int k = 0; k < objectives; k++)
                    {
                        front[counter, k] = qualities[i][k];
                    }
                    if (populationLevel)
                    {
                        paretoArchive[counter] = (IScope)ExecutionContext.Scope.SubScopes[i].Clone();
                    }
                    counter++;
                }
            }

            front.RowNames    = GetRowNames(front);
            front.ColumnNames = GetColumnNames(front);

            if (results.ContainsKey("Pareto Front"))
            {
                results["Pareto Front"].Value = front;
            }
            else
            {
                results.Add(new Result("Pareto Front", front));
            }

            if (populationLevel)
            {
                if (results.ContainsKey("Pareto Archive"))
                {
                    results["Pareto Archive"].Value = paretoArchive;
                }
                else
                {
                    results.Add(new Result("Pareto Archive", paretoArchive));
                }
            }
        }
Beispiel #2
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());
        }
Beispiel #3
0
        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());
        }
Beispiel #4
0
 private bool CanRemoveItem(UserItem I)
 {
     return(ItemArray.Count(O => O == null) > 0);
 }