-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy path06_exact_values_example_1D.py
More file actions
60 lines (45 loc) · 1.34 KB
/
06_exact_values_example_1D.py
File metadata and controls
60 lines (45 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# -*- coding: utf-8 -*-
"""
Exact Values
============
PyKrige demonstration and usage
as a non-exact interpolator in 1D.
"""
import matplotlib.pyplot as plt
import numpy as np
from pykrige.ok import OrdinaryKriging
plt.style.use("ggplot")
np.random.seed(42)
x = np.linspace(0, 12.5, 50)
xpred = np.linspace(0, 12.5, 393)
y = np.sin(x) * np.exp(-0.25 * x) + np.random.normal(-0.25, 0.25, 50)
# compare OrdinaryKriging as an exact and non exact interpolator
uk = OrdinaryKriging(
x, np.zeros(x.shape), y, variogram_model="linear", exact_values=False
)
uk_exact = OrdinaryKriging(x, np.zeros(x.shape), y, variogram_model="linear")
y_pred, y_std = uk.execute("grid", xpred, np.array([0.0]), backend="loop")
y_pred_exact, y_std_exact = uk_exact.execute(
"grid", xpred, np.array([0.0]), backend="loop"
)
y_pred = np.squeeze(y_pred)
y_std = np.squeeze(y_std)
y_pred_exact = np.squeeze(y_pred_exact)
y_std_exact = np.squeeze(y_std_exact)
fig, ax = plt.subplots(1, 1, figsize=(10, 4))
ax.scatter(x, y, label="Input Data")
ax.plot(xpred, y_pred_exact, label="Exact Prediction")
ax.plot(xpred, y_pred, label="Non Exact Prediction")
ax.fill_between(
xpred,
y_pred - 3 * y_std,
y_pred + 3 * y_std,
alpha=0.3,
label="Confidence interval",
)
ax.legend(loc=9)
ax.set_ylim(-1.8, 1.3)
ax.legend(loc=9)
plt.xlabel("X")
plt.ylabel("Field")
plt.show()