1 """Provide classes for dealing with Training Neural Networks.
2 """
3
4 import random
5
6
8 """Hold inputs and outputs of a training example.
9
10 XXX Do I really need this?
11 """
12 - def __init__(self, inputs, outputs, name=""):
13 self.name = name
14 self.inputs = inputs
15 self.outputs = outputs
16
17
19 """Manage a grouping of Training Examples.
20
21 This is meant to make it easy to split a bunch of training examples
22 into three types of data:
23
24 o Training Data -- These are the data used to do the actual training
25 of the network.
26
27 o Validation Data -- These data are used to validate the network
28 while training. They provide an independent method to evaluate how
29 the network is doing, and make sure the network gets trained independent
30 of noise in the training data set.
31
32 o Testing Data -- The data which are used to verify how well a network
33 works. They should not be used at all in the training process, so they
34 provide a completely independent method of testing how well a network
35 performs.
36 """
37 - def __init__(self, training_percent=.4, validation_percent=.4):
38 """Initialize the manager with the training examples.
39
40 Arguments:
41
42 o training_percent - The percentage of the training examples that
43 should be used for training the network.
44
45 o validation_percent - Percent of training examples for validating
46 a network during training.
47
48 Attributes:
49
50 o train_examples - A randomly chosen set of examples for training
51 purposes.
52
53 o valdiation_examples - Randomly chosesn set of examples for
54 use in validation of a network during training.
55
56 o test_examples - Examples for training purposes.
57 """
58 assert training_percent + validation_percent <= 1.0, \
59 "Training and validation percentages more than 100 percent"
60
61 self.train_examples = []
62 self.validation_examples = []
63 self.test_examples = []
64
65 self.training_percent = training_percent
66 self.validation_percent = validation_percent
67
69 """Add a set of training examples to the manager.
70
71 Arguments:
72
73 o training_examples - A list of TrainingExamples to manage.
74 """
75 placement_rand = random.Random()
76
77
78 for example in training_examples:
79 chance_num = placement_rand.random()
80
81 if chance_num <= self.training_percent:
82 self.train_examples.append(example)
83 elif chance_num <= (self.training_percent +
84 self.validation_percent):
85 self.validation_examples.append(example)
86 else:
87 self.test_examples.append(example)
88