def launchCMAESForSpecificTargetSize(sizeOfTarget, thetaFile, save): ''' Run cmaes for a specific target size Input: -sizeOfTarget, size of the target, float ''' print("Starting the CMAES Optimization for target " + str(sizeOfTarget) + " !") rs = ReadSetupFile() foldername = rs.CMAESpath + str(sizeOfTarget) + "/" thetaname = foldername + thetaFile if save: copyRBFNtoCMAES(rs, thetaFile, sizeOfTarget) #Initializes all the class used to generate trajectory exp = Experiments(rs, sizeOfTarget, False, foldername, thetaname, rs.popsizeCmaes, rs.period) theta = exp.tm.controller.theta thetaCMA = theta.flatten() #run the optimization (cmaes) resCma = cma.fmin(exp.runTrajectoriesCMAES, thetaCMA, rs.sigmaCmaes, options={ 'maxiter': rs.maxIterCmaes, 'popsize': rs.popsizeCmaes, 'CMA_diagonal': True, 'verb_log': 50, 'verb_disp': 1, 'termination_callback': term() }) print("End of optimization for target " + str(sizeOfTarget) + " !")
def GenerateRichDataFromTheta(rs, sizeOfTarget, foldername, thetaFile, repeat, save): exp = Experiments(rs, sizeOfTarget, save, foldername, thetaFile, rs.popsizeCmaes, rs.period) cost = exp.runRichTrajectories(repeat) print("Average cost: ", cost) print("foldername : ", foldername) if (save): exp.saveCost()
def GenerateDataFromTheta(rs, sizeOfTarget, foldername, thetaFile, repeat, save): exp = Experiments(rs, sizeOfTarget, save, foldername, thetaFile, rs.popsizeCmaes, rs.period) cost, time = exp.runTrajectoriesForResultsGeneration(repeat) print("Average cost: ", cost) print("Average time: ", time) print("foldername : ", foldername) if (save): exp.saveCost()
def launchCMAESForSpecificTargetSizeAndSpecificPoint(target_size, rs, save, point, noise=None): ''' Run cmaes for a specific target size Input: -target_size, size of the target, float -setuFile, file of setup, string -save: do we use a previous Best.theta file? True = Yes, False = use current controller, None = random controller noise: noise on muscle, if None, defalt noise from muscle setup, float ''' pos = point[0] x = point[1][0] y = point[1][1] print("Starting the CMAES Optimization for target " + str(target_size) + " for point " + str(pos) + " !") foldername = rs.OPTIpath + str(target_size) + "/" + str(pos) + "/" thetaname = foldername + "Best" if save: checkIfFolderExists(foldername) copyfile(rs.OPTIpath + str(target_size) + "/" + "Best.theta", foldername + "Best.theta") elif save == None: thetaname = None #Initializes all the class used to generate trajectory exp = Experiments(rs, target_size, False, foldername, thetaname, rs.popsizeCmaes, rs.period) if (noise != None): exp.setNoise(noise) theta = exp.tm.controller.getTheta() thetaCMA = theta.flatten() #run the optimization (cmaes) cma.fmin(partial(exp.runTrajectoriesCMAESOnePoint, x, y), thetaCMA, rs.sigmaCmaes, options={ 'maxiter': rs.maxIterCmaes, 'popsize': rs.popsizeCmaes, 'CMA_diagonal': True, 'verb_log': 0, 'verb_disp': 0, 'termination_callback': term() }) print("End of optimization for target " + str(target_size) + " for point " + str(pos) + " !")
def GenerateDataFromThetaOnePoint(rs, target_size, foldername, thetaFile, repeat, point): ''' Generate Data from a given theta file Input: -target_size, size of the target, float -save: do we save the results (false when running CMAES)? True = Yes, False = No ''' os.system("rm " + foldername + "/Log/*.log 2>/dev/null") exp = Experiments(rs, target_size, True, foldername, thetaFile, rs.popsizeCmaes, rs.period) cost, time = exp.runTrajectoriesForResultsGenerationOnePoint(repeat, point) print("Average cost: ", cost) print("Average time: ", time) print("foldername : ", foldername)
def GenerateRichDataFromTheta(rs, target_size, foldername, thetaFile, repeat, save): ''' Generate Data from a given theta file Input: -target_size, size of the target, float -save: do we save the results (false when running CMAES)? True = Yes, False = No ''' os.system("rm " + foldername + "Log/*.log") exp = Experiments(rs, target_size, save, foldername, thetaFile, rs.popsizeCmaes, rs.period) cost = exp.runRichTrajectories(repeat) print("Average cost: ", cost) print("foldername : ", foldername) if (save): exp.saveCost()
def launchCMAESMissing(rs, save, gamma, point): ''' Run cmaes for a specific target size Input: -target_size, size of the target, float -setuFile, file of setup, string -save: do we use a previous Best.theta file? True = Yes, False = use current controller, None = random controller ''' rs.gamma = gamma / 10.0 pos = point[0] x = point[1][0] y = point[1][1] target_size = point[2] print("Starting the CMAES Optimization for gamma = " + str(gamma) + ",target " + str(target_size) + " for point " + str(pos) + " !") foldername = rs.OPTIpathMissing + "gamma" + str(gamma) + "/" + str( target_size) + "/" + str(pos) + "/" thetaname = foldername + "Best" if save: checkIfFolderExists(foldername) copyfile( rs.OPTIpathMissing + "gamma" + str(gamma) + "/" + str(target_size) + "/" + "Best.theta", foldername + "Best.theta") elif save == None: thetaname = None #Initializes all the classes used to generate trajectory exp = Experiments(rs, target_size, False, foldername, thetaname, rs.popsizeCmaes, rs.period) theta = exp.tm.controller.getTheta() thetaCMA = theta.flatten() #run the optimization (cmaes) cma.fmin(partial(exp.runTrajectoriesCMAESOnePointMulti, x, y), thetaCMA, rs.sigmaCmaes, options={ 'maxiter': rs.maxIterCmaes, 'popsize': rs.popsizeCmaes, 'CMA_diagonal': True, 'verb_log': 0, 'verb_disp': 0, 'termination_callback': term() }) print("End of optimization for gamma = " + str(gamma) + ",target " + str(target_size) + " for point " + str(pos) + " !")
def launchCMAESForSpecificTargetSize(target_size, rs, save): ''' Run cmaes for a specific target size Input: -target_size, size of the target, float -setuFile, file of setup, string -save: do we use a previous Best.theta file? True = Yes, False = use current controller, None = random controller ''' print("Starting the CMAES Optimization for target " + str(target_size) + " !") foldername = rs.OPTIpath + str(target_size) + "/" if save: thetaname = foldername + rs.thetaFile copyRegressiontoCMAES(rs, rs.thetaFile, target_size) else: thetaname = foldername + "Best" #Initializes all the class used to generate trajectory exp = Experiments(rs, target_size, False, foldername, thetaname, rs.popsizeCmaes, rs.period) theta = exp.tm.controller.getTheta() thetaCMA = theta.flatten() #run the optimization (cmaes) cma.fmin(exp.runTrajectoriesCMAES, thetaCMA, rs.sigmaCmaes, options={ 'maxiter': rs.maxIterCmaes, 'popsize': rs.popsizeCmaes, 'CMA_diagonal': True, 'verb_log': 50, 'verb_disp': 1, 'termination_callback': term() }) print("End of optimization for target " + str(target_size) + " !")
def GenerateDataFromThetaNController(rs, target_size, foldername, thetaFile, repeat, save, noise=None): ''' Generate Data from a given theta file Input: -target_size, size of the target, float -save: do we save the results (false when running CMAES)? True = Yes, False = No ''' os.system("rm " + foldername + "/Log/*.log 2>/dev/null") exp = Experiments(rs, target_size, save, foldername, None, rs.popsizeCmaes, rs.period) if (noise != None): exp.setNoise(noise) cost, time = exp.runTrajectoriesForResultsGenerationNController( repeat, thetaFile) print("Average cost: ", cost) print("Average time: ", time) print("foldername : ", foldername) if (save): exp.saveCost()
from Utils.Chrono import Chrono from Utils.ReadXmlFile import ReadXmlFile from Utils.FileReading import loadTrajForModel from Experiments.Experiments import Experiments from GlobalVariables import pathDataFolder from Regression.NeuraNetTF import NeuralNetTF import numpy as np rs=ReadXmlFile("setupNN1th.xml") foldername = rs.CMAESpath + str(0.04) + "/" thetaname = foldername + rs.thetaFile exp = Experiments(rs, 0.04, False, foldername, thetaname,rs.popsizeCmaes,rs.period, "Inv") #exp2 = Experiments(rs, 0.04, False, foldername, thetaname,rs.popsizeCmaes,rs.period,"Reg") exp3 = Experiments(rs, 0.04, False, foldername, thetaname,rs.popsizeCmaes,rs.period,"Hyb") ''' c=Chrono() for i in range(30): cost, time = exp.runMultiProcessTrajectories(10) c.stop() print("Average cost: ", cost) print("Average time: ", time) ''' stateAndCommand, nextState = loadTrajForModel(pathDataFolder + "Brent/", 10) #stateAndCommand, nextState = loadTrajForModel(pathDataFolder + "CMAEScluster/0.02/cluster/Log/", 10) state=stateAndCommand[:,:4] command=stateAndCommand[:,4:] #exp2.tm.stateEstimator.initStore(state) exp3.tm.stateEstimator.initStore(state)