def explore_dimensions(self, initialState, ranges, pointsPerDim = 10, repetitions = 3): '''For the given vector, vary each parameter separately. Arguments: initialState -- where to start ranges -- parameter ranges pointsPerDim -- number of points along each dimension repetitions -- how many measurements to make of each position ''' nDimensions = len(initialState) self.log_start() self.log_write('RunManager.explore_dimensions, centered at %s' % prettyVec(initialState)) for dimension in range(nDimensions): self.log_write('RunManager.explore_dimensions: dimension %d' % dimension) points = Neighbor.uniform_spread(ranges, initialState, dimension, number = pointsPerDim, includeOrig = True) for ii,point in enumerate(points): for tt in range(repetitions): print 'Iteration dimension %d, point %d, trial %d' % (dimension, ii, tt), prettyVec(point), sys.stdout.flush() self.log_write('%d, %d, %d, ' % (dimension, ii, tt), newline=False) dist = self.run_robot(point) print '%.2f' % dist self.log_results(point, dist)
def updateResults(self, dist): self.iterations += 1 if self.bestDist is None or dist > self.bestDist: self.bestDist = dist self.bestState = self.current self.bestIter = self.iterations print ' best (iter %3d)' % self.bestIter, prettyVec(self.bestState), '%.2f' % self.bestDist # Prints best state and distance so far
def explore_dimensions(self, initialState, ranges, pointsPerDim=10, repetitions=3): '''For the given vector, vary each parameter separately. Arguments: initialState -- where to start ranges -- parameter ranges pointsPerDim -- number of points along each dimension repetitions -- how many measurements to make of each position ''' nDimensions = len(initialState) self.log_start() self.log_write('RunManager.explore_dimensions, centered at %s' % prettyVec(initialState)) for dimension in range(nDimensions): self.log_write('RunManager.explore_dimensions: dimension %d' % dimension) points = Neighbor.uniform_spread(ranges, initialState, dimension, number=pointsPerDim, includeOrig=True) for ii, point in enumerate(points): for tt in range(repetitions): print 'Iteration dimension %d, point %d, trial %d' % ( dimension, ii, tt), prettyVec(point), sys.stdout.flush() self.log_write('%d, %d, %d, ' % (dimension, ii, tt), newline=False) dist = self.run_robot(point) print '%.2f' % dist self.log_results(point, dist)
def do_many_runs(self, strategy, ranges, limit=None): if limit is None: limit = 10000 self.log_start(strategy.logHeader()) for ii in xrange(limit): currentState, logInfo = strategy.getNext() print #if hasattr(currentState, '__call__'): # print 'Iteration %2d: %s' % (ii+1, logStr), #else: # print 'Iteration %2d params' % (ii+1), prettyVec(currentState), paramStr = logInfo if isinstance( logInfo, basestring) else prettyVec(logInfo) print 'Iteration %2d: %s' % (ii + 1, paramStr) sys.stdout.flush() # Check if this state is new, and possibly skip it #if tuple(currentState) in self.statesSoFar: # print '*** Duplicate iteration!' # # Skip only if using random hill climbing. In other words, # # comment this line out if using gradient_search: # #currentState = neighborFunction(bestState) # continue currentDistance = self.run_robot(currentState) #currentDistance = input('Distance walked? ') #self.statesSoFar.add(tuple(currentState)) #print ' walked %.2f' % currentDistance print '%.2f' % currentDistance strategy.updateResults(currentDistance) #print ' best so far', prettyVec(strategy.bestState), '%.2f' % strategy.bestDist # Prints best state and distance so far self.log_results(logInfo, currentDistance)
def do_many_runs(self, strategy, ranges, limit = None): if limit is None: limit = 10000 self.log_start(strategy.logHeader()) for ii in xrange(limit): currentState, logInfo = strategy.getNext() print #if hasattr(currentState, '__call__'): # print 'Iteration %2d: %s' % (ii+1, logStr), #else: # print 'Iteration %2d params' % (ii+1), prettyVec(currentState), paramStr = logInfo if isinstance(logInfo, basestring) else prettyVec(logInfo) print 'Iteration %2d: %s' % (ii+1, paramStr) sys.stdout.flush() # Check if this state is new, and possibly skip it #if tuple(currentState) in self.statesSoFar: # print '*** Duplicate iteration!' # # Skip only if using random hill climbing. In other words, # # comment this line out if using gradient_search: # #currentState = neighborFunction(bestState) # continue currentDistance = self.run_robot(currentState) #currentDistance = input('Distance walked? ') #self.statesSoFar.add(tuple(currentState)) #print ' walked %.2f' % currentDistance print '%.2f' % currentDistance strategy.updateResults(currentDistance) #print ' best so far', prettyVec(strategy.bestState), '%.2f' % strategy.bestDist # Prints best state and distance so far self.log_results(logInfo, currentDistance)