Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16067


Ignore:
Timestamp:
08/07/18 16:55:29 (6 years ago)
Author:
fholzing
Message:

#2904: Added additional Unit-Test for performance measurement

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2904_CalculateImpacts/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/ClassificationVariableImpactCalculationTest.cs

    r16065 r16067  
    11using System;
    22using System.Collections.Generic;
     3using System.Diagnostics;
    34using System.Linq;
    45using HeuristicLab.Algorithms.DataAnalysis;
     
    1516  [TestClass()]
    1617  public class ClassificationVariableImpactCalculationTest {
     18    private TestContext testContextInstance;
     19    /// <summary>
     20    ///Gets or sets the test context which provides
     21    ///information about and functionality for the current test run.
     22    ///</summary>
     23    public TestContext TestContext {
     24      get { return testContextInstance; }
     25      set { testContextInstance = value; }
     26    }
     27
    1728    private static readonly double epsilon = 0.00001;
    1829
     
    8293      solution.ProblemData = LoadMammographyProblem();
    8394      ClassificationSolutionVariableImpactsCalculator.CalculateImpacts(solution);
     95    }
     96
     97
     98    [TestMethod]
     99    [TestCategory("Problems.DataAnalysis")]
     100    [TestProperty("Time", "medium")]
     101    public void PerformanceTest() {
     102      int rows = 1500;
     103      int columns = 77;
     104      IClassificationProblemData problemData = CreateDefaultProblem(rows, columns);
     105      IClassificationSolution solution = NearestNeighbourClassification.CreateNearestNeighbourClassificationSolution(problemData, 3);
     106
     107      Stopwatch watch = new Stopwatch();
     108      watch.Start();
     109      var results = ClassificationSolutionVariableImpactsCalculator.CalculateImpacts(solution);
     110      watch.Stop();
     111
     112      TestContext.WriteLine("");
     113      TestContext.WriteLine("Calculated cells per millisecond: {0}.", rows * columns / watch.ElapsedMilliseconds);
    84114    }
    85115
     
    121151      return ret;
    122152    }
     153
     154    private IClassificationProblemData CreateDefaultProblem(int rows, int columns) {
     155      List<string> allowedInputVariables = Enumerable.Range(0, columns - 1).Select(x => "x" + x.ToString()).ToList();
     156      string targetVariable = "y";
     157      var variableNames = allowedInputVariables.Union(targetVariable.ToEnumerable());
     158      double[,] variableValues = new double[rows, columns];
     159
     160      FastRandom random = new FastRandom(12345);
     161      int len0 = variableValues.GetLength(0);
     162      int len1 = variableValues.GetLength(1);
     163      for (int i = 0; i < len0; i++) {
     164        for (int j = 0; j < len1; j++) {
     165          if (j == len1 - 1) {
     166            variableValues[i, j] = (j + i) % 2;
     167          } else {
     168            variableValues[i, j] = random.Next(1, 100);
     169          }
     170        }
     171      }
     172
     173      Dataset dataset = new Dataset(variableNames, variableValues);
     174      var ret = new ClassificationProblemData(dataset, allowedInputVariables, targetVariable);
     175
     176      ret.SetClassName(0, "NOK");
     177      ret.SetClassName(1, "OK");
     178      return ret;
     179    }
     180
    123181    #endregion
    124182
Note: See TracChangeset for help on using the changeset viewer.