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 initNNController(rs): ''' Initializes the controller allowing to compute the output from the input and the vector of parameters theta Input: -rs: ReadSetupFile, parameters ''' #Initializes the function approximator fa = NeuralNet(rs.inputDim, rs.outputDim) return fa
def run(): net = NeuralNet(2, 1) plotInput(net) for i in range(5): print net.getTheta() plotOutputMap(net, i * 2) net.train() net.train() plotOutputMap(net, 10)
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 saveRandomNN(): rs = ReadSetupFile() fa = NeuralNet(rs.inputDim, rs.outputDim) fa.saveTheta(rs.NNpath + "Random.theta")
def createNN(name): rs = ReadSetupFile() fa = NeuralNet(rs.inputDim, rs.outputDim) fa.saveTheta(rs.NNpath + name + ".theta")