def runNN(name): ''' Takes the Brent trajectories as input, shuffles them, and then runs the NN regression algorithm ''' rs = ReadSetupFile() #state, command = getStateAndCommandData(BrentTrajectoriesFolder) #stateAll, commandAll = dicToArray(state), dicToArray(command) #print ("old:", stateAll[0]) stateAll, commandAll = stateAndCommandDataFromTrajs( loadStateCommandPairsByStartCoords(pathDataFolder + "TrajRepository/")) #stateAll, commandAll = stateAndCommandDataFromTrajs(loadStateCommandPairsByStartCoords(BrentTrajectoriesFolder)) #print ("len:", len(commandAll[0])) stateAll = np.vstack(np.array(stateAll)) commandAll = np.vstack(np.array(commandAll)) #print ("len global:", len(commandAll)) #print ("new:", commandAll[0]) #this works because both shuffles generate the same order, due to the seed np.random.seed(0) np.random.shuffle(stateAll) np.random.seed(0) np.random.shuffle(commandAll) print("nombre d'echantillons: ", len(stateAll)) fa = NeuralNet(rs.inputDim, rs.outputDim) fa.getTrainingData(stateAll, commandAll) fa.train() fa.saveTheta(rs.NNpath + name + ".theta")
def runNN(name): ''' Takes the Brent trajectories as input, shuffles them, and then runs the NN regression algorithm ''' rs = ReadSetupFile() #state, command = getStateAndCommandData(BrentTrajectoriesFolder) #stateAll, commandAll = dicToArray(state), dicToArray(command) #print ("old:", stateAll[0]) stateAll, commandAll = stateAndCommandDataFromTrajs(loadStateCommandPairsByStartCoords(pathDataFolder + "TrajRepository/")) #stateAll, commandAll = stateAndCommandDataFromTrajs(loadStateCommandPairsByStartCoords(BrentTrajectoriesFolder)) #print ("len:", len(commandAll[0])) stateAll = np.vstack(np.array(stateAll)) commandAll = np.vstack(np.array(commandAll)) #print ("len global:", len(commandAll)) #print ("new:", commandAll[0]) #this works because both shuffles generate the same order, due to the seed np.random.seed(0) np.random.shuffle(stateAll) np.random.seed(0) np.random.shuffle(commandAll) print("nombre d'echantillons: ", len(stateAll)) fa = NeuralNet(rs.inputDim,rs.outputDim) fa.getTrainingData(stateAll, commandAll) fa.train() fa.saveTheta(rs.NNpath + name+".theta")
def UnitTestNN(): fa = NeuralNet(2, 3) input, output = [], [] for i in range(10000): x, y = rd.random(), rd.random() input.append([x, y]) output.append([x * y, x - y, x + y]) fa.getTrainingData(np.vstack(np.array(input)), np.vstack(np.array(output))) fa.train() fa.saveTheta("test.theta") fa.loadTheta("test.theta") for i in range(20): x, y = 3 * rd.random(), 3 * rd.random() approx = fa.computeOutput(np.array([x, y])) print("in:", [x, y]) print(" out:", approx) print(" real:", [x * y, x - y, x + y])
def UnitTestNN(): fa = NeuralNet(2,3) input, output = [], [] for i in range(10000): x,y = rd.random(), rd.random() input.append([x,y]) output.append([x*y, x-y, x+y]) fa.getTrainingData(np.vstack(np.array(input)), np.vstack(np.array(output))) fa.train() fa.saveTheta("test.theta") fa.loadTheta("test.theta") for i in range(20): x,y = 3*rd.random(), 3*rd.random() approx = fa.computeOutput(np.array([x,y])) print("in:", [x,y]) print(" out:", approx) print(" real:", [x*y, x-y, x+y])