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