- Timestamp:
- 08/07/18 16:55:29 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2904_CalculateImpacts/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/ClassificationVariableImpactCalculationTest.cs
r16065 r16067 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Diagnostics; 3 4 using System.Linq; 4 5 using HeuristicLab.Algorithms.DataAnalysis; … … 15 16 [TestClass()] 16 17 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 17 28 private static readonly double epsilon = 0.00001; 18 29 … … 82 93 solution.ProblemData = LoadMammographyProblem(); 83 94 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); 84 114 } 85 115 … … 121 151 return ret; 122 152 } 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 123 181 #endregion 124 182
Note: See TracChangeset
for help on using the changeset viewer.