예제 #1
0
파일: acor_test.py 프로젝트: mugurbil/gnm
	data_file.close()
	N = data['N']
	m = data['m']
	H = data['H']
	sigma = data['s']
	y = data['y']
except: 
	print "Data could not be found."
	exit(0)

# make function instance
from acor_func import funky
f    = gnm.F(funky,data['args'])

# creating sampler object
sampler = gnm.sampler(m,H,y,sigma,f)

# to use the right format for scipy
def func(x0,x1,x2,x3,x4,x5):
	x = [x0,x1,x2,x3,x4,x5]
	x = x[:2*N]
	return	sampler.posterior(x)

def integrand(x):
	if N == 1:
		if   k == 0 :
			return lambda y : func(x,y,0,0,0,0)
		else : 
			return lambda y : func(y,x,0,0,0,0)
	if N == 2:
		if   k == 0:
예제 #2
0
파일: simple_2D.py 프로젝트: mugurbil/gnm
# correct user-defined function
# f(x,y) = (x,ax^2+y)'
print("Jtest with Correct Function:")
def funky(x, args):
    a   = args["a"]
    f_x = [x[0], a*x[0]**2+x[1]]
    J_x = [[1., 0], [2*a*x[0], 1.]]
    return 1, f_x, J_x
f = gnm.function(funky, arguments)
error = f.Jtest(x_min, x_max)
check(error)

# sample the likelihood
start_time    = time.time()
sampler       = gnm.sampler(m, funky, arguments)
sampler.prior(m, H)
sampler.sample(num_samples)
# chain         = sampler.burn_in(num_burn)
end_time      = time.time()
print 'Acceptence Percentage: ' + str(sampler.accept_rate)
print 'Ellapsed Time        : ' + str(end_time-start_time)
print 

# histogram of samples
chain = sampler.chain
plot_sampled = plt.hist(chain[:,0], num_bins,color = 'b',
                       range=[plot_range[0][0], plot_range[1][0]],normed=True,
                       label='sampled',alpha=0.3)

### START QUADRATURE ###
예제 #3
0
파일: quickstart.py 프로젝트: mugurbil/gnm
import gnm

# random seeding
np.random.seed(3)

# initial guess
x_0 = [0.1]
# user function 
def model(x, args):
    y = args['y']
    s = args['s']
    return 1, [(x[0]**2-y)/s], [[(2.*x[0])/s]]
# observed data and error = arguments for the user function
data = {'y':[1.], 's':1.}    
# sampler object
jagger = gnm.sampler(x_0, model, data)
# user-defined prior mean and precision 
m = [0.]   # vector
H = [[1.]] # matrix
jagger.prior(m, H)

# domain for Jtest
d_min = [-3.]
d_max = [3.]
# test the model's function-Jacobian match
error = jagger.Jtest(d_min, d_max)
assert error == 0 

# back-off info
max_steps = 1
dilation = 0.1
예제 #4
0
파일: rosenbrock.py 프로젝트: mugurbil/gnm
# initial guess
x_0 = [0.1, 0.1]
# user function
def model(x, args):
    a = args["a"]
    b = args["b"]
    z = (a - x[0]) ** 2 + b * (x[1] - x[0] ** 2) ** 2
    dx = -2 * (a - x[0]) + 2 * b * (x[1] - x[0] ** 2) * (-2 * x[0])
    dy = 2 * b * (x[1] - x[0] ** 2)
    return 1, [z], [[dx, dy]]


# observed data and error = arguments for the user function
args = {"a": 1.0, "b": 1.0}
# sampler object
jagger = gnm.sampler(x_0, model, args)
# user-defined prior mean and precision

m = [0.0, 0.0]  # vector
H = [[1.0, 0.0], [0.0, 1.0]]  # matrix
jagger.prior(m, H)

# domain for Jtest
d_min = [-3.0, -3.0]
d_max = [3.0, 3.0]
# test the model's function-Jacobian match
error = jagger.Jtest(d_min, d_max)
assert error == 0

# back-off info
max_steps = 0
예제 #5
0
    t = args['t']
    y = args['y']
    s = args['s']
    a,b = exp_time_series(x,t)
    return 1,(a-y)/s,b/s

# create the data with noise
x = np.array([1.,2.5,0.5,3.1])
t = np.array(range(t_max))
y,_ = exp_time_series(x,t)
for i in xrange(y.size):
	y[i] = y[i]*(1+np.random.randn()*0.1)
args = {'t':t, 'y':y, 's':sigma}


jagger = gnm.sampler(m, model, args)
jagger.prior(m, H)
jagger.dynamic(1)
# jagger.static(1, 0.1)

# print("Testing Jacobian...")
# error = jagger.Jtest(x_min,x_max)
# if error:
#     print("error :" + str(error))
# else: 
#     print("Converged!")
# print


# sample the likelihood
print("Sampling...")