Skip to content

Commit

Permalink
refactor(SurrogatesPolyChaos): op to orthopolys
Browse files Browse the repository at this point in the history
  • Loading branch information
sathvikbhagavan committed Jul 18, 2024
1 parent 2ccd236 commit 1332ae8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/SurrogatesPolyChaos/src/SurrogatesPolyChaos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function PolynomialChaosSurrogate(x, y, lb::Number, ub::Number;
end

function PolynomialChaosSurrogate(x, y, lb, ub;
op = MultiOrthoPoly([GaussOrthoPoly(2) for j in 1:length(lb)], 2))
orthopolys = MultiOrthoPoly([GaussOrthoPoly(2) for j in 1:length(lb)], 2))
n = length(x)
d = length(lb)
poly_degree = orthopolys.deg
Expand Down Expand Up @@ -57,16 +57,17 @@ function (pcND::PolynomialChaosSurrogate)(val)
return sum
end

function _calculatepce_coeff(x, y, num_of_multi_indexes, op::AbstractCanonicalOrthoPoly)
function _calculatepce_coeff(
x, y, num_of_multi_indexes, orthopolys::AbstractCanonicalOrthoPoly)
n = length(x)
A = zeros(eltype(x), n, num_of_multi_indexes)
for i in 1:n
A[i, :] = PolyChaos.evaluate(x[i], op)
A[i, :] = PolyChaos.evaluate(x[i], orthopolys)
end
return (A' * A) \ (A' * y)
end

function _calculatepce_coeff(x, y, num_of_multi_indexes, op::MultiOrthoPoly)
function _calculatepce_coeff(x, y, num_of_multi_indexes, orthopolys::MultiOrthoPoly)
n = length(x)
d = length(x[1])
A = zeros(eltype(x[1]), n, num_of_multi_indexes)
Expand All @@ -75,7 +76,7 @@ function _calculatepce_coeff(x, y, num_of_multi_indexes, op::MultiOrthoPoly)
for j in 1:d
xi[j] = x[i][j]
end
A[i, :] = PolyChaos.evaluate(xi, op)
A[i, :] = PolyChaos.evaluate(xi, orthopolys)
end
return (A' * A) \ (A' * y)
end
Expand All @@ -84,7 +85,7 @@ function SurrogatesBase.update!(polych::PolynomialChaosSurrogate, x_new, y_new)
polych.x = vcat(polych.x, x_new)
polych.y = vcat(polych.y, y_new)
polych.coeff = _calculatepce_coeff(polych.x, polych.y, polych.num_of_multi_indexes,
polych.ortopolys)
polych.orthopolys)
nothing
end

Expand Down

0 comments on commit 1332ae8

Please sign in to comment.