forked from driftingtides/hyvr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix to specsim function and minor typos in the code.
- Loading branch information
1 parent
09c19d8
commit 8e1986a
Showing
6 changed files
with
226 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import george | ||
import numpy as np | ||
from george.kernels import ExpSquaredKernel | ||
import scipy | ||
|
||
|
||
var = 2**2 | ||
corr_lengths = np.array([100**2, 200**2]) | ||
|
||
kernel = var*ExpSquaredKernel(corr_lengths, ndim=2, ) | ||
|
||
kernel.get_parameter_names() | ||
kernel.get_parameter_vector() | ||
np.exp(kernel.get_parameter_vector()) | ||
|
||
top_botm = np.loadtxt("top_botm.csv",delimiter=",", skiprows=1,usecols=(1,2,3,4)) | ||
top = top_botm[:,2] | ||
bottom = top_botm[:,3] | ||
x_y = top_botm[:,0:2] | ||
|
||
gp_top = george.GP(kernel, mean=np.mean(top), fit_mean=True, | ||
white_noise=np.log(0.5**2), fit_white_noise=True) | ||
gp_top.compute(x_y) | ||
print(gp_top.log_likelihood(top)) | ||
print(gp_top.grad_log_likelihood(top)) | ||
|
||
def nll_top(p): | ||
gp_top.set_parameter_vector(p) | ||
ll = gp_top.log_likelihood(top, quiet=True) | ||
return -ll if np.isfinite(ll) else 1e25 | ||
|
||
def grad_nll_top(p): | ||
gp_top.set_parameter_vector(p) | ||
return -gp_top.grad_log_likelihood(top, quiet=True) | ||
|
||
gp_top.compute(x_y) | ||
|
||
# Print the initial ln-likelihood. | ||
print(gp_top.log_likelihood(top)) | ||
|
||
# Run the optimization routine. | ||
p0 = gp_top.get_parameter_vector() | ||
results = scipy.optimize.minimize(nll_top, p0, jac=grad_nll_top, method="L-BFGS-B") | ||
|
||
# Update the kernel and print the final log-likelihood. | ||
gp_top.set_parameter_vector(results.x) | ||
print(gp_top.log_likelihood(top)) | ||
|
||
gp_top.get_parameter_names() | ||
params = gp_top.get_parameter_vector() | ||
params = np.concatenate([np.array([params[0]]), np.exp(params[1:])]) | ||
params | ||
|
||
kernelb = var*ExpSquaredKernel(corr_lengths, ndim=2, ) | ||
|
||
kernelb.get_parameter_names() | ||
kernelb.get_parameter_vector() | ||
|
||
|
||
gp_bottom = george.GP(kernel, mean=np.mean(bottom), fit_mean=False, | ||
white_noise=np.log(0.5**2), fit_white_noise=False) | ||
gp_bottom.compute(x_y) | ||
print(gp_bottom.log_likelihood(bottom)) | ||
print(gp_bottom.grad_log_likelihood(bottom)) | ||
|
||
def nll_bottom(p): | ||
gp_bottom.set_parameter_vector(p) | ||
ll = gp_bottom.log_likelihood(bottom, quiet=True) | ||
return -ll if np.isfinite(ll) else 1e25 | ||
|
||
def grad_nll_bottom(p): | ||
gp_bottom.set_parameter_vector(p) | ||
return -gp_bottom.grad_log_likelihood(bottom, quiet=True) | ||
|
||
gp_bottom.compute(x_y) | ||
|
||
# Print the initial ln-likelihood. | ||
print(gp_bottom.log_likelihood(bottom)) | ||
|
||
# Run the optimization routine. | ||
p0 = gp_bottom.get_parameter_vector() | ||
results = scipy.optimize.minimize(nll_bottom, p0, jac=grad_nll_bottom, method="L-BFGS-B", tol = 1e-6) | ||
|
||
# Update the kernel and print the final log-likelihood. | ||
gp_bottom.set_parameter_vector(results.x) | ||
print(gp_bottom.log_likelihood(bottom)) | ||
|
||
gp_bottom.get_parameter_names() | ||
paramsb = gp_bottom.get_parameter_vector() | ||
kern_pars = np.exp(paramsb) | ||
corr_lb = np.sqrt(kern_pars) | ||
corr_lb | ||
paramsb = np.concatenate([np.array([paramsb[0]]), np.exp(paramsb[1:])]) | ||
paramsb | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
well,x,y,top_depth_tufa,bottom_depth_tufa | ||
A5,3498882.77,5375943.75,1.41661,7.095870000000001 | ||
A3,3499465.69,5375551.362,1.51276,8.60863 | ||
A4,3498999.87,5375576.76,2.19863,5.948480000000001 | ||
A6,3498066.91,5375946.45,1.58968,3.0768 | ||
A9,3499559.9,5375903.5,2.37811,6.9548499999999995 | ||
A7,3500458.48,5375818.8,2.53195,3.2114100000000003 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.