001 package aima.test.learningtest.neural; 002 003 import java.util.List; 004 005 import junit.framework.TestCase; 006 import aima.learning.neural.NNExample; 007 import aima.learning.neural.RabbitEyeDataSet; 008 009 ; 010 011 public class DataSetTests extends TestCase { 012 013 public void testNormalizationOfFileBasedDataProducesCorrectMeanStdDevAndNormalizedValues() 014 throws Exception { 015 RabbitEyeDataSet reds = new RabbitEyeDataSet(); 016 reds.createNormalizedDataFromFile("rabbiteyes"); 017 018 List<Double> means = reds.getMeans(); 019 assertEquals(2, means.size()); 020 assertEquals(244.771, means.get(0), 0.001); 021 assertEquals(145.505, means.get(1), 0.001); 022 023 List<Double> stdev = reds.getStdevs(); 024 assertEquals(2, stdev.size()); 025 assertEquals(213.554, stdev.get(0), 0.001); 026 assertEquals(65.776, stdev.get(1), 0.001); 027 028 List<List<Double>> normalized = reds.getNormalizedData(); 029 assertEquals(70, normalized.size()); 030 031 // check first value 032 assertEquals(-1.0759, normalized.get(0).get(0), 0.001); 033 assertEquals(-1.882, normalized.get(0).get(1), 0.001); 034 035 // check last Value 036 assertEquals(2.880, normalized.get(69).get(0), 0.001); 037 assertEquals(1.538, normalized.get(69).get(1), 0.001); 038 } 039 040 public void testExampleFormation() throws Exception { 041 RabbitEyeDataSet reds = new RabbitEyeDataSet(); 042 reds.createExamplesFromFile("rabbiteyes"); 043 assertEquals(70, reds.howManyExamplesLeft()); 044 NNExample e = reds.getExampleAtRandom(); 045 assertEquals(69, reds.howManyExamplesLeft()); 046 NNExample e2 = reds.getExampleAtRandom(); 047 assertEquals(68, reds.howManyExamplesLeft()); 048 } 049 050 }