Exemplo n.º 1
0
 def calcAction(self):
     vec.normalize(vec.randomVec(self.action.direction), self.action.direction)
     self.action.speed = util.clamp(util.uniform(), 0.25, 1.0)
Exemplo n.º 2
0
 def calcAction(self):
     vec.normalize(vec.randomVec(self.action.direction), self.action.direction)
     self.action.speed = util.clamp(util.uniform(), 0.25, 1.0)
Exemplo n.º 3
0
def main():
   nump,n,lower,upper = 10,2,-10,10
   points = []
   print "\nPOINTS\n"
   for i in range(nump):
      invalid = True
      while invalid:
         v = vec.randomVec(n,lower,upper)
         if v.norm() != 0 and v not in points:
            points.append(v)
            print str(points[i]) + ",",
            invalid = False
   print ""

   print "\nLEADER ALGORITHM\n"
   t = 0.65
   print "Cosine Similarity, t = " + str(t),
   cleader0 = leader(points, t, vec.cos, 1, True)
   print ""
   for c in cleader0:
      print "C:" + str(c)
   t = 7
   print "Euclidean Distance, t = " + str(t),
   cleader1 = leader(points, t, vec.euclid, -1, True)
   print ""
   for c in cleader1:
      print "C:" + str(c)

   print "\nK-MEANS\n"
   k = 4
   print "Cosine Similarity",
   ckmeans0 = kmeans(points,k,vec.cos,1,True)
   print ""
   for c in ckmeans0:
      print "C:" + str(c)

   print "Euclidean Distance",
   ckmeans1 = kmeans(points,k,vec.euclid,-1,True)
   print ""
   for c in ckmeans1:
      print "C:" + str(c)

   print "\nAGGLOMORATIVE\n"
   t = threshold(points, .4, vec.cos)
   link = 's'
   print "Cosine Similarity, " + link + ", t = " + str(t),
   cagglo0 = agglomorate(points,link,t,vec.cos,1, True)
   print ""
   for c in cagglo0:
      print "C:" + str(c)
   t = threshold(points, .5, vec.euclid)
   link = 'c'
   print "Euclidean Distance, " + link + ", t = " + str(t),
   cagglo1 = agglomorate(points,link,t,vec.euclid,-1, True)
   print ""
   for c in cagglo1:
      print "C:" + str(c)

   print "\nAGGREGATION\n"
   t = threshold(points, .9, vec.euclid)
   combined = aggregate(ckmeans1, cagglo1, t, vec.euclid, -1, True)
   print ""
   for c in combined:
      print "C:" + str(c)

   print "\nAGGREGATION2\n"
   combined2 = aggregate2(ckmeans1, cagglo1, t, vec.euclid, -1, True)
   print ""
   for c in combined2:
      print "C:" + str(c)

   print "\nPRUNE\n"
   pruned = prune(points,combined2, vec.euclid, -1)
   for c in pruned:
      print "C:" + str(c)
    
   return points, [ cleader0, cleader1, ckmeans0, ckmeans1, cagglo0, cagglo1 ], combined