Skip to content

Commit

Permalink
Merge pull request #370 from vikram-s-narayan/make_theta_param_as_array
Browse files Browse the repository at this point in the history
Make theta a user-supplied array param
  • Loading branch information
ChrisRackauckas authored Jul 8, 2022
2 parents 2de1b9d + ade62b4 commit 8cebcbe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
5 changes: 3 additions & 2 deletions docs/src/gekpls.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ y_true = water_flow.(x_test)
n_comp = 2
delta_x = 0.0001
extra_points = 2
initial_theta = 0.01
initial_theta = [0.01 for i in 1:n_comp]
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)
println(rmse) #0.0347
```

3 changes: 1 addition & 2 deletions src/GEKPLS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ function bounds_error(x, xl)
end

#constructor for GEKPLS Struct
function GEKPLS(X, y, grads, n_comp, delta_x, xlimits, extra_points, θ)
function GEKPLS(X, y, grads, n_comp, delta_x, xlimits, extra_points, theta)

#ensure that X values are within the upper and lower bounds
if bounds_error(X, xlimits)
println("X values outside bounds")
return
end

theta =for i in 1:n_comp]
pls_mean, X_after_PLS, y_after_PLS = _ge_compute_pls(X, y, n_comp, grads, delta_x,
xlimits, extra_points)
X_after_std, y_after_std, X_offset, y_mean, X_scale, y_std = standardization(X_after_PLS,
Expand Down
18 changes: 9 additions & 9 deletions test/GEKPLS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ y_true = water_flow.(x_test)
n_comp = 2
delta_x = 0.0001
extra_points = 2
initial_theta = 0.01
initial_theta = [0.01 for i in 1:n_comp]
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))
Expand All @@ -71,7 +71,7 @@ end
n_comp = 3
delta_x = 0.0001
extra_points = 2
initial_theta = 0.01
initial_theta = [0.01 for i in 1:n_comp]
g = GEKPLS(X, y, grads, n_comp, delta_x, xlimits, extra_points, initial_theta) #change hard-coded 2 param to variable
y_pred = g(X_test)
rmse = sqrt(sum(((y_pred - y_true) .^ 2) / n_test))
Expand All @@ -82,7 +82,7 @@ end
n_comp = 3
delta_x = 0.0001
extra_points = 3
initial_theta = 0.01
initial_theta = [0.01 for i in 1:n_comp]
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))
Expand Down Expand Up @@ -118,7 +118,7 @@ y_true = welded_beam.(x_test)
n_comp = 3
delta_x = 0.0001
extra_points = 2
initial_theta = 0.01
initial_theta = [0.01 for i in 1:n_comp]
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))
Expand All @@ -129,7 +129,7 @@ end
n_comp = 2
delta_x = 0.0001
extra_points = 2
initial_theta = 0.01
initial_theta = [0.01 for i in 1:n_comp]
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))
Expand All @@ -141,7 +141,7 @@ end
n_comp = 2
delta_x = 0.0001
extra_points = 4
initial_theta = 0.01
initial_theta = [0.01 for i in 1:n_comp]
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))
Expand Down Expand Up @@ -171,7 +171,7 @@ y_true = sphere_function.(x_test)
n_comp = 2
delta_x = 0.0001
extra_points = 2
initial_theta = 0.01
initial_theta = [0.01 for i in 1:n_comp]
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))
Expand All @@ -197,7 +197,7 @@ y_true = sphere_function.(x_test)
n_comp = 2
delta_x = 0.0001
extra_points = 2
initial_theta = 0.01
initial_theta = [0.01 for i in 1:n_comp]
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))
Expand All @@ -216,7 +216,7 @@ end
n_comp = 2
delta_x = 0.0001
extra_points = 2
initial_theta = 0.01
initial_theta = [0.01 for i in 1:n_comp]
g = GEKPLS(initial_X, initial_y, initial_grads, n_comp, delta_x, xlimits, extra_points,
initial_theta)
n_test = 100
Expand Down

0 comments on commit 8cebcbe

Please sign in to comment.