import bpnn # Training data TRAINING = '/home/striegnk/teaching/csc106/code/data/ann/optdigits.training' # Data for testing by the same writers that produced the training data TESTING_1 = '/home/striegnk/teaching/csc106/code/data/ann/optdigits.same_writers_testing' # Data for testing by different writers than those that produced the training data TESTING_2 = '/home/striegnk/teaching/csc106/code/data/ann/optdigits.different_writers_testing' def read_data (filename) : """ This function reads in a file of training or testing data. Each line is one pattern. The last element on each line is the target output, everything before that are inputs. We are only interested in the digits 8 and 9, so filter out those lines and ignore the rest. See optdigits.names for a description of the data. """ fo = open(filename, 'r') patterns = [] for line in fo: line = line.strip() attributes = line.split(',') if attributes[-1] in ['8','9']: normalized_attributes = [] for a in attributes[:-1]: normalized_attributes.append(float(a)/16) target = [0,0] target[int(attributes[-1])-8] = 1 patterns.append([normalized_attributes, target]) fo.close() return patterns def main (training_data_filename, same_writers_test_data_filename, different_writers_test_data_filename) : # Read in the data from files and build lists of training and test patterns. training_patterns = read_data(training_data_filename) test_patterns_1 = read_data(same_writers_test_data_filename) test_patterns_2 = read_data(different_writers_test_data_filename) # ADD YOUR CODE HERE # Building your neural network: How many input units do you need? How many # output units? Have a look at the training and test patterns if you # are not sure. Use 2 hidden units. # Training your network: Training with all of the training patterns is pretty # slow. So train with just the first 100 patterns at first. Train for # 2000 iterations, instead of the default 1000, by passing 'iterations=2000' # as a parameter to the 'train' method. # Testing your network: You can run two tests: one using data by the same # people who produced the training data and one using data by # different people than the ones that produced the training data. main(TRAINING, TESTING_1, TESTING_2)