Exemplo n.º 1
0
 def get_current_scaled_txouts(scale, trunc=0):
     txouts = node.get_current_txouts()
     total = sum(txouts.itervalues())
     results = dict((script, value*scale//total) for script, value in txouts.iteritems())
     if trunc > 0:
         total_random = 0
         random_set = set()
         for s in sorted(results, key=results.__getitem__):
             if results[s] >= trunc:
                 break
             total_random += results[s]
             random_set.add(s)
         if total_random:
             winner = math.weighted_choice((script, results[script]) for script in random_set)
             for script in random_set:
                 del results[script]
             results[winner] = total_random
     if sum(results.itervalues()) < int(scale):
         results[math.weighted_choice(results.iteritems())] += int(scale) - sum(results.itervalues())
     return results
Exemplo n.º 2
0
 def act(self, state, actions) :        
     choice = weighted_choice([1.0-self.eps, self.eps])
     if choice == 0 : return actions[randint(0, len(actions)-1)]
     return self.argmax(state, actions)