Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis/3.3/Tests/LinearScalingTest.cs @ 7461

Last change on this file since 7461 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic;
25using Microsoft.VisualStudio.TestTools.UnitTesting;
26namespace HeuristicLab.Problems.DataAnalysis.Tests {
27
28  [TestClass()]
29  public class LinearScalingTest {
30    [TestMethod]
31    public void CalculateScalingParametersTest() {
32      var testData = new double[,] {
33     {5,1,1,1,2,1,3,1,1,2},
34     {5,4,4,5,7,10,3,2,1,2},
35     {3,1,1,1,2,2,3,1,1,2},
36     {6,8,8,1,3,4,3,7,1,2},
37     {4,1,1,3,2,1,3,1,1,2},
38     {8,10,10,8,7,10,9,7,1,4},           
39     {1,1,1,1,2,10,3,1,1,2},             
40     {2,1,2,1,2,1,3,1,1,2},                 
41     {2,1,1,1,2,1,1,1,5,2},                 
42     {4,2,1,1,2,1,2,1,1,2},                   
43     {1,1,1,1,1,1,3,1,1,2},   
44     {2,1,1,1,2,1,2,1,1,2},                   
45     {5,3,3,3,2,3,4,4,1,4},                         
46     {8,7,5,10,7,9,5,5,4,4},         
47     {7,4,6,4,6,1,4,3,1,4},                         
48     {4,1,1,1,2,1,2,1,1,2},     
49     {4,1,1,1,2,1,3,1,1,2},     
50     {10,7,7,6,4,10,4,1,2,4}, 
51     {6,1,1,1,2,1,3,1,1,2},     
52     {7,3,2,10,5,10,5,4,4,4},   
53     {10,5,5,3,6,7,7,10,1,4}
54      };
55
56      double alpha, beta;
57      int n = testData.GetLength(0);
58      {
59        IEnumerable<double> x = from rows in Enumerable.Range(0, n)
60                                select testData[rows, 0];
61        IEnumerable<double> y = from rows in Enumerable.Range(0, n)
62                                select testData[rows, 1];
63        SymbolicRegressionScaledMeanSquaredErrorEvaluator.CalculateScalingParameters(x, y, out beta, out alpha);
64
65        Assert.AreEqual(alpha, 2.757281, 1.0E-6);
66        Assert.AreEqual(beta, 0.720267, 1.0E-6);
67
68        IEnumerable<double> scaledY = from value in y select value * beta + alpha;
69        Assert.AreEqual(x.Average(), scaledY.Average(), 1.0E-6);
70      }
71      {
72        IEnumerable<double> x = from rows in Enumerable.Range(0, n)
73                                select testData[rows, 2] * 1.0E3;
74        IEnumerable<double> y = from rows in Enumerable.Range(0, n)
75                                select testData[rows, 8] * 1.0E-3;
76        SymbolicRegressionScaledMeanSquaredErrorEvaluator.CalculateScalingParameters(x, y, out beta, out alpha);
77
78        IEnumerable<double> scaledY = from value in y select value * beta + alpha;
79        Assert.AreEqual(x.Average(), scaledY.Average(), 1.0E-6);
80      }
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.