Ejemplo n.º 1
0
    def test_showQ(self):
        import matplotlib.pyplot as plt
        import time
          
        print "---------- DisplayTreeTest ----------"
        #plt.figure(self.fig_values.number)
        maxLevel=2
        no1dN = []
        points = numpy.array([[0.0, 0.0], [0.0, 1.0], [ 1.0, 0.0], [1.0, 1.0]])
        util.splitN(points, 0, 0, maxLevel, no1dN)
        tree = kdtree.createNewTree(no1dN)
          
        numberOfStates= tree.getHighestNodeId
        numberOfActions = 4
        
        kdtree.visualize(tree)
        Q = numpy.ones((100,numberOfActions))
        
        n = tree.get_path_to_best_matching_node([0.75, 0.75])[-1]
        print n.label
        n.split2([0.85, 0.75], axis=0, sel_axis = (lambda axis: axis))
        kdtree.visualize(tree)  
        # only leaves are shown!
        # States are positioned like in the tree i.e. xy axes splits in tree represent xy position in coord system
        # 0, 0 is bottom left, x increases to the right 
        # action 0 is to the left
        # Q[State][action]
        Q[3][0] = 0 # bottom left, action left
#         Q[5][1] = 0.1 # above Q[2] (in y direction), right
#         Q[58][2] = 0.1 #right top corner, down
#         Q[4][0] = 0.5
        kdtree.plotQ2D(tree, min_coord=[0, 0], max_coord=[1, 1],Values = Q, plt=plt, plot="Q")
        time.sleep(5)  
Ejemplo n.º 2
0
 def plotQ2D(self, min_coord=[0, 0], max_coord=[1, 1], Values=numpy.empty((0,0)), plot="V", path_savefig=None):
     plt.figure(self.fig.number)
     kdtree.plotQ2D(self.tree, min_coord=min_coord, max_coord=max_coord, plt=plt, Values=Values, path_savefig=path_savefig)
Ejemplo n.º 3
0
# ax.set_xlim(-2,2)
# ax.set_ylim(-2,2)
# plt.show()



no2dN = []
points = numpy.array([[0.0, 0.0], [0.0, 1.0], [ 1.0, 0.0], [1.0, 1.0]])
util.splitN(points, 0, 0, 6, no2dN)
tree2dN = kdtree.create(no2dN)
util.activate(tree2dN, 4)
  
kdtree.visualize(tree2dN)
 
V = numpy.random.rand(len(no2dN),1)
kdtree.plotQ2D(tree2dN, Values=V)
#kdtree.plot2D(tree2dN)



#kdtree.plot2DUpdate(tree2dN)
# 
# 
# no3dN_test = []
# points = numpy.array([[0.0, 0.0,  0.0],[0.0 ,  0.0, 1.0], [ 0.0, 1.0, 0.0], [ 0.0, 1.0, 1.0], [1.0, 0.0,  0.0], [1.0, 0.0,  1.0], [1.0, 1.0,  0.0], [1.0, 1.0,  1.0]])
# splitN_test(points, 0,0,7, no3dN_test)
# 
# assert all(x in no3dN_test for x in no3dN), "NOT EQUAL !!!"

#kdtree.plot2D(tree)