-
-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GEKPLS With Custom PLS Based on SKLearn PLS #359
Merged
ChrisRackauckas
merged 12 commits into
SciML:master
from
vikram-s-narayan:gekpls_with_own_pls
Jun 29, 2022
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4d78d53
replace sklearn pls with julia version of modified pls
vikram-s-narayan d6b1a54
format after rebase from master
vikram-s-narayan 6e8e3ad
add 2D box behnken FOTA
vikram-s-narayan bb8c534
provide fix to prevent NaN values from creeping into matrices
vikram-s-narayan 64f527b
fix formatting after git rebase
vikram-s-narayan f31d42c
add add_point function, tests for add_point function and bounds checking
vikram-s-narayan 2e2cd88
change struct of GEKPLS
vikram-s-narayan bb14ca4
update files after rebase
vikram-s-narayan 0b1984f
remove unnecessary variables and comments
vikram-s-narayan 45d864d
fix changes introduced by rebase
vikram-s-narayan e39d421
update code after rebase with master
vikram-s-narayan cd72b3f
Update Project.toml
ChrisRackauckas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
## GEKPLS Surrogate Tutorial | ||
|
||
Gradient Enhanced Kriging with Partial Least Squares Method (GEKPLS) is a surrogate modelling technique that brings down computation time and returns improved accuracy for high-dimensional problems. The Julia implementation of GEKPLS is adapted from the Python version by [SMT](https://github.com/SMTorg) which is based on this [paper](https://arxiv.org/pdf/1708.02663.pdf). | ||
|
||
The following are the inputs when building a GEKPLS surrogate: | ||
|
||
1. X - The matrix containing the training points | ||
2. y - The vector containing the training outputs associated with each of the training points | ||
3. grads - The gradients at each of the input X training points | ||
4. n_comp - Number of components to retain for the partial least squares regression (PLS) | ||
5. delta_x - The step size to use for the first order Taylor approximation | ||
6. xlimits - The lower and upper bounds for the training points | ||
7. extra_points - The number of additional points to use for the PLS | ||
8. theta - The hyperparameter to use for the correlation model | ||
|
||
The following example illustrates how to use GEKPLS: | ||
|
||
```@example gekpls_water_flow | ||
|
||
using Surrogates | ||
using Zygote | ||
|
||
function vector_of_tuples_to_matrix(v) | ||
#helper function to convert training data generated by surrogate sampling into a matrix suitable for GEKPLS | ||
num_rows = length(v) | ||
num_cols = length(first(v)) | ||
K = zeros(num_rows, num_cols) | ||
for row in 1:num_rows | ||
for col in 1:num_cols | ||
K[row, col]=v[row][col] | ||
end | ||
end | ||
return K | ||
end | ||
|
||
function vector_of_tuples_to_matrix2(v) | ||
#helper function to convert gradients into matrix form | ||
num_rows = length(v) | ||
num_cols = length(first(first(v))) | ||
K = zeros(num_rows, num_cols) | ||
for row in 1:num_rows | ||
for col in 1:num_cols | ||
K[row, col] = v[row][1][col] | ||
end | ||
end | ||
return K | ||
end | ||
|
||
function water_flow(x) | ||
r_w = x[1] | ||
r = x[2] | ||
T_u = x[3] | ||
H_u = x[4] | ||
T_l = x[5] | ||
H_l = x[6] | ||
L = x[7] | ||
K_w = x[8] | ||
log_val = log(r/r_w) | ||
return (2*pi*T_u*(H_u - H_l))/ ( log_val*(1 + (2*L*T_u/(log_val*r_w^2*K_w)) + T_u/T_l)) | ||
end | ||
|
||
n = 1000 | ||
d = 8 | ||
lb = [0.05,100,63070,990,63.1,700,1120,9855] | ||
ub = [0.15,50000,115600,1110,116,820,1680,12045] | ||
x = sample(n,lb,ub,SobolSample()) | ||
X = vector_of_tuples_to_matrix(x) | ||
grads = vector_of_tuples_to_matrix2(gradient.(water_flow, x)) | ||
y = reshape(water_flow.(x),(size(x,1),1)) | ||
xlimits = hcat(lb, ub) | ||
n_test = 100 | ||
x_test = sample(n_test,lb,ub,GoldenSample()) | ||
X_test = vector_of_tuples_to_matrix(x_test) | ||
y_true = water_flow.(x_test) | ||
n_comp = 2 | ||
delta_x = 0.0001 | ||
extra_points = 2 | ||
initial_theta = 0.01 | ||
g = GEKPLS(X, y, grads, n_comp, delta_x, xlimits, extra_points, initial_theta) | ||
y_pred = g(X_test) | ||
rmse = sqrt(sum(((y_pred - y_true).^2)/n_test)) #root mean squared error | ||
println(rmse) | ||
``` | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be required in the Project?