Skip to content

Commit

Permalink
Merge pull request #131 from ArnoStrouwen/formatter
Browse files Browse the repository at this point in the history
reapply formatter
  • Loading branch information
ChrisRackauckas authored Feb 24, 2024
2 parents 87ffa2f + ab4ab67 commit 77e2734
Show file tree
Hide file tree
Showing 33 changed files with 618 additions and 533 deletions.
3 changes: 2 additions & 1 deletion .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
style = "sciml"
format_markdown = true
format_markdown = true
format_docstrings = true
34 changes: 16 additions & 18 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@ cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true)
include("pages.jl")

makedocs(sitename = "PolyChaos.jl",
clean = true, doctest = false, linkcheck = true,
linkcheck_ignore = [
"https://www.sciencedirect.com/science/article/pii/S235246771830105X",
],
strict = [
:doctest,
:linkcheck,
:parse_error,
# Other available options are
# :autodocs_block, :cross_references, :docs_block, :eval_block, :example_block, :footnote, :meta_block, :missing_docs, :setup_block
],
format = Documenter.HTML(analytics = "UA-90474609-3",
assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/PolyChaos/stable/"),
modules = [PolyChaos],
authors = "[email protected]",
pages = pages)
clean = true, doctest = false, linkcheck = true,
linkcheck_ignore = [
"https://www.sciencedirect.com/science/article/pii/S235246771830105X"
],
strict = [
:doctest,
:linkcheck,
:parse_error # Other available options are # :autodocs_block, :cross_references, :docs_block, :eval_block, :example_block, :footnote, :meta_block, :missing_docs, :setup_block
],
format = Documenter.HTML(analytics = "UA-90474609-3",
assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/PolyChaos/stable/"),
modules = [PolyChaos],
authors = "[email protected]",
pages = pages)

deploydocs(repo = "github.com/SciML/PolyChaos.jl.git",
target = "build")
target = "build")
34 changes: 17 additions & 17 deletions docs/pages.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
pages = Any["index.md",
"type_hierarchy.md",
"Usage" => [
"numerical_integration.md",
"quadrature_rules.md",
"orthogonal_polynomials_canonical.md",
"gaussian_mixture_model.md",
"multiple_discretization.md",
"scalar_products.md",
"Polynomial Chaos" => ["Basic Usage" => "pce_tutorial.md",
"Chi Squared, One DOF" => "chi_squared_k1.md",
"Chi Squared, Several DOFs" => "chi_squared_k_greater1.md",
"Random ODE" => "random_ode.md",
],
"Optimal Power Flow" => "DCsOPF.md",
],
"math.md",
"functions.md"]
"type_hierarchy.md",
"Usage" => [
"numerical_integration.md",
"quadrature_rules.md",
"orthogonal_polynomials_canonical.md",
"gaussian_mixture_model.md",
"multiple_discretization.md",
"scalar_products.md",
"Polynomial Chaos" => ["Basic Usage" => "pce_tutorial.md",
"Chi Squared, One DOF" => "chi_squared_k1.md",
"Chi Squared, Several DOFs" => "chi_squared_k_greater1.md",
"Random ODE" => "random_ode.md"
],
"Optimal Power Flow" => "DCsOPF.md"
],
"math.md",
"functions.md"]
10 changes: 5 additions & 5 deletions docs/src/DCsOPF.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,16 @@ We use `Mosek` to solve the problem; for academic use there are [free license](h
model = Model(with_optimizer(Mosek.Optimizer))
@variable(model, p[i in 1:Ng, j in 1:Npce], base_name="p")
@constraint(model, energy_balance[j in 1:Npce],
sum(p[i, j] for i in 1:Ng) - sum(d[i, j] for i in 1:Nd)==0)
sum(p[i, j] for i in 1:Ng) - sum(d[i, j] for i in 1:Nd)==0)
@constraint(model, con_pmax[i in 1:Ng],
[1 / λp[i] * (pmax[i] - mean(p[i, :], mop)); buildSOC(p[i, :], mop)] in SecondOrderCone())
[1 / λp[i] * (pmax[i] - mean(p[i, :], mop)); buildSOC(p[i, :], mop)] in SecondOrderCone())
@constraint(model, con_pmin[i in 1:Ng],
[1 / λp[i] * (mean(p[i, :], mop) - pmin[i]); buildSOC(p[i, :], mop)] in SecondOrderCone())
[1 / λp[i] * (mean(p[i, :], mop) - pmin[i]); buildSOC(p[i, :], mop)] in SecondOrderCone())
pl = Ψ * (Cp * p + Cd * d)
@constraint(model, con_plmax[i in 1:Nl],
[1 / λl[i] * (plmax[i] - mean(pl[1, :], mop)); buildSOC(pl[i, :], mop)] in SecondOrderCone())
[1 / λl[i] * (plmax[i] - mean(pl[1, :], mop)); buildSOC(pl[i, :], mop)] in SecondOrderCone())
@constraint(model, con_plmin[i in 1:Nl],
[1 / λl[i] * (mean(pl[1, :], mop) - plmin[i]); buildSOC(pl[i, :], mop)] in SecondOrderCone())
[1 / λl[i] * (mean(pl[1, :], mop) - plmin[i]); buildSOC(pl[i, :], mop)] in SecondOrderCone())
@objective(model, Min, sum(mean(p[i, :], mop) * c[i] for i in 1:Ng))
optimize!(model) # here we go
```
Expand Down
4 changes: 2 additions & 2 deletions docs/src/chi_squared_k1.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ With the tensors at hand, we can compute the Galerkin projection.

```@example mysetup
y = [sum(x[i] * x[j] * t3.get([i - 1, j - 1, m - 1]) / t2.get([m - 1, m - 1])
for i in 1:L, j in 1:L) for m in 1:L]
for i in 1:L, j in 1:L) for m in 1:L]
```

Let's compare the moments via PCE to the closed-form expressions.
Expand All @@ -125,7 +125,7 @@ Let's compare the moments via PCE to the closed-form expressions.
moms_analytic(k) = [k, sqrt(2k), sqrt(8 / k)]
function myskew(y)
e3 = sum(y[i] * y[j] * y[k] * t3.get([i - 1, j - 1, k - 1])
for i in 1:L, j in 1:L, k in 1:L)
for i in 1:L, j in 1:L, k in 1:L)
μ = y[1]
σ = std(y, opq)
(e3 - 3 * μ * σ^2 - μ^3) / (σ^3)
Expand Down
4 changes: 2 additions & 2 deletions docs/src/chi_squared_k_greater1.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Notice: there are more efficient ways to do this, but let's keep it simple.

```@example mysetup
y = [sum(x[i][j1] * x[i][j2] * t3.get([j1 - 1, j2 - 1, m - 1]) / t2.get([m - 1, m - 1])
for i in 1:k, j1 in 1:L, j2 in 1:L) for m in 1:L]
for i in 1:k, j1 in 1:L, j2 in 1:L) for m in 1:L]
```

Let's compare the moments via PCE to the closed-form expressions.
Expand All @@ -120,7 +120,7 @@ Let's compare the moments via PCE to the closed-form expressions.
moms_analytic(k) = [k, sqrt(2k), sqrt(8 / k)]
function myskew(y)
e3 = sum(y[i] * y[j] * y[k] * t3.get([i - 1, j - 1, k - 1])
for i in 1:L, j in 1:L, k in 1:L)
for i in 1:L, j in 1:L, k in 1:L)
μ = y[1]
σ = std(y, mop)
(e3 - 3 * μ * σ^2 - μ^3) / (σ^3)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/multiple_discretization.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Let's verify this by plotting the recurrence coefficients for several values of
```@example mysetup
Γ = 0:0.1:1;
ab = [mcdiscretization(N,
[n -> quad_gaussleg_mod(n, gam); n -> quad_gausscheb_mod(n, gam)])
[n -> quad_gaussleg_mod(n, gam); n -> quad_gausscheb_mod(n, gam)])
for gam in Γ];
bb = hcat([ab[i][2] for i in 1:length(Γ)]...);
b_leg = rm_legendre(N)[2];
Expand Down
2 changes: 1 addition & 1 deletion docs/src/random_ode.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ t3 = Tensor(3, opq); # \langle \phi_i \phi_j, \phi_k \rangle
# Galerkin-projected random differential equation
function ODEgalerkin(du, u, p, t)
du[:] = [sum(p[j + 1] * u[k + 1] * t3.get([j, k, m]) / t2.get([m, m]) for j in 0:L
for k in 0:L) for m in 0:L]
for k in 0:L) for m in 0:L]
end
probgalerkin = ODEProblem(ODEgalerkin, xinit, (0, tend), a)
Expand Down
10 changes: 5 additions & 5 deletions src/auxfuns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ julia> integrate(x -> 6x^5, opq)
- interval of integration is "hidden" in `nodes`.
"""
function integrate(f::Function, nodes::AbstractVector{<:Real},
weights::AbstractVector{<:Real})
weights::AbstractVector{<:Real})
dot(weights, f.(nodes))
end

Expand Down Expand Up @@ -119,7 +119,7 @@ function multi2uni(a::AbstractVector{<:Int}, ind::AbstractMatrix{<:Int})
m = length(a) # dimension of scalar product
l -= 1 # (l+1)-dimensional basis
maximum(a) > l && throw(DomainError(a,
"not enough elements in multi-index (requested: $(maximum(a)), max: $l)"))
"not enough elements in multi-index (requested: $(maximum(a)), max: $l)"))
A = zeros(Int64, p, m)
for (i, a_element) in enumerate(a)
A[:, i] = ind[a_element + 1, :]
Expand All @@ -128,14 +128,14 @@ function multi2uni(a::AbstractVector{<:Int}, ind::AbstractMatrix{<:Int})
end

function getentry(a::AbstractVector{<:Int}, T::SparseVector{<:Real, <:Int},
ind::AbstractMatrix{<:Int}, dim::Int)
ind::AbstractMatrix{<:Int}, dim::Int)
m = length(a)
l = size(ind, 1) - 1
minimum(a) < 0 && throw(DomainError(a, "no negative degrees allowed"))
maximum(a) > l && throw(DomainError(a,
"not enough elements in multi-index (requested: $(maximum(a)), max: $l)"))
"not enough elements in multi-index (requested: $(maximum(a)), max: $l)"))
m != dim && throw(DomainError(m,
"length $m of provided index $a is inconsistent with dimension $(dim) of multi-index"))
"length $m of provided index $a is inconsistent with dimension $(dim) of multi-index"))
# a .+= 1
sort!(a; rev = true)

Expand Down
20 changes: 10 additions & 10 deletions src/evaluate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ which returns an array of dimensions `(mop.dim,size(x,1))`.
- `size(a)==size(b)=p`.
"""
function evaluate(n::Int, x::AbstractArray{<:Real}, a::AbstractVector{<:Real},
b::AbstractVector{<:Real})
b::AbstractVector{<:Real})
@assert n>=0 "Degree n has to be non-negative (currently n=$n)."
# if length(a)==0 warn("Length of a is 0.") end
@assert length(a)==length(b) "Inconsistent number of recurrence coefficients."
Expand Down Expand Up @@ -105,7 +105,7 @@ evaluate(n::Int, x::Real, op::AbstractOrthoPoly) = evaluate(n, [x], op)

# univariate + several bases
function evaluate(ns, x::AbstractArray{<:Real}, a::AbstractVector{<:Real},
b::AbstractVector{<:Real})
b::AbstractVector{<:Real})
hcat(map(i -> evaluate(i, x, a, b), ns)...)
end
function evaluate(ns, x::Real, a::AbstractVector{<:Real}, b::AbstractVector{<:Real})
Expand All @@ -121,8 +121,8 @@ evaluate(x::Real, op::AbstractOrthoPoly) = evaluate([x], op)

# multivariate
function evaluate(n::AbstractVector{<:Int}, x::AbstractMatrix{<:Real},
a::AbstractVector{<:AbstractVector{<:Real}},
b::AbstractVector{<:AbstractVector{<:Real}})
a::AbstractVector{<:AbstractVector{<:Real}},
b::AbstractVector{<:AbstractVector{<:Real}})
@assert length(n)==size(x, 2) "number of univariate bases (= $(length(n))) inconsistent with columns points x (= $(size(x,2)))"
val = ones(Float64, size(x, 1))
for i in 1:length(n)
Expand All @@ -131,8 +131,8 @@ function evaluate(n::AbstractVector{<:Int}, x::AbstractMatrix{<:Real},
return val
end
function evaluate(n::AbstractVector{<:Int}, x::AbstractVector{<:Real},
a::AbstractVector{<:AbstractVector{<:Real}},
b::AbstractVector{<:AbstractVector{<:Real}})
a::AbstractVector{<:AbstractVector{<:Real}},
b::AbstractVector{<:AbstractVector{<:Real}})
evaluate(n, reshape(x, 1, length(x)), a, b)
end
function evaluate(n::AbstractVector{<:Int}, x::AbstractMatrix{<:Real}, op::MultiOrthoPoly)
Expand All @@ -144,8 +144,8 @@ end

# using multi-index + multivariate
function evaluate(ind::AbstractMatrix{<:Int}, x::AbstractMatrix{<:Real},
a::AbstractVector{<:AbstractVector{<:Real}},
b::AbstractVector{<:AbstractVector{<:Real}})
a::AbstractVector{<:AbstractVector{<:Real}},
b::AbstractVector{<:AbstractVector{<:Real}})
vals = map(i -> evaluate(ind[i, :], x, a, b), Base.OneTo(size(ind, 1)))
hcat(vals...) |> transpose |> Matrix
end
Expand All @@ -156,8 +156,8 @@ end
evaluate(x::AbstractMatrix{<:Real}, mop::MultiOrthoPoly) = evaluate(mop.ind, x, mop)

function evaluate(ind::AbstractMatrix{<:Int}, x::AbstractVector{<:Real},
a::AbstractVector{<:AbstractVector{<:Real}},
b::AbstractVector{<:AbstractVector{<:Real}})
a::AbstractVector{<:AbstractVector{<:Real}},
b::AbstractVector{<:AbstractVector{<:Real}})
evaluate(ind, reshape(x, 1, length(x)), a, b)
end
function evaluate(ind::AbstractMatrix{<:Int}, x::AbstractVector{<:Real}, op::MultiOrthoPoly)
Expand Down
32 changes: 16 additions & 16 deletions src/polynomial_chaos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function convert2affinePCE(mu::Real, sigma::Real, op::GaussOrthoPoly)
end

function convert2affinePCE(par1::Real, par2::Real, op::Uniform01OrthoPoly;
kind::String = "lbub")
kind::String = "lbub")
kind = _checkKind(kind)
a1, a2 = if kind == "lbub"
_checkBounds(par1, par2)
Expand All @@ -97,7 +97,7 @@ function convert2affinePCE(par1::Real, par2::Real, op::Uniform01OrthoPoly;
end

function convert2affinePCE(par1::Real, par2::Real, op::Uniform_11OrthoPoly;
kind::String = "lbub")
kind::String = "lbub")
kind = _checkKind(kind)
a1, a2 = if kind == "lbub"
_checkBounds(par1, par2)
Expand All @@ -118,7 +118,7 @@ function convert2affinePCE(p1::Real, p2::Real, op::Beta01OrthoPoly; kind::String
elseif kind == "μσ"
_checkStandardDeviation(p2)
a1, a2 = p1 - sqrt/ β) * sqrt(1 + α + β) * p2,
+ β) * sqrt((α + β + 1) /* β)) * p2
+ β) * sqrt((α + β + 1) /* β)) * p2
end
convert2affinePCE(a1, a2, first(op.α))
end
Expand Down Expand Up @@ -176,7 +176,7 @@ Multivariate extension, which provides an array of samples with `n` rows and
as many columns as the multimeasure has univariate measures.
"""
function sampleMeasure(n::Int, w::Function, dom::Tuple{<:Real, <:Real};
method::String = "adaptiverejection")
method::String = "adaptiverejection")
_checkNumberOfSamples(n)
method = lowercase(method)

Expand Down Expand Up @@ -222,13 +222,13 @@ end
sampleMeasure(n::Int, meas::LogisticMeasure) = sampleMeasure(n, Logistic())

function sampleMeasure(n::Int, meas::AbstractCanonicalMeasure;
method::String = "adaptiverejection")
method::String = "adaptiverejection")
@warn "ignoring keyword method; sampling from Distributions.jl instead"
sampleMeasure(n, meas)
end

function sampleMeasure(n::Int, measure::ProductMeasure;
method::Vector{String} = _createMethodVector(measure))
method::Vector{String} = _createMethodVector(measure))
samples = Matrix{Float64}(undef, n, 0)
for (k, unimeasure) in enumerate(measure.measures)
samples = hcat(samples, sampleMeasure(n, unimeasure; method = method[k]))
Expand All @@ -237,7 +237,7 @@ function sampleMeasure(n::Int, measure::ProductMeasure;
end

function sampleMeasure(n::Int, mop::MultiOrthoPoly;
method::Vector{String} = _createMethodVector(mop))
method::Vector{String} = _createMethodVector(mop))
sampleMeasure(n, mop.measure; method = method)
end

Expand All @@ -254,7 +254,7 @@ where `L+1 = length(x)` and ``x_j`` is the ``j``th sample where ``j=1,\\dots,m``
with `m = length(ξ)`.
"""
function evaluatePCE(x::AbstractVector{<:Real}, ξ::AbstractVector{<:Real},
α::AbstractVector{<:Real}, β::AbstractVector{<:Real})
α::AbstractVector{<:Real}, β::AbstractVector{<:Real})
length(α) != length(β) &&
throw(InconsistencyError("inconsistent number of recurrence coefficients"))
Nsmpl = length(ξ)
Expand All @@ -271,17 +271,17 @@ function evaluatePCE(x::AbstractVector{<:Real}, ξ::AbstractVector{<:Real},
ϕ * x
end
function evaluatePCE(x::AbstractVector{<:Real}, ξ::Real, α::AbstractVector{<:Real},
β::AbstractVector{<:Real})
β::AbstractVector{<:Real})
evaluatePCE(x, [ξ], α, β)
end
function evaluatePCE(x::AbstractVector{<:Real}, ξ::AbstractVector{<:Real},
op::AbstractOrthoPoly)
op::AbstractOrthoPoly)
evaluatePCE(x, ξ, op.α, op.β)
end

function evaluatePCE(x::AbstractVector{<:Real}, ξ::AbstractMatrix{<:Real},
α::AbstractVector{<:AbstractVector{<:Real}},
β::AbstractVector{<:AbstractVector{<:Real}}, ind::AbstractMatrix{Int})
α::AbstractVector{<:AbstractVector{<:Real}},
β::AbstractVector{<:AbstractVector{<:Real}}, ind::AbstractMatrix{Int})
Nsmpl = size(ξ, 1)
_checkNumberOfSamples(Nsmpl)
!(length(α) == length(β) == size(ξ, 2) == size(ind, 2)) &&
Expand All @@ -296,7 +296,7 @@ function evaluatePCE(x::AbstractVector{<:Real}, ξ::AbstractMatrix{<:Real},
ϕ * x
end
function evaluatePCE(x::AbstractVector{<:Real}, ξ::AbstractMatrix{<:Real},
mOP::MultiOrthoPoly)
mOP::MultiOrthoPoly)
a, b = coeffs(mOP)
evaluatePCE(x, ξ, a, b, mOP.ind)
end
Expand All @@ -318,19 +318,19 @@ samplePCE(n::Int,x::AbstractVector{<:Real},mop::MultiOrthoPoly;method::Vector{St
```
"""
function samplePCE(n::Int, x::AbstractVector{<:Real}, op::AbstractOrthoPoly;
method::String = "adaptiverejection")
method::String = "adaptiverejection")
ξ = sampleMeasure(n, op; method = method)
evaluatePCE(x, ξ, op)
end

function samplePCE(n::Int, x::AbstractVector{<:Real}, op::AbstractCanonicalOrthoPoly;
method::String = "adaptiverejection")
method::String = "adaptiverejection")
ξ = sampleMeasure(n, op)
evaluatePCE(x, ξ, op)
end

function samplePCE(n::Int, x::AbstractVector{<:Real}, mop::MultiOrthoPoly;
method::Vector{String} = _createMethodVector(mop))
method::Vector{String} = _createMethodVector(mop))
ξ = sampleMeasure(n, mop; method = method)
evaluatePCE(x, ξ, mop)
end
Expand Down
Loading

0 comments on commit 77e2734

Please sign in to comment.