Ejemplo n.º 1
0
def test_generic_compute_Lx():

    ## now compare against theano version
    vv = T.matrix()
    gg = T.matrix()
    hh = T.matrix()
    aa = T.vector()
    bb = T.vector()
    cc = T.vector()
    xxw_mat = T.matrix()
    xxv_mat = T.matrix()
    xxw = T.vector()
    xxv = T.vector()
    xxa = T.vector()
    xxb = T.vector()
    xxc = T.vector()

    # test compute_Lx
    LLx = natural.generic_compute_Lx([vv, gg, hh],
                                     [xxw_mat, xxv_mat],
                                     [xxa, xxb, xxc])
    f = theano.function([vv, gg, hh, xxw_mat, xxv_mat, xxa, xxb, xxc], LLx)
    t1 = time.time()
    rvals = f(v, g, h, xw_mat, xv_mat, xa, xb, xc)
    print 'Elapsed: ', time.time() - t1
    numpy.testing.assert_almost_equal(Lx_w, rvals[0], decimal=3)
    numpy.testing.assert_almost_equal(Lx_v, rvals[1], decimal=3)
    numpy.testing.assert_almost_equal(Lx_a, rvals[2], decimal=3)
    numpy.testing.assert_almost_equal(Lx_b, rvals[3], decimal=3)
    numpy.testing.assert_almost_equal(Lx_c, rvals[4], decimal=3)
Ejemplo n.º 2
0
def test_generic_compute_Lx():

    ## now compare against theano version
    vv = T.matrix()
    gg = T.matrix()
    hh = T.matrix()
    qq = T.matrix()
    aa = T.vector()
    bb = T.vector()
    cc = T.vector()
    dd = T.vector()
    xxw_mat = T.matrix()
    xxv_mat = T.matrix()
    xxz_mat = T.matrix()
    xxw = T.vector()
    xxv = T.vector()
    xxa = T.vector()
    xxb = T.vector()
    xxc = T.vector()
    xxd = T.vector()

    # test compute_Lx
    LLx = natural.generic_compute_Lx([vv, gg, hh, qq],
                                     [xxw_mat, xxv_mat, xxz_mat],
                                     [xxa, xxb, xxc, xxd])
    f = theano.function(
        [vv, gg, hh, qq, xxw_mat, xxv_mat, xxz_mat, xxa, xxb, xxc, xxd], LLx)
    rvals = f(v, g, h, q, xw_mat, xv_mat, xz_mat, xa, xb, xc, xd)
    numpy.testing.assert_almost_equal(Lx_w, rvals[0], decimal=3)
    numpy.testing.assert_almost_equal(Lx_v, rvals[1], decimal=3)
    numpy.testing.assert_almost_equal(Lx_z, rvals[2], decimal=3)
    numpy.testing.assert_almost_equal(Lx_a, rvals[3], decimal=3)
    numpy.testing.assert_almost_equal(Lx_b, rvals[4], decimal=3)
    numpy.testing.assert_almost_equal(Lx_c, rvals[5], decimal=3)
    numpy.testing.assert_almost_equal(Lx_d, rvals[6], decimal=3)
Ejemplo n.º 3
0
def test_generic_compute_Lx():

    ## now compare against theano version
    vv = T.matrix()
    gg = T.matrix()
    hh = T.matrix()
    aa = T.vector()
    bb = T.vector()
    cc = T.vector()
    xxw_mat = T.matrix()
    xxv_mat = T.matrix()
    xxw = T.vector()
    xxv = T.vector()
    xxa = T.vector()
    xxb = T.vector()
    xxc = T.vector()

    # test compute_Lx
    LLx = natural.generic_compute_Lx([vv, gg, hh], [xxw_mat, xxv_mat],
                                     [xxa, xxb, xxc])
    f = theano.function([vv, gg, hh, xxw_mat, xxv_mat, xxa, xxb, xxc], LLx)
    t1 = time.time()
    rvals = f(v, g, h, xw_mat, xv_mat, xa, xb, xc)
    print 'Elapsed: ', time.time() - t1
    numpy.testing.assert_almost_equal(Lx_w, rvals[0], decimal=3)
    numpy.testing.assert_almost_equal(Lx_v, rvals[1], decimal=3)
    numpy.testing.assert_almost_equal(Lx_a, rvals[2], decimal=3)
    numpy.testing.assert_almost_equal(Lx_b, rvals[3], decimal=3)
    numpy.testing.assert_almost_equal(Lx_c, rvals[4], decimal=3)
Ejemplo n.º 4
0
def test_generic_compute_Lx():

    ## now compare against theano version
    vv = T.matrix()
    gg = T.matrix()
    hh = T.matrix()
    qq = T.matrix()
    aa = T.vector()
    bb = T.vector()
    cc = T.vector()
    dd = T.vector()
    xxw_mat = T.matrix()
    xxv_mat = T.matrix()
    xxz_mat = T.matrix()
    xxw = T.vector()
    xxv = T.vector()
    xxa = T.vector()
    xxb = T.vector()
    xxc = T.vector()
    xxd = T.vector()

    # test compute_Lx
    LLx = natural.generic_compute_Lx([vv, gg, hh, qq],
                                     [xxw_mat, xxv_mat, xxz_mat],
                                     [xxa, xxb, xxc, xxd])
    f = theano.function([vv, gg, hh, qq, xxw_mat, xxv_mat, xxz_mat, xxa, xxb, xxc, xxd], LLx)
    rvals = f(v, g, h, q, xw_mat, xv_mat, xz_mat, xa, xb, xc, xd)
    numpy.testing.assert_almost_equal(Lx_w, rvals[0], decimal=3)
    numpy.testing.assert_almost_equal(Lx_v, rvals[1], decimal=3)
    numpy.testing.assert_almost_equal(Lx_z, rvals[2], decimal=3)
    numpy.testing.assert_almost_equal(Lx_a, rvals[3], decimal=3)
    numpy.testing.assert_almost_equal(Lx_b, rvals[4], decimal=3)
    numpy.testing.assert_almost_equal(Lx_c, rvals[5], decimal=3)
    numpy.testing.assert_almost_equal(Lx_d, rvals[6], decimal=3)
Ejemplo n.º 5
0
def test_runtime():

    ### theano implementation ###
    energies = - T.sum(T.dot(symb['v'], symb['W']) * symb['g'], axis=1) \
               - T.sum(T.dot(symb['g'], symb['V']) * symb['h'], axis=1) \
               - T.dot(symb['v'], symb['a']) \
               - T.dot(symb['g'], symb['b']) \
               - T.dot(symb['h'], symb['c'])

    # Fisher Implementation
    symb_params = [symb['W'], symb['V'], symb['a'], symb['b'], symb['c']]
    symb_x = [symb['x_W'], symb['x_V'], symb['x_a'], symb['x_b'], symb['x_c']]
    f_inputs = [symb['v'], symb['g'], symb['h']] + symb_params + symb_x
    fisher_Lx = fisher.compute_Lx(energies, symb_params, symb_x)
    fisher_func = theano.function(f_inputs, fisher_Lx)

    samples = [symb['v'], symb['g'], symb['h']]
    symb_weights = [symb['x_W'], symb['x_V']]
    symb_biases = [symb['x_a'], symb['x_b'], symb['x_c']]
    f_inputs = [symb['v'], symb['g'], symb['h']] + symb_weights + symb_biases
    natural_Lx = natural.generic_compute_Lx(samples, symb_weights, symb_biases)
    natural_func = theano.function(f_inputs, natural_Lx)

    t1 = time.time()
    fisher_rval = fisher_func(vals['v'], vals['g'], vals['h'], vals['W'],
                              vals['V'], vals['a'], vals['b'], vals['c'],
                              vals['x_W'], vals['x_V'], vals['x_a'],
                              vals['x_b'], vals['x_c'])
    print 'Fisher runtime (s): ', time.time() - t1

    t1 = time.time()
    nat_rval = natural_func(vals['v'], vals['g'], vals['h'], vals['x_W'],
                            vals['x_V'], vals['x_a'], vals['x_b'], vals['x_c'])
    print 'Natural runtime (s): ', time.time() - t1

    ### make sure the two return the same thing ###
    for (rval1, rval2) in zip(fisher_rval, nat_rval):
        numpy.testing.assert_almost_equal(rval1, rval2, decimal=2)
Ejemplo n.º 6
0
def test_runtime():

    ### theano implementation ###
    energies = - T.sum(T.dot(symb['v'], symb['W']) * symb['g'], axis=1) \
               - T.sum(T.dot(symb['g'], symb['V']) * symb['h'], axis=1) \
               - T.dot(symb['v'], symb['a']) \
               - T.dot(symb['g'], symb['b']) \
               - T.dot(symb['h'], symb['c'])

    # Fisher Implementation
    symb_params = [symb['W'], symb['V'], symb['a'], symb['b'], symb['c']]
    symb_x = [symb['x_W'], symb['x_V'], symb['x_a'], symb['x_b'], symb['x_c']]
    f_inputs = [symb['v'], symb['g'], symb['h']] + symb_params + symb_x
    fisher_Lx = fisher.compute_Lx(energies, symb_params, symb_x)
    fisher_func = theano.function(f_inputs, fisher_Lx)

    samples = [symb['v'], symb['g'], symb['h']]
    symb_weights = [symb['x_W'], symb['x_V']]
    symb_biases = [symb['x_a'], symb['x_b'], symb['x_c']]
    f_inputs = [symb['v'], symb['g'], symb['h']] + symb_weights + symb_biases
    natural_Lx = natural.generic_compute_Lx(samples, symb_weights, symb_biases)
    natural_func = theano.function(f_inputs, natural_Lx)
    
    t1 = time.time()
    fisher_rval = fisher_func(vals['v'], vals['g'], vals['h'],
              vals['W'], vals['V'], vals['a'], vals['b'], vals['c'],
              vals['x_W'], vals['x_V'], vals['x_a'], vals['x_b'], vals['x_c'])
    print 'Fisher runtime (s): ', time.time() - t1

    t1 = time.time()
    nat_rval = natural_func(vals['v'], vals['g'], vals['h'],
              vals['x_W'], vals['x_V'], vals['x_a'], vals['x_b'], vals['x_c'])
    print 'Natural runtime (s): ', time.time() - t1

    ### make sure the two return the same thing ###
    for (rval1, rval2) in zip(fisher_rval, nat_rval):
        numpy.testing.assert_almost_equal(rval1, rval2, decimal=2)