Skip to content

Release 1

Preston Tranbarger edited this page Feb 22, 2019 · 23 revisions

Release 1

Constructor

Parameters

basicNeuralNet(nodes, learningRate)

The constructor passes 2 parameters: an array containing the amount of nodes in each layer, and a number that dictates the learning rate in stochastic gradient decent.

Example

nn = basicNeuralNet([2, 3, 1], 0.1)

This creates a object, called nn, of basicNeuralNet with 2 nodes in its input layer, 3 nodes in its 1st intermediate layer and 1 node in its output layer, and it sets the learning rate to be 0.1.

getNodes()

Parameters

getNodes()

There are no parameters for this method.

Return

This method returns the object’s stored value for the array nodes, an array which contains the number of nodes in each layer.

Example

nn = basicNeuralNet([2, 3, 1], 0.1)
print(nn.getNodes())

This prints:
[2, 3, 1]

getLearningRate()

Parameters

getLearningRate()

There are no parameters for this method.

Return

This method returns the objects stored value for the learning rate, a number which dictates the rate of stochastic gradient decent.

Example

nn = basicNeuralNet([2, 3, 1], 0.1)
print(nn.getLearningRate())

This prints:
0.1

getWeights()

Parameters

getWeights()

There are no parameters for this method.

Return

This method returns the object's stored value for weights, an array containing the weight of each connection between nodes.

Example

nn = basicNeuralNet([1, 2, 1], 0.1)
print(nn.getWeights())

This could print (output varies based off of the values stored in the object's weight array):
[[[0.835734567971406], [0.21740565479821994]], [[0.6464352637609099, 0.10556332348227149]]]

For details of how the weight array is created, please look at the code in the init method.

getWeight()

Parameters

getWeight(location)

This method passes 1 parameter: an array for the location of the weight in the object's weight array that you would like to return.

Return

This method returns an array of sub arrays leading up to the final desired weight value in the last index of the output.

Example

nn = basicNeuralNet([1, 2, 1], 0.1)
print(nn.getWeight([0, 0, 0])

This could print (output varies based off of the values stored in the object's weight array):
[[[[0.9582632173156346], [0.6728321531385041]], [[0.05023917599931649, 0.9551830456872886]]], [[0.9582632173156346], [0.6728321531385041]], [0.9582632173156346], 0.9582632173156346]

For details of how the weight array is created, please look at the code in the init method.

setWeight()

Parameters

setWeight(location, value)

This method passes 2 parameters: an array for the location of the weight in the object's weight array that you would like to change, and a number for the value you would like to change that weight to.

Return

This method returns an array of sub arrays for the location in the same way as getWeight() but with the new modified value. The first index in the output array is the new value of that object's weight array.

Example

nn = basicNeuralNet([1, 2, 1], 0.1)
print(nn.getWeights())
print(nn.setWeight([0, 0, 0], 1))
print(nn.getWeights())

This could print (output varies based off of the values stored in the object's weight array):

[[[0.46745166694341644], [0.6013006799015506]], [[0.22937081238412904, 0.7712979142797524]]]
[[[[1], [0.6013006799015506]], [[0.22937081238412904, 0.7712979142797524]]], [[1], [0.6013006799015506]], [1], 1]
[[[1], [0.6013006799015506]], [[0.22937081238412904, 0.7712979142797524]]]

For details of how the weight array is created, please look at the code in the init method.

nodeOutput()

Parameters

nodeOutput(inputValues, inputWeights)

This method passes 2 parameters: an array containing the weights of connections coming into the node from the previous layer, and an array containing the node outputs from the previous layer.

Return

This method returns the node output given the weights of the connections from the previous to the given node and the output values of the nodes in the previous layer given a sigmoid activation function.

Example

nn = basicNeuralNet([2, 3, 1], 0.1)
print(nn.nodeOutput([0.15, 0.61, 0.74], [0.15, 0.61, 0.74]))

This prints:
0.7195438328843728

networkOutput()

Parameters

networkOutput(inputValues)

This method passes 1 parameter: an array containing the values to be input into the input layer.

Return

This method returns an array containing the output values of the nodes in the output layer for a given array of inputs.

Example

nn = basicNeuralNet([2, 3, 2], 0.1)
print(nn.networkOutput([1,1]))

This could print (output varies based off of the values stored in the object's weight array):
[0.7101099400714266, 0.747699419970463]

For details of how the weight array is created, please look at the code in the init method.

cost()

Parameters

cost(dataSet)

This method passes 1 parameter: an array containing all of the data for the expected outputs of the network given certain inputs, the format for this dataSet will be shown in the example section of this method's documentation.

Return

This method returns the cost for the current neural network given an input dataSet.

Example

nn = basicNeuralNet([2, 3, 1], 0.1)
trainingData = [[[0, 0], [0]], [[0, 1], [1]], [[1, 0], [1]], [[1, 1], [0]]]
print(nn.cost(trainingData))

This could print (output varies based off of the values stored in the object's weight array):
1.1919172429014118

For details of how the weight array is created, please look at the code in the init method.

gradient()

Parameters

gradient(dataSet)

This method passes 1 parameter: an array containing all of the data for the expected outputs of the network given certain inputs, the format for this dataSet will be shown in the example section of this method's documentation.

Return

This method returns an array containing the partial derivatives of the cost function with respect to each weight in the neural network, and when interpreted as a vector is the gradient of the cost function.

Example

nn = basicNeuralNet([2, 3, 1], 0.1)
trainingData = [[[0, 0], [0]], [[0, 1], [1]], [[1, 0], [1]], [[1, 1], [0]]]
print(nn.gradient(trainingData))

This could print (output varies based off of the values stored in the object's weight array):
[0.01184385922670117, 0.014050982599655981, 0.02205347016115411, 0.025770496847599134, 0.026991742174686806, 0.027116087153444823, 0.21690427232101683, 0.21647128534141302, 0.2085931427586729]

For details of how the weight array is created, please look at the code in the init method.

optimize()

Parameters

to add...

Return

to add...

Example

to add...

Release 1.1

setLearningRate()

Parameters

setLearningRate(learningRate)

This method passes 1 parameter: a number that dictates the learning rate in stochastic gradient decent.

Return

This method returns None.

Example

nn = basicNeuralNet([2, 3, 1], 0.1)
print(nn.getLearningRate())
nn.setLearningRate(0.01)
print(nn.getLearningRate())

This prints:

0.1
0.01

Released 2/15/19 by QPU Misaligned

Clone this wiki locally