def run(rs): ''' Takes the Brent trajectories as input, shuffles them, and then runs the NN regression algorithm ''' #state, command = getStateAndCommandData(BrentTrajectoriesFolder) #stateAll, commandAll = dicToArray(state), dicToArray(command) #print ("old:", stateAll[0]) #stateAll, commandAll = stateAndCommandDataFromTrajs(loadStateCommandPairsByStartCoords(pathDataFolder + "Brent/", 0.1, rs.det)) stateAll, commandAll = loadTrajs(pathDataFolder + "Brent/", 1, rs.det) print("RunRegression L52") #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 = regressionDict[rs.regression](rs) fa.getTrainingData(stateAll, commandAll) fa.train() fa.saveTheta(rs.path+ rs.thetaFile+".theta")
def run(rs): ''' Takes the Brent trajectories as input, shuffles them, and then runs the NN regression algorithm ''' #state, command = getStateAndCommandData(BrentTrajectoriesFolder) #stateAll, commandAll = dicToArray(state), dicToArray(command) #print ("old:", stateAll[0]) #stateAll, commandAll = stateAndCommandDataFromTrajs(loadStateCommandPairsByStartCoords(pathDataFolder + "Brent/", 0.1, rs.det)) stateAll, commandAll = loadTrajs(pathDataFolder + "Brent/", 1, rs.det) print("RunRegression L52") #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 = regressionDict[rs.regression](rs) fa.getTrainingData(stateAll, commandAll) fa.train() fa.saveTheta(rs.path + rs.thetaFile + ".theta")
def testRegression(setupFile, thetaFile): """ """ rs=ReadXmlFile(setupFile) stateAll, commandAll = loadTrajs(pathDataFolder + "Brent/", 0.01, rs.det) stateAll=np.array(stateAll) arm=ArmType[rs.Arm]() trajReg = np.empty_like(stateAll) trajMaker = TrajMaker(rs,0.02,None,rs.path+thetaFile) for i in range(stateAll.shape[0]): coordHand = arm.mgdEndEffector(stateAll[i][0][2:]) trajReg[i]=trajMaker.runTrajectory2(coordHand[0], coordHand[1])[0] plotRegBrent(trajReg, stateAll)