コード例 #1
0
def test_bad_mcmc():
	constrainer = MCMCConstrainer(proposer = GaussProposal(adapt=False, scale=1e-5), nmaxsteps=100000)
	N = 40
	for d in 2, 7, 20:
		print 'running in %d dimensions' % d
		run_constrainer(d=d, N=N, constrainer=constrainer, name='rejection')
		plt.savefig('test_constrainer_%d_%s.pdf' % (d, 'rejection'), bbox_inches='tight')
		plt.close()
コード例 #2
0
def test_bad_mcmc():
    constrainer = MCMCConstrainer(proposer=GaussProposal(adapt=False,
                                                         scale=1e-5),
                                  nmaxsteps=100000)
    N = 40
    for d in 2, 7, 20:
        print('running in %d dimensions' % d)
        run_constrainer(d=d, N=N, constrainer=constrainer, name='rejection')
        plt.savefig('test_constrainer_%d_%s.pdf' % (d, 'rejection'),
                    bbox_inches='tight')
        plt.close()
コード例 #3
0
def run_constrainers(ds, Ns, constrainers):
	fout = file('constrainertest.tex', 'w')
	print ' %(name)30s  %(d)3s  %(N)3s     D  pvalue     D  pvalue   iter      evals   efficiency' % dict(name='constrainer', d='dim', N='N')
	print ' %s  ---  ---  ----  ------  ----  ------  -----  ----------  -------------' % ('-'*30)
	for d in ds:
		for name, constrainer in constrainers:
			for N in Ns:
				results = run_constrainer(d, N, constrainer, name=name)
				fout.write('%(name)s & %(d)d & %(pvalue).4f & %(shrinkage_pvalue).4f & %(niter)d & %(total_samples)d & %(efficiency).2f\\%% \\\\ \n' % results)
				fout.flush()
		fout.write('\hline\n')
	fout.close()
コード例 #4
0
def run_constrainers(ds, Ns, constrainers):
    fout = file('constrainertest.tex', 'w')
    print ' %(name)30s  %(d)3s  %(N)3s     D  pvalue     D  pvalue   iter      evals   efficiency' % dict(
        name='constrainer', d='dim', N='N')
    print ' %s  ---  ---  ----  ------  ----  ------  -----  ----------  -------------' % (
        '-' * 30)
    for d in ds:
        for name, constrainer in constrainers:
            for N in Ns:
                results = run_constrainer(d, N, constrainer, name=name)
                fout.write(
                    '%(name)s & %(d)d & %(pvalue).4f & %(shrinkage_pvalue).4f & %(niter)d & %(total_samples)d & %(efficiency).2f\\%% \\\\ \n'
                    % results)
                fout.flush()
        fout.write('\hline\n')
    fout.close()
コード例 #5
0
        Ns=[400],
        constrainers=constrainers)


def test_rejection():
    constrainer = RejectionConstrainer()
    N = 40
    for d in 2, 7, 20:
        print('running in %d dimensions' % d)
        evaluate_constrainer(d=d, N=N, constrainer=constrainer, niter=400)
        plt.savefig('test_constrainer_%d_%s.pdf' % (d, 'rejection'),
                    bbox_inches='tight')
        plt.close()


if __name__ == '__main__':
    import sys
    if len(sys.argv) == 1:
        test_all()
    else:
        sel = int(sys.argv[1])
        i = 0
        ds = (2, 7, 20)
        Ns = [400]
        for name, constrainer in constrainers:
            for d in ds:
                for N in Ns:
                    i = i + 1
                    if i == sel:
                        run_constrainer(d, N, constrainer, name=name)
コード例 #6
0
	fout.close()
def test_all():
	run_constrainers(ds=(2, 7, 20), #(2, 7, 20),
		Ns=[400], constrainers=constrainers)

def test_rejection():
	constrainer = RejectionConstrainer()
	N = 40
	for d in 2, 7, 20:
		print 'running in %d dimensions' % d
		evaluate_constrainer(d=d, N=N, constrainer=constrainer, niter=400)
		plt.savefig('test_constrainer_%d_%s.pdf' % (d, 'rejection'), bbox_inches='tight')
		plt.close()

if __name__ == '__main__':
	import sys
	if len(sys.argv) == 1:
		test_all()
	else:
		sel = int(sys.argv[1])
		i = 0
		ds=(2, 7, 20)
		Ns=[400]
		for name, constrainer in constrainers:
			for d in ds:
				for N in Ns:
					i = i + 1
					if i == sel:
						run_constrainer(d, N, constrainer, name=name)