Skip to content
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

Change to use Symbolics.variables to create an array of symbolic vars #18

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/PCE/PCE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ function PCE(states, uni_basis::AbstractVector{<:Pair})
moments = Vector{Num}[]
for (i, state) in enumerate(collect(states))
ind_vars = get_independent_vars(state)
create_var = isempty(ind_vars) ? name -> (@variables $(name))[1] :
name -> (@variables $(name)(ind_vars...))[1]
push!(moments, [create_var(moment_name(i, j)) for j in 1:n_basis])
new_vars = if isempty(ind_vars)
Symbolics.variables(:z, i:i, 1:n_basis)
else
map(z -> z(ind_vars...),
Symbolics.variables(:z, i:i, 1:n_basis; T = Symbolics.FnType))
end
push!(moments, vec(new_vars))
end
ansatz = [states[i] => sum(moments[i][j] * sym_basis[j] for j in 1:n_basis)
for i in 1:n_states]
Expand Down
16 changes: 5 additions & 11 deletions src/PCE/PCE_utils.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import PolyChaos: computeSP2, computeSP, dim, deg

# moment names
function moment_name(i, j)
return Symbol("z" * Symbolics.map_subscripts(i) *
"₋" * Symbolics.map_subscripts(j))
end

# getting independent variables
function get_independent_vars(var)
return []
Expand Down Expand Up @@ -109,7 +103,7 @@ end

"""
`TensorProductOrthoPoly` objects represent bases formed as the tensor product of univariate `PolyChaos.AbstractOrthoPoly` bases.
By default the basis elements of the tensor product are restricted to polynomials with total degree up to the maximum degree among the
By default the basis elements of the tensor product are restricted to polynomials with total degree up to the maximum degree among the
univariate bases. This maximum degree can be manually specified, however.
"""
struct TensorProductOrthoPoly{M, U}
Expand Down Expand Up @@ -149,8 +143,8 @@ end
"""
$(TYPEDSIGNATURES)

computes inner product between basis functions of a `TensorProductOrthoPoly` via
`PolyChaos`'s infrastructure (exploiting the tensor product form).
computes inner product between basis functions of a `TensorProductOrthoPoly` via
`PolyChaos`'s infrastructure (exploiting the tensor product form).
"""
function computeSP(basis_fxns, tpop::TensorProductOrthoPoly,
integrators = tpop.uni)
Expand Down Expand Up @@ -195,8 +189,8 @@ end
"""
$(TYPEDSIGNATURES)

Compute the an ascending list of `n`-dimensional multi-indices with fixed `grade` (= sum of entries)
in graded reverse lexicographic order. Constraints on the degrees considered can be incorporated.
Compute the an ascending list of `n`-dimensional multi-indices with fixed `grade` (= sum of entries)
in graded reverse lexicographic order. Constraints on the degrees considered can be incorporated.
"""
function grevlex(n::Int, grade::Int)
if n == 1
Expand Down