Changeset 7058
- Timestamp:
- 11/23/11 18:12:57 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/StatisticCalculatorsTest.cs
r7051 r7058 181 181 Assert.AreEqual(expected, actual, 1E-9); 182 182 } 183 184 [TestMethod] 185 public void CalculateMultiStepDirectionalSymmetryTest() { 186 // delta: +0.01, +1, -0.01, -2, -0.01, -1, +0.01, +2 187 var original = new double[] { 0, 0.01, 1.01, 1, -1, -1.01, -2.01, -2, 0 }; 188 { 189 var estimated = new double[][] 190 { 191 new double[] {0.01, 1.01, 1, -1, -1.01}, 192 new double[] {1.01, 1, -1, -1.01, -2.01}, 193 new double[] {1, -1, -1.01, -2.01, -2}, 194 new double[] {-1, -1.01, -2.01, -2, 0} 195 }; 196 197 // 5-step forecast 198 var startValues = original.Take(4); 199 var actualContinuations = from i in Enumerable.Range(1, original.Count() - 5) 200 select original.Skip(i).Take(5); 201 var predictedContinuations = estimated; 202 double expected = 1; // predictions are 100% correct 203 OnlineCalculatorError errorState; 204 double actual = OnlineDirectionalSymmetryCalculator.Calculate(startValues, actualContinuations, 205 predictedContinuations, out errorState); 206 Assert.AreEqual(expected, actual, 1E-9); 207 } 208 { 209 // only the direction is relevant 210 var estimated = new double[][] 211 { 212 new double[] {0.01, 0.01, 0.01, -0.01, -0.01}, // start=0, original deltas: 0.01, 1.01, 1.00, -1.00, -1.01 213 new double[] {0.02, 0.02, 0.00, 0.00, 0.00}, // start=0.01, original deltas: 1.00, 0.90, -1.01, -1.02, -2.02, 214 new double[] { 1.00, 1.00, 1.00, 1.00, 1.00}, // start=1.01, original deltas: -0.01, -2.01, -2.02, -3.02, -3.01 215 new double[] { 0.90, 0.90, 0.90, 0.90, 0.90} // start=1, original deltas: -2.00, -0.01, -3.01, -3.00, -1.00 216 }; 217 218 // 5-step forecast 219 var startValues = original.Take(4); 220 var actualContinuations = from i in Enumerable.Range(1, original.Count() - 5) 221 select original.Skip(i).Take(5); 222 var predictedContinuations = estimated; 223 double expected = 1; // half of the predicted deltas are correct 224 OnlineCalculatorError errorState; 225 double actual = OnlineDirectionalSymmetryCalculator.Calculate(startValues, actualContinuations, 226 predictedContinuations, out errorState); 227 Assert.AreEqual(expected, actual, 1E-9); 228 } 229 { 230 // also check incorrectly predicted directions 231 var estimated = new double[][] 232 { 233 new double[] {0.01, 0.01, 0.01, +0.01, +0.01}, // start=0, original deltas: 0.01, 1.01, 1.00, -1.00, -1.01 234 new double[] {0.02, 0.00, 0.02, 0.00, 0.00}, // start=0.01, original deltas: 1.00, 0.90, -1.01, -1.02, -2.02, 235 new double[] { 1.02, 1.00, 1.02, 1.00, 1.02}, // start=1.01, original deltas: -0.01, -2.01, -2.02, -3.02, -3.01 236 new double[] { 0.90, 0.90, 0.90, 0.90, 0.90} // start=1, original deltas: -2.00, -0.01, -3.01, -3.00, -1.00 237 }; 238 239 // 5-step forecast 240 var startValues = original.Take(4); 241 var actualContinuations = from i in Enumerable.Range(1, original.Count() - 5) 242 select original.Skip(i).Take(5); 243 var predictedContinuations = estimated; 244 double expected = (20 - 7) / 20.0; // half of the predicted deltas are correct 245 OnlineCalculatorError errorState; 246 double actual = OnlineDirectionalSymmetryCalculator.Calculate(startValues, actualContinuations, 247 predictedContinuations, out errorState); 248 Assert.AreEqual(expected, actual, 1E-9); 249 } 250 } 251 252 183 253 [TestMethod] 184 254 public void CalculateWeightedDirectionalSymmetryTest() { … … 199 269 Assert.AreEqual(expected, actual, 1E-9); 200 270 } 271 201 272 [TestMethod] 202 273 public void CalculateTheilsUTest() { … … 216 287 Assert.AreEqual(expected, actual, 1E-9); 217 288 } 289 290 [TestMethod] 291 public void CalculateMultiStepTheilsUTest() { 292 var original = new double[] { 0, 0.01, 1.01, 1, -1, -1.01, -2.01, -2, 0 }; 293 { 294 // prefect prediction 295 var estimated = new double[][] 296 { 297 new double[] {0.01, 1.01, 1, -1, -1.01}, 298 new double[] {1.01, 1, -1, -1.01, -2.01}, 299 new double[] {1, -1, -1.01, -2.01, -2}, 300 new double[] {-1, -1.01, -2.01, -2, 0} 301 }; 302 // 5-step forecast 303 var startValues = original.Take(4); 304 var actualContinuations = from i in Enumerable.Range(1, original.Count() - 5) 305 select original.Skip(i).Take(5); 306 var predictedContinuations = estimated; 307 308 double expected = 0; 309 OnlineCalculatorError errorState; 310 double actual = OnlineTheilsUStatisticCalculator.Calculate(startValues, actualContinuations, 311 predictedContinuations, out errorState); 312 Assert.AreEqual(expected, actual, 1E-9); 313 } 314 { 315 // naive prediction 316 var estimated = new double[][] 317 { 318 new double[] {0, 0, 0, 0, 0}, 319 new double[] {0.01, 0.01, 0.01, 0.01, 0.01}, 320 new double[] {1.01, 1.01, 1.01, 1.01, 1.01}, 321 new double[] {1, 1, 1, 1, 1} 322 }; 323 // 5-step forecast 324 var startValues = original.Take(4); 325 var actualContinuations = from i in Enumerable.Range(1, original.Count() - 5) 326 select original.Skip(i).Take(5); 327 var predictedContinuations = estimated; 328 329 double expected = 1; 330 OnlineCalculatorError errorState; 331 double actual = OnlineTheilsUStatisticCalculator.Calculate(startValues, actualContinuations, 332 predictedContinuations, out errorState); 333 Assert.AreEqual(expected, actual, 1E-9); 334 } 335 { 336 // realistic prediction 337 var estimated = new double[][] 338 { 339 new double[] {0.005, 0.5, 0.5, -0.5, -0.5}, // start = 0 340 new double[] {0.60, 0.5, -0.5, -0.5, -1}, // start = 0.01 341 new double[] {-0.005, 0, 0, -0.5, -1}, // start = 1.01 342 new double[] {-0, 0, -0.5, -1, 0.5} // start = 1 343 }; 344 // 5-step forecast 345 var startValues = original.Take(4); 346 var actualContinuations = from i in Enumerable.Range(1, original.Count() - 5) 347 select original.Skip(i).Take(5); 348 var predictedContinuations = estimated; 349 350 double expected = 0.47558387; 351 OnlineCalculatorError errorState; 352 double actual = OnlineTheilsUStatisticCalculator.Calculate(startValues, actualContinuations, 353 predictedContinuations, out errorState); 354 Assert.AreEqual(expected, actual, 1E-6); 355 } 356 } 357 218 358 [TestMethod] 219 359 public void CalculateAccuracyTest() {
Note: See TracChangeset
for help on using the changeset viewer.