Ejemplo n.º 1
0
def plot_gradient(V, loc):
    g = grad(V)
    gx = generate(g.shape[0], lambda i, j: g[i][j][0])
    gy = generate(g.shape[0], lambda i, j: g[i][j][1])
    fig = plt.imshow(V, interpolation='none')
    plt.savefig(loc + "-original.png")
    fig = plt.imshow(gx, interpolation='none')
    plt.savefig(loc + "-ddx.png")
    fig = plt.imshow(gy, interpolation='none')
    plt.savefig(loc + "-ddy.png")
Ejemplo n.º 2
0
 def test_more_complex(self):
     v = np.array([[1, 2], [0, 3]])
     vx = np.array([[[-1, 1], [1, 1]], [[-1, 3], [1, 3]]])
     assertArrayEq(self, vx, grad(v))
Ejemplo n.º 3
0
 def test_basic(self):
     v = np.array([[1, 2], [1, 2]])
     vx = np.array([[[0, 1], [0, 1]], [[0, 1], [0, 1]]])
     assertArrayEq(self, vx, grad(v))
Ejemplo n.º 4
0
 def test_constant_function(self):
     x = np.array([[1, 1], [1, 1]])
     assertArrayEq(self, np.zeros((2, 2, 2)), grad(x))
     x = np.array([[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1],
                   [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]])
     assertArrayEq(self, np.zeros((5, 5, 2)), grad(x))
Ejemplo n.º 5
0
 def test_more_complex(self):
     v = np.array([[1,2],[0,3]])
     vx = np.array([[[-1,1], [1,1]], [[-1,3], [1,3]]])
     assertArrayEq(self, vx, grad(v))
Ejemplo n.º 6
0
 def test_basic(self):
     v = np.array([[1,2],[1,2]])
     vx = np.array([[[0,1], [0,1]], [[0,1], [0,1]]])
     assertArrayEq(self, vx, grad(v))
Ejemplo n.º 7
0
 def test_constant_function(self):
     x = np.array([[1,1],[1,1]])
     assertArrayEq(self, np.zeros((2,2,2)), grad(x))
     x = np.array([[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]])
     assertArrayEq(self, np.zeros((5,5,2)), grad(x))