1 43 44 package org.jfree.data.statistics.junit; 45 46 import junit.framework.Test; 47 import junit.framework.TestCase; 48 import junit.framework.TestSuite; 49 50 import org.jfree.data.statistics.Regression; 51 import org.jfree.data.xy.XYDataset; 52 import org.jfree.data.xy.XYSeries; 53 import org.jfree.data.xy.XYSeriesCollection; 54 55 58 public class RegressionTests extends TestCase { 59 60 65 public static Test suite() { 66 return new TestSuite(RegressionTests.class); 67 } 68 69 74 public RegressionTests(String name) { 75 super(name); 76 } 77 78 81 public void testOLSRegression1a() { 82 83 double[][] data = createSampleData1(); 84 double[] result1 = Regression.getOLSRegression(data); 85 assertEquals(.25680930, result1[0], 0.0000001); 86 assertEquals(0.72792106, result1[1], 0.0000001); 87 88 } 89 90 94 public void testOLSRegression1b() { 95 96 double[][] data = createSampleData1(); 97 98 XYSeries series = new XYSeries("Test"); 99 for (int i = 0; i < 11; i++) { 100 series.add(data[i][0], data[i][1]); 101 } 102 XYDataset ds = new XYSeriesCollection(series); 103 double[] result2 = Regression.getOLSRegression(ds, 0); 104 105 assertEquals(.25680930, result2[0], 0.0000001); 106 assertEquals(0.72792106, result2[1], 0.0000001); 107 108 } 109 110 113 public void testPowerRegression1a() { 114 115 double[][] data = createSampleData1(); 116 double[] result = Regression.getPowerRegression(data); 117 assertEquals(0.91045813, result[0], 0.0000001); 118 assertEquals(0.88918346, result[1], 0.0000001); 119 120 } 121 122 126 public void testPowerRegression1b() { 127 128 double[][] data = createSampleData1(); 129 130 XYSeries series = new XYSeries("Test"); 131 for (int i = 0; i < 11; i++) { 132 series.add(data[i][0], data[i][1]); 133 } 134 XYDataset ds = new XYSeriesCollection(series); 135 double[] result = Regression.getPowerRegression(ds, 0); 136 137 assertEquals(0.91045813, result[0], 0.0000001); 138 assertEquals(0.88918346, result[1], 0.0000001); 139 140 } 141 142 145 public void testOLSRegression2a() { 146 147 double[][] data = createSampleData2(); 148 double[] result = Regression.getOLSRegression(data); 149 assertEquals(53.9729697, result[0], 0.0000001); 150 assertEquals(-4.1823030, result[1], 0.0000001); 151 152 } 153 154 158 public void testOLSRegression2b() { 159 160 double[][] data = createSampleData2(); 161 162 XYSeries series = new XYSeries("Test"); 163 for (int i = 0; i < 10; i++) { 164 series.add(data[i][0], data[i][1]); 165 } 166 XYDataset ds = new XYSeriesCollection(series); 167 double[] result = Regression.getOLSRegression(ds, 0); 168 169 assertEquals(53.9729697, result[0], 0.0000001); 170 assertEquals(-4.1823030, result[1], 0.0000001); 171 172 } 173 174 177 public void testPowerRegression2a() { 178 179 double[][] data = createSampleData2(); 180 double[] result = Regression.getPowerRegression(data); 181 assertEquals(106.1241681, result[0], 0.0000001); 182 assertEquals(-0.8466615, result[1], 0.0000001); 183 184 } 185 186 190 public void testPowerRegression2b() { 191 192 double[][] data = createSampleData2(); 193 194 XYSeries series = new XYSeries("Test"); 195 for (int i = 0; i < 10; i++) { 196 series.add(data[i][0], data[i][1]); 197 } 198 XYDataset ds = new XYSeriesCollection(series); 199 double[] result = Regression.getPowerRegression(ds, 0); 200 201 assertEquals(106.1241681, result[0], 0.0000001); 202 assertEquals(-0.8466615, result[1], 0.0000001); 203 204 } 205 206 214 private double[][] createSampleData1() { 215 216 double[][] result = new double[11][2]; 217 218 result[0][0] = 2.00; 219 result[0][1] = 1.60; 220 result[1][0] = 2.25; 221 result[1][1] = 2.00; 222 result[2][0] = 2.60; 223 result[2][1] = 1.80; 224 result[3][0] = 2.65; 225 result[3][1] = 2.80; 226 result[4][0] = 2.80; 227 result[4][1] = 2.10; 228 result[5][0] = 3.10; 229 result[5][1] = 2.00; 230 result[6][0] = 2.90; 231 result[6][1] = 2.65; 232 result[7][0] = 3.25; 233 result[7][1] = 2.25; 234 result[8][0] = 3.30; 235 result[8][1] = 2.60; 236 result[9][0] = 3.60; 237 result[9][1] = 3.00; 238 result[10][0] = 3.25; 239 result[10][1] = 3.10; 240 241 return result; 242 243 } 244 245 250 private double[][] createSampleData2() { 251 252 double[][] result = new double[10][2]; 253 254 result[0][0] = 2; 255 result[0][1] = 56.27; 256 result[1][0] = 3; 257 result[1][1] = 41.32; 258 result[2][0] = 4; 259 result[2][1] = 31.45; 260 result[3][0] = 5; 261 result[3][1] = 30.05; 262 result[4][0] = 6; 263 result[4][1] = 24.69; 264 result[5][0] = 7; 265 result[5][1] = 19.78; 266 result[6][0] = 8; 267 result[6][1] = 20.94; 268 result[7][0] = 9; 269 result[7][1] = 16.73; 270 result[8][0] = 10; 271 result[8][1] = 14.21; 272 result[9][0] = 11; 273 result[9][1] = 12.44; 274 275 return result; 276 277 } 278 279 } 280 | Popular Tags |