Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 7239 was 4459, checked in by gkronber, 14 years ago

Fixed data analysis test cases. #1142

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.IO;
23using System;
24using HeuristicLab.Random;
25using HeuristicLab.Common;
26using System.Collections.Generic;
27using System.Diagnostics;
28using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
29using HeuristicLab.Problems.DataAnalysis.Symbolic;
30using Microsoft.VisualStudio.TestTools.UnitTesting;
31using System.Linq;
32using System.Globalization;
33using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic;
34namespace HeuristicLab.Problems.DataAnalysis.Tests {
35
36  [TestClass()]
37  public class LinearScalingTest {
38    [TestMethod]
39    public void CalculateScalingParametersTest() {
40      var testData = new double[,] {
41     {5,1,1,1,2,1,3,1,1,2},
42     {5,4,4,5,7,10,3,2,1,2},
43     {3,1,1,1,2,2,3,1,1,2},
44     {6,8,8,1,3,4,3,7,1,2},
45     {4,1,1,3,2,1,3,1,1,2},
46     {8,10,10,8,7,10,9,7,1,4},           
47     {1,1,1,1,2,10,3,1,1,2},             
48     {2,1,2,1,2,1,3,1,1,2},                 
49     {2,1,1,1,2,1,1,1,5,2},                 
50     {4,2,1,1,2,1,2,1,1,2},                   
51     {1,1,1,1,1,1,3,1,1,2},   
52     {2,1,1,1,2,1,2,1,1,2},                   
53     {5,3,3,3,2,3,4,4,1,4},                         
54     {8,7,5,10,7,9,5,5,4,4},         
55     {7,4,6,4,6,1,4,3,1,4},                         
56     {4,1,1,1,2,1,2,1,1,2},     
57     {4,1,1,1,2,1,3,1,1,2},     
58     {10,7,7,6,4,10,4,1,2,4}, 
59     {6,1,1,1,2,1,3,1,1,2},     
60     {7,3,2,10,5,10,5,4,4,4},   
61     {10,5,5,3,6,7,7,10,1,4}
62      };
63
64      double alpha, beta;
65      int n = testData.GetLength(0);
66      {
67        IEnumerable<double> x = from rows in Enumerable.Range(0, n)
68                                select testData[rows, 0];
69        IEnumerable<double> y = from rows in Enumerable.Range(0, n)
70                                select testData[rows, 1];
71        SymbolicRegressionScaledMeanSquaredErrorEvaluator.CalculateScalingParameters(x, y, out beta, out alpha);
72
73        Assert.AreEqual(alpha, 2.757281, 1.0E-6);
74        Assert.AreEqual(beta, 0.720267, 1.0E-6);
75
76        IEnumerable<double> scaledY = from value in y select value * beta + alpha;
77        Assert.AreEqual(x.Average(), scaledY.Average(), 1.0E-6);
78      }
79      {
80        IEnumerable<double> x = from rows in Enumerable.Range(0, n)
81                                select testData[rows, 2] * 1.0E3;
82        IEnumerable<double> y = from rows in Enumerable.Range(0, n)
83                                select testData[rows, 8] * 1.0E-3;
84        SymbolicRegressionScaledMeanSquaredErrorEvaluator.CalculateScalingParameters(x, y, out beta, out alpha);
85
86        IEnumerable<double> scaledY = from value in y select value * beta + alpha;
87        Assert.AreEqual(x.Average(), scaledY.Average(), 1.0E-6);
88      }
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.