示例#1
0
    def test_save_and_load(self):
        n = FeedForwardNetwork([2, 3, 4])
        n.ws = [np.array([[1, 1],
                          [0, -1],
                          [5, -9]]),
                np.array([[2, 7, -4],
                          [0, -1, 1],
                          [6, 20, -10],
                          [3, 3, 3, 3]])]

        n.bs = [np.array([[0], [0], [1]]),
                np.array([[9], [1], [-1], [50]])]

        temp_file = tempfile.mkstemp(suffix=".npz")[1]
        n.save(temp_file)

        n2 = FeedForwardNetwork([])
        n2.load(temp_file)

        for w, b, w2, b2 in zip(n.ws, n.bs, n2.ws, n2.bs):
            npt.assert_equal(w, w2)
            npt.assert_equal(b, b2)

        os.remove(temp_file)
示例#2
0
def clone(n):
    n2 = FeedForwardNetwork([9, 9])
    n2.ws = [np.copy(w) for w in n.ws]
    n2.bs = [np.copy(b) for b in n.bs]
    return n2