https://github.com/ctf20/DarwinianNeurodynamics/commit/1d833d0fbbb148905482f8f6289a75bbd6675484
and modified
https://github.com/ctf20/DarwinianNeurodynamics/commit/270e43c629490f24baa531c0d6e059c2ac40d8b2
This system now optimizes the elbow position quite nicely.
You see above that forcefully perturbing the elbow position results in it being brought back to the position which maximizes the output of atom 1. Atom 2 the hill climber atom sees that this is achieved by choosing joint angles that have this effect.
The next step is to introduce mutation operations that generate new actors, and also to generate a more general kind of dynamical parameter specification for an actor, e.g. specification of the weights of a FF or R neural network, or weights and time-constants of a CTRNN, or the readout elements of a LSM. This should provide a richer controller space than just specifying the final joint angles explicitly in the parameter vector as we have been doing above.
Slight error in above code due to F***** up copying of lists in python .
http://henry.precheur.org/python/copy_list
self.parameters = list(self.newParameters)#Bloody annoying python thing, otherwise we just move pointers ratehr than copying stuff in the lists.
rather than
self.parameters = self.newParameters
which is what I was doing above which actually meant the SHC didn't work. Now it does...
#ACT 3 *************************************************************************
if self.actorType is 3: #TAKE A MESSAGE INPUT AS FITNESS, and OUTPUT MOTOR OUTPUT DIRECTLY.
print "SHC actor type"
#5. Assess fitness of the new state/position
#1. m[0] shows the fitness of the current state./
#6. If m > oldm, parameters = newparameters.
if m[0] <= self.oldMesgValue[0] or random.random() < 0.05:
print "accepted new parameters " + str(m) + " better than " + str(self.oldMesgValue)
self.parameters = list(self.newParameters)#Bloody annoying python thing, otherwise we just move pointers ratehr than copying stuff in the lists.
self.oldMesgValue = m
print "OldMesgValue set to new m = " + str(self.oldMesgValue)
print "Keeping arm in new position"
else:
#7. If m <= oldm, revert, move back to the original parameters
print "revert" + str(m) + " worse than " + str(self.oldMesgValue)
m = self.oldMesgValue
angles = self.parameters
names = []
for i in range(len(angles)):
names.append(self.sd.getMotorName(self.outputs[i]))#Put motor output names into names list
for index, i in enumerate(names):#Check that motor outputs are within limits.
lim = self.motion.getLimits(i)
#print lim
#print i
if angles[index] < lim[0][0]/2.0:
angles[index] = lim[0][0]/2.0
if angles[index] > lim[0][1]/2.0:
angles[index] = lim[0][1]/2.0
self.motion.post.setAngles(names,angles,1)#Actually move the motors according to values in angles list.
# self.motion.post.angleInterpolation(names,angles,[0.1]*len(names),1)#Actually move the motors according to values in angles list.
time.sleep(0.1)
#Need to recall the fitness function to recalculate.
print "Moved back arm to old position, so m = oldMesgValue = " + str(m)
#2. Mutate the current parameters to new-parameters.
#print len(self.newParameters)
for i,v in enumerate(self.newParameters):
#print 0.5*(random.random()-0.5)
self.newParameters[i] = self.parameters[i] + 0.5*(random.random()-0.5)
#3. Execute the new parameters.
angles = self.newParameters
names = []
for i in range(len(angles)):
names.append(self.sd.getMotorName(self.outputs[i]))#Put motor output names into names list
for index, i in enumerate(names):#Check that motor outputs are within limits.
lim = self.motion.getLimits(i)
if angles[index] < lim[0][0]/2.0:
angles[index] = lim[0][0]/2.0
if angles[index] > lim[0][1]/2.0:
angles[index] = lim[0][1]/2.0
self.motion.post.setAngles(names,angles,1)#Actually move the motors according to values in angles list.
time.sleep(0.1)
#self.motion.post.angleInterpolation(names,angles,[0.1]*len(names),1)#Actually move the motors according to values in angles list.
#4. Save the value of the old fitness
print "Moved arm to new mutated newparemter position"
self.oldMesgValue = m
No comments:
Post a Comment