def __init__(self, number_of_hidden_nodes=15, learning_rate = .1, edge_probability = 1.0): """ Arguments: --------- number_of_hidden_nodes : the number of hidden nodes on one layer learning_rate : the learning rate that we start at. this decays every time we enter a new epoch edge_probability : probability that a node will have an edge with its parent node Returns: -------- Nothing Description: ----------- Our custom network uses two new strategies for generating hypothesis. Firstly, it uses a decaying learning_rate. After every epoch, we decrease the learning rate. We give it a lower bound of .0001 Secondly, every time we generate a new hidden node our output node, we set a probability p that it is connected to any one of its potential parent nodes. We no longer have a connected graph, but by reducing the complexity we can potentially reduce overfitting. """ super(CustomNetwork, self).__init__() # <Don't remove this line> self.learning_rate = learning_rate # every epoch, we reduce the learning rate def DecayingLRateTrain(network, inputs, targets, learning_rate, epochs): network.CheckComplete() for e in range(epochs): for input, target in zip(inputs, targets): Backprop(network, input, target, self.learning_rate) self.learning_rate = max(self.learning_rate - (self.learning_rate/25.), .0001) # new training function uses decaying learning rate self.RegisterTrainFunction(DecayingLRateTrain) # 1) Adds an input node for each pixel for i in range(36): new_input = Node() self.network.AddNode(new_input, NeuralNetwork.INPUT) # 2) Adds the hidden layer for i in range(number_of_hidden_nodes): new_hidden = Node() self.network.AddNode(new_hidden, NeuralNetwork.HIDDEN) for input_node in self.network.inputs: if random.random() < .9: new_hidden.AddInput(input_node, None, self.network) # 3) Adds an output node for each possible digit label. for i in range(2): new_output = Node() self.network.AddNode(new_output, NeuralNetwork.OUTPUT) for hidden_node in self.network.hidden_nodes: if random.random() < .9: new_output.AddInput(hidden_node, None, self.network)
def __init__(self): """ Arguments: --------- Nothing Returns: ------- Nothing Description: ----------- Initializes a simple network, with 196 input nodes, 10 output nodes, and NO hidden nodes. Each input node should be connected to every output node. """ super(SimpleNetwork, self).__init__() # 1) Adds an input node for each pixel. for i in range(196): toAdd = Node() self.network.AddNode(toAdd, NeuralNetwork.INPUT) # 2) Add an output node for each possible digit label. for i in range(10): toAdd = Node() self.network.AddNode(toAdd, NeuralNetwork.OUTPUT) for i in range(196): toAdd.AddInput(self.network.inputs[i], False, self.network) pass
def __init__(self): """ Arguments: --------- Nothing Returns: ------- Nothing Description: ----------- Initializes a simple network, with 196 input nodes, 10 output nodes, and NO hidden nodes. Each input node should be connected to every output node. """ super(SimpleNetwork, self).__init__() # 1) Adds an input node for each pixel. for i in range(36): self.network.AddNode(Node(), 1) # 2) Add an output node for each possible digit label. for i in range(1): node = Node() self.network.AddNode(node, 3) for j in range(36): node.AddInput(self.network.inputs[j], None, self.network) self.network.complete = True self.network.MarkAsComplete()
def __init__(self): """ Arguments: --------- Nothing Returns: ------- Nothing Description: ----------- Initializes a simple network, with 196 input nodes, 10 output nodes, and NO hidden nodes. Each input node should be connected to every output node. """ super(SimpleNetwork, self).__init__() # < Don't remove this line > # 1) Adds an input node for each pixel. for i in range(36): new_input = Node() self.network.AddNode(new_input, NeuralNetwork.INPUT) # 2) Add an output node for each possible digit label. for i in range(2): new_output = Node() self.network.AddNode(new_output, NeuralNetwork.OUTPUT) for input_node in self.network.inputs: new_output.AddInput(input_node, None, self.network)
def __init__(self, number_of_hidden_nodes=10, number_of_layers=2): """ Arguments: --------- number_of_hidden_nodes : the number of hidden nodes to create per layer (an integer) number_of_layers : the number of layers of hidden nodes Returns: -------- Your pick Description: ----------- Network with multiple hidden layers, all of the same size. All layers fully connected. """ super(CustomNetwork, self).__init__() # 1) Adds an input node for each pixel for i in range(36): self.network.AddNode(Node(), 1) # 2) Adds the first hidden layer for i in range(number_of_hidden_nodes): node = Node() self.network.AddNode(node, 2) for j in range(36): node.AddInput(self.network.inputs[j], None, self.network) # 2) Adds the next hidden layer(s) for k in range(number_of_layers - 1): for i in range(number_of_hidden_nodes): node = Node() self.network.AddNode(node, 2) for j in range(number_of_hidden_nodes): node.AddInput( self.network.hidden_nodes[number_of_hidden_nodes * k + j], None, self.network) # 3) Adds an output node for each possible digit label. for i in range(1): node = Node() self.network.AddNode(node, 3) for j in range(number_of_hidden_nodes): node.AddInput( self.network.hidden_nodes[number_of_hidden_nodes * (number_of_layers - 1) + j], None, self.network) self.network.complete = True self.network.MarkAsComplete()
def __init__(self, number_of_hidden_nodes=160): """ Arguments: --------- number_of_hidden_nodes : the number of hidden nodes to create (an integer) Returns: ------- Nothing Description: ----------- Initializes a network with a hidden layer. The network should have 196 input nodes, the specified number of hidden nodes, and 10 output nodes. The network should be, again, fully connected. That is, each input node is connected to every hidden node, and each hidden_node is connected to every output node. """ super(HiddenNetwork, self).__init__() # 1) Adds an input node for each pixel for i in range(196): toAdd = Node() self.network.AddNode(toAdd, NeuralNetwork.INPUT) # 2) Adds the hidden layer for i in range(number_of_hidden_nodes): toAdd = Node() self.network.AddNode(toAdd, NeuralNetwork.HIDDEN) for i in range(196): toAdd.AddInput(self.network.inputs[i], False, self.network) # 3) Adds an output node for each possible digit label. for i in range(10): toAdd = Node() self.network.AddNode(toAdd, NeuralNetwork.OUTPUT) for i in range(number_of_hidden_nodes): toAdd.AddInput(self.network.hidden_nodes[i], False, self.network) print "weights len: " + str(len(self.network.weights)) pass
def __init__(self, number_of_hidden_nodes=10): """ Arguments: --------- number_of_hidden_nodes : the number of hidden nodes to create (an integer) Returns: ------- Nothing Description: ----------- Initializes a network with a hidden layer. The network should have 196 input nodes, the specified number of hidden nodes, and 10 output nodes. The network should be, again, fully connected. That is, each input node is connected to every hidden node, and each hidden_node is connected to every output node. """ super(HiddenNetwork, self).__init__() # 1) Adds an input node for each pixel for i in range(36): self.network.AddNode(Node(), 1) # 2) Adds the hidden layer for i in range(number_of_hidden_nodes): node = Node() self.network.AddNode(node, 2) for j in range(36): node.AddInput(self.network.inputs[j], None, self.network) # 3) Adds an output node for each possible digit label. for i in range(1): node = Node() self.network.AddNode(node, 3) for j in range(number_of_hidden_nodes): node.AddInput(self.network.hidden_nodes[j], None, self.network) self.network.complete = True self.network.MarkAsComplete()
def __init__(self, number_of_hidden_nodes=30): """ Arguments: --------- number_of_hidden_nodes : the number of hidden nodes to create (an integer) Returns: ------- Nothing Description: ----------- Initializes a network with a hidden layer. The network should have 196 input nodes, the specified number of hidden nodes, and 10 output nodes. The network should be, again, fully connected. That is, each input node is connected to every hidden node, and each hidden_node is connected to every output node. """ super(HiddenNetwork, self).__init__() # < Don't remove this line > # 1) Adds an input node for each pixel for i in range(36): new_input = Node() self.network.AddNode(new_input, NeuralNetwork.INPUT) # 2) Adds the hidden layer for i in range(number_of_hidden_nodes): new_hidden = Node() self.network.AddNode(new_hidden, NeuralNetwork.HIDDEN) for input_node in self.network.inputs: new_hidden.AddInput(input_node, None, self.network) # 3) Adds an output node for each possible digit label. for i in range(2): new_output = Node() self.network.AddNode(new_output, NeuralNetwork.OUTPUT) for hidden_node in self.network.hidden_nodes: new_output.AddInput(hidden_node, None, self.network)
def __init__(self, firstlayer=15, secondlayer=15): """ Arguments: --------- Your pick. Returns: -------- Nothing Description: ----------- Commented out code trains a single hidden layer with a large number of hidden units. Alternate code trains two hidden layers. """ super(CustomNetwork, self).__init__() """ # 1) Adds an input node for each pixel for i in range(196): toAdd = Node() self.network.AddNode(toAdd, NeuralNetwork.INPUT) # 2) Adds the hidden layer for i in range(183): toAdd = Node() self.network.AddNode(toAdd, NeuralNetwork.HIDDEN) for i in range(196): toAdd.AddInput(self.network.inputs[i], False, self.network) # 3) Adds an output node for each possible digit label. for i in range(10): toAdd = Node() self.network.AddNode(toAdd, NeuralNetwork.OUTPUT) for i in range(183): toAdd.AddInput(self.network.hidden_nodes[i], False, self.network) """ # 1) Adds an input node for each pixel for i in range(196): toAdd = Node() self.network.AddNode(toAdd, NeuralNetwork.INPUT) # 2) Adds the first hidden layer for i in range(firstlayer): toAdd = Node() self.network.AddNode(toAdd, NeuralNetwork.HIDDEN) for j in range(196): toAdd.AddInput(self.network.inputs[j], False, self.network) # 3) Add the second hidden layer for i in range(secondlayer): toAdd = Node() self.network.AddNode(toAdd, NeuralNetwork.HIDDEN) for j in range(firstlayer): toAdd.AddInput(self.network.hidden_nodes[j], False, self.network) # 4) Adds an output node for each possible digit label. for i in range(10): toAdd = Node() self.network.AddNode(toAdd, NeuralNetwork.OUTPUT) for j in range(firstlayer, firstlayer+secondlayer): toAdd.AddInput(self.network.hidden_nodes[j], False, self.network) pass