我是我自己创建的具有5000个数据点的数据集。利用这些数据,我建立了一个网络来训练1个隐藏层。
我将tangent-Sigmoid(tanh)激活函数用于隐藏的神经元,并将线性激活函数用于输出层。我使用张量板来可视化结果的准确性和损失。
问题是我的图表(看图中)非常模糊并且含义更少。而且我的准确率不会超过40%。而且网络似乎并不像以前那样倾斜。
我的假设是,我的数据输入方法有问题。请帮帮我。import random
import math
import csv
import numpy as np
from matplotlib import pyplot as plt
from sklearn import preprocessing
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.callbacks import TensorBoard
linkLength = 2
def Xe (a,b,c):
return linkLength*math.cos(a)+linkLength*math.cos(a+b)+linkLength*math.cos(a+b+c)
def Ye (e,f,g):
return linkLength*math.sin(e) + linkLength*math.sin(e + f) + linkLength*math.sin(e + f + g)
def tita (h,i,j):
return math.degrees(h)+math.degrees(i)+math.degrees(j)
Q1 = []
Q2 = []
Q3 = []
posX = []
posY = []
titaEnd = []
# data set creation
for i in range (0,5000):
q1= round(random.uniform(0,math.pi),2)
q2= round(random.uniform(-math.pi,0),2)
q3= round(random.uniform(-math.pi/2, math.pi/2), 2)
Q1.append(q1)
Q2.append(q2)
Q3.append(q3)
posX.append(Xe(q1,q2,q3))
posY.append(Ye(q1,q2,q3))
titaEnd.append(tita(q1,q2,q3))
for i in range(0,len(posX)):
plt.plot([posX[i],posX[i]+0.2*math.cos(math.radians(titaEnd[i]))],[posY[i],posY[i]+0.2*math.sin(math.radians(titaEnd[i]))],'k-')
plt.scatter(posX,posY)
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.title("data set of 1000 possible endeffector positions and orientations")
plt.show()
dataMat =np.c_[Q1,Q2,Q3,posX,posY,titaEnd]
#removing duplicated end effeector positions
for i in range (0,4999):
check1 = dataMat[i,3]
check2 = dataMat[i,4]
check3 = dataMat[i,5]
for j in range (0,4999):
if i != j:
#print(i,j,'checking..')
if (dataMat[j,3] == check1 and dataMat[j,4] == check2 and dataMat[j,5] == check3):
print(i,j,dataMat[j,3],dataMat[j,4],dataMat[j,5])
#Preprocessing
MinMaxNorm = preprocessing.minmax_scale(dataMat,(-1,1))
plt.scatter(MinMaxNorm[:,3],MinMaxNorm[:,4])
plt.title("Preprocessed data")
plt.show()
#print(MinMaxNorm)
data =MinMaxNorm[:,[3,4,5]]
output =MinMaxNorm[:,[0,1,2]]
#Building NN
random.shuffle(data)
random.shuffle(output)
model = keras.Sequential()
model.add(keras.layers.Dense(100, activation ='tanh'))
model.add(keras.layers.Dense(3, activation ='linear'))
NAME = "Trajectry Tracking"
tensorboard = TensorBoard(log_dir="logs/{}".format(NAME))
model.compile(optimizer=tf.train.AdamOptimizer(0.01),loss='mse',metrics=['accuracy']) # mean squared error
model.fit(data,output, epochs=20, batch_size =40, callbacks=[tensorboard])
model.evaluate(data,output)
#_Tensor Board
#tensorboard --logdir=logs/`