def cmaesf(x): evaluation = evaluationInter.evaluationInter(runtime=runtime) evaluation.updateHyperParams(x) result = evaluation.evaluation() y0 = -np.ones((1,1))*result[0] # seek minimum return y0[0]
def bo_penalty_f(x): evaluation = evaluationInter.evaluationInter(runtime=runtime) evaluation.updateHyperParams(x) result = evaluation.evaluation() if result[1] < 0: result[0] = result[0] + result[1]/500.0 # penalty item return result
def cmaes_initiateSafeSet(inputDimension): while True: x = (0.5-np.random.random((1, inputDimension)))*10 y = cmaesf(x) evaluation = evaluationInter.evaluationInter(runtime=runtime) evaluation.updateHyperParams(x) result = evaluation.evaluation() y = result[0] if y < -0.7 and y > -0.8 and result[2] is False: print('initial x :') print(x) print('initial y :') print(y) return x return x
rbfn = RBFN.RBFN(1, 5, 3, runtime) # indim, numCenters, outdim, time rbfn.setHyperParams(optimalX.reshape(5, 3)) timeInterval = safeopt.linearly_spaced_combinations([(0, runtime)], runtime * 10) priorities = np.zeros((3, 0)) for time in timeInterval: priorities = np.column_stack((priorities, rbfn.calOutput(time).T)) print(priorities) plt.figure() plt.plot(timeInterval, priorities[0], color='r') plt.plot(timeInterval, priorities[1], color='g') plt.plot(timeInterval, priorities[2], color='b') plt.ioff() displayResult = evaluationInter.evaluationInter(runtime=runtime) displayResult.updateHyperParams(optimalX) print(displayResult.evaluation()) JointAngleCurve = displayResult.getJointAngleCurve() JointTauCurve = displayResult.getJointTauCurve() JointAccelerationCurve = displayResult.getJointAccelerationCurve() txt_data = np.column_stack( (timeInterval, priorities.T, JointAccelerationCurve.T, JointAngleCurve.T)) np.savetxt( "/home/zhou/lee/safeLearningPriorities/mat_plot/robot_state/robotStates.txt", txt_data) '''np.savetxt("/home/zhou/lee/safeLearningPriorities/mat_plot/robot_state/JointAccelerationCurve.txt", JointAccelerationCurve.T) np.savetxt("/home/zhou/lee/safeLearningPriorities/mat_plot/robot_state/priorities.txt", priorities.T)
def f_c(x): evaluation = evaluationInter.evaluationInter(runtime=runtime) evaluation.updateHyperParams(x) result = evaluation.evaluation() return np.hstack([np.ones((1,1))*result[0], np.ones((1,1))*result[1]])