示例#1
0
    def _plotQ(self, x_min, y_min, x_max, y_max, ax, norm, Q=numpy.empty((0,0)) ):
        if (self.left is not None and self.left.active) or (self.right is not None and self.right.active):        
            if self.axis == 0:                
                if self.left is not None:
                    #print ("   call plot left:", x_min," ", y_min," ", self.data[1]," ",  y_max)
                    self.left._plotQ(x_min, y_min, self.data[self.axis],  y_max, ax, norm, Q)
            
                if self.right is not None:
                    #print ("   call plot right:", x_min, " ",self.data[1], " ",x_max, " ",y_max)
                    self.right._plotQ(self.data[0], y_min, x_max, y_max, ax, norm, Q)
                
            elif self.axis == 1:
                #self._plotRect([x_min, x_max] , [self.data[self.axis], self.data[self.axis] ], colors[self.label])
                if self.left is not None:
                    #print ("   call plot left:", x_min," ", y_min," ", self.data[1]," ",  y_max)
                    self.left._plotQ(x_min, y_min, x_max,  self.data[self.axis], ax, norm, Q)
            
                if self.right is not None:
                    #print ("   call plot right:", x_min, " ",self.data[1], " ",x_max, " ",y_max)
                    self.right._plotQ(x_min, self.data[1], x_max, y_max, ax, norm, Q)
            else:
                pass
#                assert False, "Cannot plot this axis"
        else:
            assert self.data is None, "At a leaf data is None. There is no further split."
            colors = [cm.ocean(norm( float(q) )) for q in Q[self.label]] 
            self._plotActionValues(x_min, y_min, x_max, y_max, ax, colors)       
示例#2
0
 def _plotV(self, x_min, y_min, x_max, y_max, ax, norm, V=numpy.empty(0)):
     plt_kd.text(self.data[0], self.data[1], "%0.2f" % V[self.label], size=8)
     color = cm.ocean( norm( float( V[self.label] ) ) ) 
     self._plotRect(x_min, y_min, x_max, y_max, ax, color)
     
     if (self.left and self.left.active) or (self.right and self.right.active):        
         if self.axis == 0:                
         
             if self.left:
                 #print ("   call plot left:", x_min," ", y_min," ", self.data[1]," ",  y_max)
                 self.left._plotV(x_min, y_min, self.data[self.axis],  y_max, ax, norm, V)
         
             if self.right:
                 #print ("   call plot right:", x_min, " ",self.data[1], " ",x_max, " ",y_max)
                 self.right._plotV(self.data[0], y_min, x_max, y_max, ax, norm, V)
             
         elif self.axis == 1:
             #self._plotRect([x_min, x_max] , [self.data[self.axis], self.data[self.axis] ], colors[self.label])
             if self.left:
                 #print ("   call plot left:", x_min," ", y_min," ", self.data[1]," ",  y_max)
                 self.left._plotV(x_min, y_min, x_max,  self.data[self.axis], ax, norm, V)
         
             if self.right:
                 #print ("   call plot right:", x_min, " ",self.data[1], " ",x_max, " ",y_max)
                 self.right._plotV(x_min, self.data[1], x_max, y_max, ax, norm, V) 
示例#3
0
    def get_rope_sdf_str(self):
        rope_sdf_str = self.model_start_frag
        curr_z = self.rope_height
        # Add the rest of the rope
        for i in range(0, self.num_segments):
            frac = i / self.num_segments
            if self.model_name == "rope_1":
                r, g, b, a = cm.plasma(frac)
            else:
                r, g, b, a = cm.ocean(frac)
            capsule_str = SDFGenerator.apply_replacements(
                self.capsule_frag, {
                    "{height}": str(curr_z),
                    "{name}": f"{self.model_name}_capsule_{i + 1}",
                    "{length}": str(self.segment_lengths[i]),
                    "{half_length}": str(self.segment_lengths[i] / 2.0),
                    "{radius}": str(self.rope_radius),
                    "{link_mass}": str(self.link_masses[i]),
                    "{link_ixx}": str(self.link_ixxs[i]),
                    "{link_iyy}": str(self.link_iyys[i]),
                    "{link_izz}": str(self.link_izzs[i]),
                    "{x}": str(self.rope_x),
                    "{y}": str(self.rope_y),
                    "{r}": str(r),
                    "{g}": str(g),
                    "{b}": str(b)
                })

            revolute_str = SDFGenerator.apply_replacements(
                self.capsule_joint_frag, {
                    "{effort_int}": "0",
                    "{height}": str(curr_z),
                    "{joint1_name}": f"{self.model_name}_capsule_{i}",
                    "{joint2_name}": f"{self.model_name}_capsule_{i + 1}",
                    "{limit}": str(self.joint_limit),
                    "{damping}": str(self.joint_damping),
                    "{friction}": str(self.joint_friction),
                    "{spring_stiffness}": str(self.spring_stiffness),
                    "{x}": str(self.rope_x),
                    "{y}": str(self.rope_y)
                })
            curr_z -= self.segment_lengths[i]
            if i == 0:
                revolute_str = ""
            rope_sdf_str += capsule_str
            rope_sdf_str += revolute_str

        rope_sdf_str += self.model_end_frag
        return rope_sdf_str
示例#4
0
def _draw_single_box_only(image,
                          xmin,
                          ymin,
                          xmax,
                          ymax,
                          display_str,
                          font,
                          color='black',
                          thickness=4):
    #draw = ImageDraw.Draw(image, 'RGBA')
    draw = ImageDraw.Draw(image)
    (left, right, top, bottom) = (xmin, xmax, ymin, ymax)
    scale = 255 / 92
    rgba_val = [int(x) for x in np.dot(cm.ocean(int(scale * color)), 255)]
    rgba_val[-1] = 50
    # print(rgba_val, "class", color)
    draw.rectangle([(left, top), (right, bottom)], fill=int(scale * color))

    return image
示例#5
0
def color (number):
    return cm.ocean( number / 4.)
if __name__ == "__main__":
    plt.title("Neural Life")

    plt.xscale("log")
    plt.yscale("log")
    
    plt.xlabel("Train size")
    plt.ylabel("Board accuracy")

    plt_patches = []
    for meta_ind,N in enumerate(sorted(META_PARAMETERS.keys())):
        points_x = []
        points_y = []
        
        X_test, Y_test = generateData(N, 100000)
        
        for data_size in META_PARAMETERS[N]: 
            nn = loadKeras("models/model_{}_{}".format(N, int(data_size * 0.5)))
        
            cellAcc, boardAcc = getAccuracies(nn, X_test, Y_test)
            
            points_x.append(data_size * 0.5)
            points_y.append(boardAcc)
            
        plt.plot(points_x, points_y, "o", linestyle="-", color=cm.ocean(meta_ind/len(META_PARAMETERS)))
        plt_patches.append(mpatches.Patch(color=cm.ocean(meta_ind/len(META_PARAMETERS)), label="N={}".format(N)))

    plt.legend(handles=plt_patches, loc=2)
    plt.savefig("graphics-board.svg")
示例#7
0
#Q = numpy.zeros((numberOfStates,numberOfActions))
Q = numpy.zeros((10,4))
Q[1][0]=0.1
Q[1][1]=0.2
Q[1][2]=0.3
Q[1][3]=0.4

norm = colors.Normalize(Q.min(), Q.max())

x_min = 0
y_min = 0 
x_max = 1
y_max = 1
    
state = 5    
color = [cm.ocean(norm( float(q) )) for q in Q[1]]    

# ---------------------------------------------------------
x_top = (x_min + x_max)/2.0
y_top = (y_min + y_max)/2.0

triangle_coord = [[x_min, y_min, y_min, y_max],[x_min, y_max, x_max, y_max],[x_max, y_max, x_max, y_min, y_max],[x_max, y_min, x_min, y_min]] 
         
assert len(triangle_coord)==len(color), "only four actions/colors supported"
for col, coord in zip(color, triangle_coord):
    print col
    verts = [
        (coord[0], coord[1]), # left, bottom
        (coord[2], coord[3]), # left, top
        (x_top, y_top), # triangle peak, center of square 
        (coord[0], coord[1]), # ignored
示例#8
0
    fi = np.asarray(fi)
    print fi.shape
    d = [float(i) for i in fi[:, 1]]
    d = sorted(d)
    d = np.asarray(d)
    #m = max(d)
    m = 305
    tot = float(len(d))
    X = np.arange(5, m, 5)
    X = np.append(X, [0, 1])
    X = np.sort(X)
    Y = []
    for i in X:
        if i < 300:
            c = ((0 <= d) & (d <= i)).sum()
            c = (c / tot) * 100
        else:
            c = ((0 <= d) & (d <= max(d))).sum()
            c = (c / tot) * 100
        Y.append(c)
    plt.plot(X, Y, color=cm.ocean(indx * 5), label=q)
plt.xlabel('Depth')
plt.ylabel('Percent of Bases Covered')
plt.legend(bbox_to_anchor=(0., 1.02, 1., .102),
           loc=3,
           ncol=3,
           mode="expand",
           borderaxespad=1.5,
           prop={'size': 8})
plt.savefig('coverage.pdf', format='pdf')