Skip to content

Commit

Permalink
bug fix in gp2Scale
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusMNoack committed Dec 13, 2022
1 parent a03af0d commit ba5f9ed
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions fvgp/gp2Scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ def __init__(
abs(np.mean(self.y_data) / 100.0)
print("CAUTION: you have not provided data variances in fvGP,")
print("they will be set to 1 percent of the data values!")
elif variances.dim() == 2:
elif np.ndim(variances) == 2:
self.variances = variances[:,0]
elif variances.dim() == 1:
elif np.ndim(variances) == 1:
self.variances = np.array(variances)#, requires_grad = True)
else:
raise Exception("Variances are not given in an allowed format. Give variances as 1d numpy array")
Expand Down
8 changes: 5 additions & 3 deletions fvgp/mcmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ def mcmc(func,bounds, x0 = None, distr = None, max_iter = 1000, ):
f = []
if x0 is None: x.append(np.random.uniform(low = bounds[:,0],high = bounds[:,1],size = len(bounds)))
else: x.append(x0)
if distr is None: l = np.diag((np.abs(np.subtract(bounds[:,0],bounds[:,1])))/20.0)**2
if distr is None: l = np.diag((np.abs(np.subtract(bounds[:,0],bounds[:,1])))/1000.0)**2
counter = 0
current_func = func(x0)
f.append(current_func)
run = True
while run:
x_proposal = np.random.multivariate_normal(x[-1], l)
#x_proposal = project_onto_bounds(x_proposal,bounds)
x_proposal = project_onto_bounds(x_proposal,bounds)
##check for constraints?
proposal_func = func(x_proposal) ####call function
acceptance_prob = proposal_func - current_func ##these are already logs
u = np.log(np.random.rand())
print("current f: ",current_func, " proposal f: ",proposal_func, "acceptance probability: ",acceptance_prob," u ",u, flush = True)
print("iteration: ", counter,"current f: ",current_func, " prop f: ",proposal_func,flush = True)
print("acceptance prob: ",acceptance_prob,"u: ", u,flush = True)
if u < acceptance_prob:
x.append(x_proposal)
f.append(proposal_func)
Expand All @@ -45,6 +46,7 @@ def mcmc(func,bounds, x0 = None, distr = None, max_iter = 1000, ):
f.append(current_func)
print(f[-1], flush = True)
logger.debug("mcmc f(x):{}",f[-1])
print("")
counter += 1
if counter >= max_iter: run = False
#if len(x)>201 and np.linalg.norm(np.mean(x[-100:],axis = 0)-np.mean(x[-200:-100],axis = 0)) < 0.01 * np.linalg.norm(np.mean(x[-100:],axis = 0)): run = False
Expand Down
1 change: 0 additions & 1 deletion fvgp/sparse_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def random_logdet(self, A,eps = 10.0,delta = 0.1,m = 100):
p = int(20.0 * np.log(2./delta)/eps**2)+1
gamma = np.zeros((p,m))
for i in range(p):
print(i," of ",p)
g = np.random.normal(0, 1., size = N)
v = C @ g
gamma[i,1] = g.T @ v
Expand Down

0 comments on commit ba5f9ed

Please sign in to comment.