def launchDDPGForSpecificTargetSizeAndSpeceficBeginning( sizeOfTarget, rs, point): ''' Run cmaes for a specific target sizeCMAES Input: -sizeOfTarget, size of the target, float -setuFile, file of setup, string -save, for saving result, bool ''' pos = point[0] x = point[1][0] y = point[1][1] print("Starting the DDPGor target " + str(sizeOfTarget) + " for point " + str(pos) + " !") foldername = rs.OPTIpath + str(sizeOfTarget) + "/" + str(pos) + "/" actor = simple_actor_network(rs.inputDim, rs.outputDim, l1_size=rs.hiddenLayers[0][1], l2_size=rs.hiddenLayers[1][1], learning_rate=rs.learningRate) env = DDPGEnv(rs, sizeOfTarget, "Best.theta", actor=actor, saveDir=foldername) env.setOnePointController(x, y) ddpg = DDPG(env, actor=actor) ddpg.M_episodes(rs.maxIterDDPG, train=False) print("End of optimization for target " + str(sizeOfTarget) + " for point " + str(pos) + " !")
def launchDDPGForSpecificTargetSizeAndSpeceficBeginning(sizeOfTarget, rs, point): """ Run cmaes for a specific target sizeCMAES Input: -sizeOfTarget, size of the target, float -setuFile, file of setup, string -save, for saving result, bool """ pos = point[0] x = point[1][0] y = point[1][1] print("Starting the DDPGor target " + str(sizeOfTarget) + " for point " + str(pos) + " !") foldername = rs.OPTIpath + str(sizeOfTarget) + "/" + str(pos) + "/" actor = simple_actor_network( rs.inputDim, rs.outputDim, l1_size=rs.hiddenLayers[0][1], l2_size=rs.hiddenLayers[1][1], learning_rate=rs.learningRate, ) env = DDPGEnv(rs, sizeOfTarget, "Best.theta", actor=actor, saveDir=foldername) env.setOnePointController(x, y) ddpg = DDPG(env, actor=actor) ddpg.M_episodes(rs.maxIterDDPG, train=False) print("End of optimization for target " + str(sizeOfTarget) + " for point " + str(pos) + " !")
def launchDDPGForSpecificTargetSize(sizeOfTarget, rs): actor = simple_actor_network(rs.inputDim, rs.outputDim, l1_size=rs.hiddenLayers[0][1], l2_size=rs.hiddenLayers[1][1], learning_rate=rs.learningRate) env = DDPGEnv(rs, sizeOfTarget, rs.thetaFile, actor=actor) ddpg = DDPG(env, actor=actor) ddpg.M_episodes(rs.maxIterDDPG, train=False)
def generateFromDDPG(repeat, rs, thetaFile, saveDir='Data'): for el in rs.sizeOfTarget: c = Chrono() actor = simple_actor_network(rs.inputDim, rs.outputDim, l1_size=rs.hiddenLayers[0][1], l2_size=rs.hiddenLayers[1][1], learning_rate=rs.learningRate) env = DDPGEnv(rs, el, rs.thetaFile, actor=actor, saveDir=saveDir) thetaName = rs.OPTIpath + str(el) + "/" + thetaFile + ".theta" saveName = rs.OPTIpath + str(el) + "/" + saveDir + "/" os.system("rm " + saveName + "Log/*.log 2>/dev/null") parameters = np.loadtxt(thetaName) actor.load_parameters(parameters) cost, time = env.saveAllTraj(repeat) c.stop() print("Average cost: ", cost) print("Average time: ", time) print("foldername : ", saveName) print("DDPG:End of generation")
def generateFromDDPG(repeat, rs, thetaFile, saveDir="Data"): for el in rs.sizeOfTarget: c = Chrono() actor = simple_actor_network( rs.inputDim, rs.outputDim, l1_size=rs.hiddenLayers[0][1], l2_size=rs.hiddenLayers[1][1], learning_rate=rs.learningRate, ) env = DDPGEnv(rs, el, rs.thetaFile, actor=actor, saveDir=saveDir) thetaName = rs.OPTIpath + str(el) + "/" + thetaFile + ".theta" saveName = rs.OPTIpath + str(el) + "/" + saveDir + "/" os.system("rm " + saveName + "Log/*.log 2>/dev/null") parameters = np.loadtxt(thetaName) actor.load_parameters(parameters) cost, time = env.saveAllTraj(repeat) c.stop() print("Average cost: ", cost) print("Average time: ", time) print("foldername : ", saveName) print("DDPG:End of generation")