def goalBabble(self, x): print("Doing goal babbling now\n") p = self.net.params p[:] = x[3] i = 0 self.sMemory = np.array([1] * (INPUTSIZE + PREDICTSIZE)) self.mMemory = np.array([0] * OUTPUTSIZE) self.rest() sensedAngles = self.get_sensor_values() pv = sensedAngles[x[2]] #Choose a goal sensor value in the range of the predicted angle #self.randomGoal = self.rand.uniform(self.Body[x[1]][0],self.Body[x[1]][1]) self.randomGoal = self.rand.uniform(-0.5, 0.5) print(self.randomGoal) #CMA-ES can be used to discover joint angles that get #closer to the goal state!!!!!!!! self.x1 = x[1] self.x2 = x[2] res = cma.fmin(self.calcGoalScore, 0.1 * (np.random.random_sample(2, ) - 0.5), 0.5, maxfevals=500, verb_disp=1, bounds=[self.Body[x[1]][0], self.Body[x[1]][1]]) cma.plot() cma.show()
def goalBabble(self, x): print("Doing goal babbling now\n") p = self.net.params p[:] = x[3] i = 0 self.sMemory = np.array([1]*(INPUTSIZE + PREDICTSIZE)) self.mMemory = np.array([0]*OUTPUTSIZE) self.rest() sensedAngles = self.get_sensor_values() pv = sensedAngles[x[2]] #Choose a goal sensor value in the range of the predicted angle #self.randomGoal = self.rand.uniform(self.Body[x[1]][0],self.Body[x[1]][1]) self.randomGoal = self.rand.uniform(-0.5,0.5) print(self.randomGoal) #CMA-ES can be used to discover joint angles that get #closer to the goal state!!!!!!!! self.x1 = x[1] self.x2 = x[2] res = cma.fmin(self.calcGoalScore, 0.1*(np.random.random_sample(2,)-0.5), 0.5,maxfevals=500, verb_disp=1, bounds=[self.Body[x[1]][0], self.Body[x[1]][1]] ) cma.plot() cma.show()
def main(self): # 500g foot at 18cm : addedInertia = 0.0162 self.updateModelConstants(12, self.i0, self.ke, self.r, self.klin, self.linearTransition, self.staticFriction, self.coulombFriction, addedInertia) self.simulationTest(0.7) return # print self # T = numpy.arange(0, 1, 0.0001) # timedCommands = zip(T, itertools.repeat(8)) # self.updateModelConstants(12, self.i0, self.ke, self.r, self.klin, self.linearTransition, self.staticFriction, self.coulombFriction) # self.simulation(timedCommands, 0, 0, printIt=True) # # return print "Initial model values :" print "voltage = ", self.voltage #12 print "io = ", self.i0 #0.00353 print "ke = ", self.ke #1.6 print "r = ", self.r #5.86 print "klin = ", self.klin #-1.60368670825 print "linearTransition = ", self.linearTransition #0.306796157577 print "staticFriction = ", self.staticFriction #0.150170648464 print "coulombFriction = ", self.coulombFriction #0.0750853242321 print "addedInertia = ", self.addedInertia#0.004 listOfMeasures = self.readMeasures("measures/completeTest", timeLimit=0.150, typeOffset=0) listOfMeasuresheavyLoad = self.readMeasures("measures/completeTestHeavyLoad", timeLimit=0.150, typeOffset=10) #Adding the heavy load measures listOfMeasures.extend(listOfMeasuresheavyLoad) #Max speed is 4PI/s = 120 rpm self.fixGaps(listOfMeasures, 4*math.pi) self.noDisplay = False #self.noDisplay = True #value = self.evaluateModelForMeasures(listOfMeasures, 12, self.i0, self.ke, self.r, self.klin, self.linearTransition, self.staticFriction, self.coulombFriction) #print value #tolfun 100 # value = self.evaluateModelForMeasures(listOfMeasures, 12, -0.0017217180565952648, 3.9265053688586535, 4.4190475060541337, -1.642030980764918, -0.19456964024780998, 0.19221036872483038, 0.60201284035701119) #tolfun 100 with limits on values # value = self.evaluateModelForMeasures(listOfMeasures, 12, 0.00905955, 3.29605672, 1.63030819, -1.6484249, 0.04996982, 0.19198735, 0.21656958) #tolfun 100 with limits on values # value = self.evaluateModelForMeasures(listOfMeasures, 12, 0.00794687, 1.49117495, 0.85706012, 1.64383661, -0.04078583, 0.07417589, 0.30257492) # value = self.evaluateModelForMeasures(listOfMeasures, 12, 0.0034689028202296171, 1.555666164824836, 1.1287356922053267, 1.6444843194436245, 0.41284770773063401, 0.1294117709539814, 0.29580470901307804) #tolfun 80 : # [0.0021731366250028568, 1.355067751766774, 0.94623234209939366, 1.6460100334124927, 0.027949448057014062, 0.12011789072794421, 0.27722890096104058] #Score of 5.27 # value = self.evaluateModelForMeasures(listOfMeasures, 12, 4.66664605e-04, 1.21498291e+00, 5.13895843e-01, 1.80236842e+00, 3.23283556e-01, 1.31244462e-01, 1.36619002e-01) #Score of 23 # value = self.evaluateModelForMeasures(listOfMeasures, 12, 0.32711334, 5.0, 11.26126126, 12.46876941, 37.99361901, 0.50304455, 0.50304455) #Score of 5 (only on the first 150 ms though) # value = self.evaluateModelForMeasures(listOfMeasures, 12, 0.00589097, 1.4666091, 4.10039631, 1.55765625, 0.25689851, 0.12147452, 0.08027712) #Score of 0.91 (only on the first 150 ms though) # value = self.evaluateModelForMeasures(listOfMeasures, 12, 0.00459395, 1.39735606, 3.26399923, 1.7137901, 0.59109595, 0.14349084, 0.11449425) #Score of 0.127 (only on the first 150 ms though) # value = self.evaluateModelForMeasures(listOfMeasures, 12, 0.00250709722, 1.57426512, 4.57635209, 1.62426655, 0.149425682, 0.0985980367, 0.0915512434) #Score of 10 (full length) # 3.83787890e-03 1.47894946e+00 4.25865142e+00 1.63136824e+00 9.17768154e-02 1.26099628e-01 9.98887909e-02 #Adding the "addedInertia" attribute from here # value = self.evaluateModelForMeasures(listOfMeasures, 12, 0.00250709722, 1.57426512, 4.57635209, 1.62426655, 0.149425682, 0.0985980367, 0.0915512434, 0.004) #Score of 0.94 with addedInertia, on the first 150ms # 1.07728666e-03 1.36831818e+00 3.91813279e+00 1.65976880e+00 1.75653773e-01 1.26764092e-01 9.03878047e-02 3.11286186e-03 #Score of 0.39 with addedInertia, on the first 150ms # 4.91495976e-04 1.62594599e+00 4.72658717e+00 1.63540545e+00 1.95274189e-01 1.21803765e-01 8.79444393e-02 4.07977291e-03 #Score of 0.39 with addedInertia, on the first 150ms # 0.00537005 1.39865656 4.06586179 1.63538543 0.19542816 0.12123053 0.1030164 0.00408195 #Score of 0.386 with addedInertia, on the first 150ms # 6.74933458e-03 1.50816125e+00 4.38408117e+00 1.63554751e+00 1.38872124e-01 1.45544129e-01 1.01677621e-01 4.09684545e-03 #Score of 0.382214837376 with addedInertia, on the first 150ms # [ 1.55818308e-02 1.51294795e+00 4.39798614e+00 1.63553529e+00 8.09641650e-02 2.03719639e-01 1.20403543e-01 4.07587229e-03] # print "value = ", value # return self.noDisplay = True params = [self.i0, self.ke, self.r, self.klin, self.linearTransition, self.staticFriction, self.coulombFriction, self.addedInertia] options = cma.CMAOptions() #Rescaling the sigmas for each variable options['scaling_of_variables'] = [params[0], params[1], params[2]/5.0, params[3]/5.0, params[4], params[5]/10.0, params[6]*2, params[7]/2.5] options['tolfun'] = 0.5 options['ftarget'] = 0.2 res = cma.fmin(self.evaluateModelForMeasures1D, params, 0.5, options, args=[listOfMeasures], restarts=6, bipop=True) print "Best solution = ", res[0] print "Best score = ", res[1] print "Function evals = ", res[2] print "Function evals? = ", res[3] print "Nb iterations = ", res[4] print "mean of final sample distribution", res[5] cma.plot() cma.show() while(True) : temp = 22
import cma import matplotlib.pyplot as plt cma.plot() cma.show()