amount of trainings, the program runs a test with 500 different angle combinations, calculating the
mean error and the standard deviation. When training is finished, two weight matrices with the 
trained values are saved within the same path as the training file and an error function is plotted.
'''
from Class_Definitions import NeuralNetwork, ForwardKinematics
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import distance
import random

# Create a NeuralNetwork object.
inodes = 3
hnodes = 80
onodes = 3
learnrate = 1.3
net = NeuralNetwork(inodes, hnodes, onodes, learnrate)

# Create a ForwardKinematics object.
manipulator = ForwardKinematics(0, 1, 1, 1)

# Create an array containing all values, an angle can have (integers from -180 to 180 in this case).
angles = np.linspace(-180, 180, num=361, dtype=int)

# Create empty arrays to save the mean error and deviation after each test and plot the deviations
# and mean errors in the end.
deviationlist = []
meanerrorlist = []

# Number of times, the network is trained.
epochs = 200000
# Number of trainings, after which the network is tested.
mean error and the standard deviation. When training is finished, two weight matrices for each net
with the trained values are saved within the same path as the training file and an error function
is plotted.
'''
from Class_Definitions import NeuralNetwork, ForwardKinematics
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import distance
import random

# Create a NeuralNetwork object outputting the x-coordinate of the endeffector.
inodes_x = 1083
hnodes_x = 200
onodes_x = 401
lr_x = 0.4
net_x = NeuralNetwork(inodes_x, hnodes_x, onodes_x, lr_x)
# Create a NeuralNetwork object outputting the y-coordinate of the endeffector.
inodes_y = 1083
hnodes_y = 200
onodes_y = 401
lr_y = 0.4
net_y = NeuralNetwork(inodes_y, hnodes_y, onodes_y, lr_y)
# Create a NeuralNetwork object outputting the z-coordinate of the endeffector.
inodes_z = 1083
hnodes_z = 200
onodes_z = 401
lr_z = 0.4
net_z = NeuralNetwork(inodes_z, hnodes_z, onodes_z, lr_z)

# Create a ForwardKinematics object.
manipulator = ForwardKinematics(0, 1, 1, 1)
from Class_Definitions import NeuralNetwork
import numpy as np
import matplotlib.pyplot as plt
import random

# Create a NeuralNetwork object.
inodes = 101
hnodes = 40
onodes = 76
lr = 0.4
net = NeuralNetwork(inodes, hnodes, onodes, lr)

# Create empty arrays to plot the deviations and mean errors over the whole training
# process when finished.
deviationlist = []
meanerrorlist = []

# Number of times, the network is trained.
epochs = 10000
# Number of trainings, after which the network is tested.
test = epochs / 5

for e in range(epochs + 1):

    # Chose an input value of the range from 0 to 1, discretised to 2 decimals.
    x = random.choice(np.linspace(0, 1, num=101))
    # Create the input array with value 0.01 for each element
    xlist = np.zeros(inodes) + 0.01
    # Set the value of the index which results from the multiplication of x with 100 to 1.0.
    xlist[int(x * 100)] = 1.00
from Class_Definitions import NeuralNetwork
import numpy as np
import matplotlib.pyplot as plt
import random

# Create a NeuralNetwork object.
inodes = 1
hnodes = 500
onodes = 1
lr = 0.4
net = NeuralNetwork(inodes, hnodes, onodes, lr)

# Create empty arrays to plot the deviations and mean errors over the whole training
# process when finished.
deviationlist = []
meanerrorlist = []

# Number of times, the network is trained.
epochs = 60000
# Number of trainings, after which the network is tested.
test = epochs / 5

for e in range(epochs+1):

    # Set the input to a range between 0.01 and 1.00.
    x = ((random.random()) * 0.99) + 0.01
    y = 3 * x * (1 - x)

    # Define the target for the network avoiding 0 because it can not be reached by the
    # sigmoid activation function.
    target = y + 0.1
from Class_Definitions import NeuralNetwork
import numpy as np
import matplotlib.pyplot as plt
import random

# Create a NeuralNetwork object.
inodes = 101
hnodes = 60
onodes = 1
lr = 0.4
net = NeuralNetwork(inodes, hnodes, onodes, lr)

# Create empty arrays to plot the deviations and mean errors over the whole training
# process when finished.
deviationlist = []
meanerrorlist = []

# Number of times, the network is trained.
epochs = 10000
# Number of trainings, after which the network is tested.
test = epochs / 5

for e in range(epochs + 1):

    # Chose an input value of the range from 0 to 1, discretised to 2 decimals.
    x = random.choice(np.linspace(0, 1, num=101))
    # Create the input array with value 0.01 for each element
    xlist = np.zeros(inodes) + 0.01
    # Set the value of the index which results from the multiplication of x with 100 to 1.0.
    xlist[int(x * 100)] = 1.00
예제 #6
0
from Class_Definitions import NeuralNetwork
import numpy as np
import matplotlib.pyplot as plt
import random

# Create a NeuralNetwork object.
inodes = 1
hnodes = 40
onodes = 76
lr = 0.4
net = NeuralNetwork(inodes, hnodes, onodes, lr)

# Create empty arrays to plot the deviations and mean errors over the whole training
# process when finished.
deviationlist = []
meanerrorlist = []

# Number of times, the network is trained.
epochs = 40000
# Number of trainings, after which the network is tested.
test = epochs / 5

for e in range(epochs + 1):

    # Set the input to a range between 0.01 and 1.00.
    x = ((random.random()) * 0.99) + 0.01

    # Calculate the result for the given input with the function. Round the result to 2 decimals
    # which is the accuracy, the network is limited to due to the discretization of the output.
    y = (3 * x * (1 - x)).__round__(2)
    # Create the target array with value 0.01.
freedom are lines 12, 13, 14 and 23.
'''
from Class_Definitions import NeuralNetwork, ForwardKinematics
import numpy as np

# Type in the angles, for which the forward kinematics should be solved, in degree.
Theta1 = 0
Theta2 = 0
Theta3 = 23

# Initialize a neural network, named testnet, with the same parameters as the one you want to test.
inputnodes = 3
hiddennodes = 80
outputnodes = 3
learningrate = 1.3
testnet = NeuralNetwork(inputnodes, hiddennodes, outputnodes, learningrate)
# Load the weight matrices from the net you want to test into the testnet.
testnet.load('1DOF')

# Simulate a standard manipulator by initializing a ForwardKinematics object. It should have the same parameters
# like the one, the net was trained with.
manipulator = ForwardKinematics(0, 1, 1, 1)

# Set the input to a range between 0.01 and 1.00.
inputs = (((np.asarray([Theta1, Theta2, Theta3]) + 180) / 360) * 0.99) + 0.01
# Calculate the networks answer for given input.
output = testnet.query(inputs)
# Resize the outputs which are numbers between 0.2 and 0.8 so they match the real answer.
netanswer = (((output - 0.2) / 0.6) * 4) - 2
netanswer[2] = (((output[2] - 0.2) / 0.6) * 4) - 1
# Calculate the solutions of the forward kinematics for given input with homogenous transformation matrices.