Example #1
0
def ais_nodata(fname, do_exact=True):

    rbm_params = load_rbm_params(fname)

    # ais estimate using tempered models as intermediate distributions
    t1 = time.time()
    (logz, log_var_dz), aisobj = rbm_tools.rbm_ais(rbm_params, n_runs=100, seed=123)
    print 'AIS logZ         : %f' % logz
    print '    log_variance : %f' % log_var_dz
    print 'Elapsed time: ', time.time() - t1

    if do_exact:
        exact_logz = compute_logz(rbm_params)
        print 'Exact logZ = %f' % exact_logz
        numpy.testing.assert_almost_equal(exact_logz, logz, decimal=0)
Example #2
0
def ais_nodata(fname, do_exact=True):

    rbm_params = load_rbm_params(fname)

    # ais estimate using tempered models as intermediate distributions
    t1 = time.time()
    (logz, log_var_dz), aisobj = rbm_tools.rbm_ais(rbm_params, n_runs=100, seed=123)
    print "AIS logZ         : %f" % logz
    print "    log_variance : %f" % log_var_dz
    print "Elapsed time: ", time.time() - t1

    if do_exact:
        exact_logz = compute_logz(rbm_params)
        print "Exact logZ = %f" % exact_logz
        # accept less than 1% error
        assert abs(exact_logz - logz) < 0.01 * exact_logz
Example #3
0
def ais_nodata(fname, do_exact=True):

    rbm_params = load_rbm_params(fname)

    # ais estimate using tempered models as intermediate distributions
    t1 = time.time()
    (logz, log_var_dz), aisobj = rbm_tools.rbm_ais(rbm_params,
                                                   n_runs=100,
                                                   seed=123)
    print 'AIS logZ         : %f' % logz
    print '    log_variance : %f' % log_var_dz
    print 'Elapsed time: ', time.time() - t1

    if do_exact:
        exact_logz = compute_logz(rbm_params)
        print 'Exact logZ = %f' % exact_logz
        numpy.testing.assert_almost_equal(exact_logz, logz, decimal=0)
Example #4
0
def ais_nodata(fname, do_exact=True, betas=None):

    rbm_params = load_rbm_params(fname)

    # ais estimate using tempered models as intermediate distributions
    t1 = time.time()
    (logz, log_var_dz), aisobj = \
        rbm_tools.rbm_ais(rbm_params, n_runs=100, seed=123, betas=betas)
    print 'AIS logZ         : %f' % logz
    print '    log_variance : %f' % log_var_dz
    print 'Elapsed time: ', time.time() - t1

    if do_exact:
        exact_logz = compute_logz(rbm_params)
        print 'Exact logZ = %f' % exact_logz
        # accept less than 1% error
        assert abs(exact_logz - logz) < 0.01*exact_logz
Example #5
0
def ais_data(fname, do_exact=True):

    rbm_params = load_rbm_params(fname)

    # load data to set visible biases to ML solution
    from pylearn.datasets import MNIST
    dataset = MNIST.train_valid_test()
    data = numpy.asarray(dataset.train.x, dtype=config.floatX)

    # run ais using B=0 model with ML visible biases
    t1 = time.time()
    (logz, log_var_dz), aisobj = rbm_tools.rbm_ais(rbm_params, n_runs=100, seed=123, data=data)
    print 'AIS logZ         : %f' % logz
    print '    log_variance : %f' % log_var_dz
    print 'Elapsed time: ', time.time() - t1

    if do_exact:
        exact_logz = compute_logz(rbm_params)
        print 'Exact logZ = %f' % exact_logz
        numpy.testing.assert_almost_equal(exact_logz, logz, decimal=0)
Example #6
0
def ais_data(fname, do_exact=True):

    rbm_params = load_rbm_params(fname)

    # load data to set visible biases to ML solution
    from pylearn2.datasets.mnist import MNIST
    dataset = MNIST(which_set='train', one_hot=True)
    data = numpy.asarray(dataset.X, dtype=config.floatX)

    # run ais using B=0 model with ML visible biases
    t1 = time.time()
    (logz, log_var_dz), aisobj = \
        rbm_tools.rbm_ais(rbm_params, n_runs=100, seed=123, data=data)
    print 'AIS logZ         : %f' % logz
    print '    log_variance : %f' % log_var_dz
    print 'Elapsed time: ', time.time() - t1

    if do_exact:
        exact_logz = compute_logz(rbm_params)
        print 'Exact logZ = %f' % exact_logz
        numpy.testing.assert_almost_equal(exact_logz, logz, decimal=0)
Example #7
0
def ais_data(fname, do_exact=True, betas=None):

    rbm_params = load_rbm_params(fname)

    # load data to set visible biases to ML solution
    from pylearn2.datasets.mnist import MNIST
    dataset = MNIST(which_set='train')
    data = numpy.asarray(dataset.X, dtype=config.floatX)

    # run ais using B=0 model with ML visible biases
    t1 = time.time()
    (logz, log_var_dz), aisobj = \
        rbm_tools.rbm_ais(rbm_params, n_runs=100, seed=123, data=data,
                          betas=betas)
    print('AIS logZ         : %f' % logz)
    print('    log_variance : %f' % log_var_dz)
    print('Elapsed time: ', time.time() - t1)

    if do_exact:
        exact_logz = compute_logz(rbm_params)
        print('Exact logZ = %f' % exact_logz)
        numpy.testing.assert_almost_equal(exact_logz, logz, decimal=0)