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")
Exemple #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))
Exemple #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))
Exemple #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))
Exemple #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))
Exemple #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))
Exemple #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))