ScPo Computational Economics 2018
#Pkg.add("FastGaussQuadrature")
using FastGaussQuadrature
np = 3
rules = Dict("hermite" => gausshermite(np),
"chebyshev" => gausschebyshev(np),
"legendre" => gausslegendre(np),
"lobatto" => gausslobatto(np))
using DataFrames
integ = DataFrame(Rule=Symbol[Symbol(x) for x in keys(rules)],nodes=[x[1] for x in values(rules)],weights=[x[2] for x in values(rules)])
INFO: Precompiling module FastGaussQuadrature. WARNING: Method definition midpoints(Base.Range{T} where T) in module Base at deprecated.jl:56 overwritten in module StatsBase at /Users/florian.oswald/.julia/v0.6/StatsBase/src/hist.jl:535. WARNING: Method definition midpoints(AbstractArray{T, 1} where T) in module Base at deprecated.jl:56 overwritten in module StatsBase at /Users/florian.oswald/.julia/v0.6/StatsBase/src/hist.jl:533.
Rule | nodes | weights | |
---|---|---|---|
1 | lobatto | [-1.0, 0.0, 1.0] | [0.333333, 1.33333, 0.333333] |
2 | hermite | [-1.22474, -8.88178e-16, 1.22474] | [0.295409, 1.18164, 0.295409] |
3 | legendre | [-0.774597, 0.0, 0.774597] | [0.555556, 0.888889, 0.555556] |
4 | chebyshev | [-0.866025, 6.12323e-17, 0.866025] | [1.0472, 1.0472, 1.0472] |
A = [1 2;3 4]
B = [1;10]
kron(A,B)
kron(B,A)
4×2 Array{Int64,2}: 1 2 3 4 10 20 30 40
rules["hermite"]
.rules["hermite"][1]
repeat(rules["hermite"][1],inner=[1],outer=[9])
27-element Array{Float64,1}: -1.22474 -8.88178e-16 1.22474 -1.22474 -8.88178e-16 1.22474 -1.22474 -8.88178e-16 1.22474 -1.22474 -8.88178e-16 1.22474 -1.22474 ⋮ -1.22474 -8.88178e-16 1.22474 -1.22474 -8.88178e-16 1.22474 -1.22474 -8.88178e-16 1.22474 -1.22474 -8.88178e-16 1.22474
nodes = Any[]
push!(nodes,repeat(rules["hermite"][1],inner=[1],outer=[9])) # dim1
push!(nodes,repeat(rules["hermite"][1],inner=[3],outer=[3])) # dim2
push!(nodes,repeat(rules["hermite"][1],inner=[9],outer=[1])) # dim3
weights = kron(rules["hermite"][2],kron(rules["hermite"][2],rules["hermite"][2]))
df = hcat(DataFrame(weights=weights),DataFrame(nodes,[:dim1,:dim2,:dim3]))
weights | dim1 | dim2 | dim3 | |
---|---|---|---|---|
1 | 0.0257793 | -1.22474 | -1.22474 | -1.22474 |
2 | 0.103117 | -8.88178e-16 | -1.22474 | -1.22474 |
3 | 0.0257793 | 1.22474 | -1.22474 | -1.22474 |
4 | 0.103117 | -1.22474 | -8.88178e-16 | -1.22474 |
5 | 0.412469 | -8.88178e-16 | -8.88178e-16 | -1.22474 |
6 | 0.103117 | 1.22474 | -8.88178e-16 | -1.22474 |
7 | 0.0257793 | -1.22474 | 1.22474 | -1.22474 |
8 | 0.103117 | -8.88178e-16 | 1.22474 | -1.22474 |
9 | 0.0257793 | 1.22474 | 1.22474 | -1.22474 |
10 | 0.103117 | -1.22474 | -1.22474 | -8.88178e-16 |
11 | 0.412469 | -8.88178e-16 | -1.22474 | -8.88178e-16 |
12 | 0.103117 | 1.22474 | -1.22474 | -8.88178e-16 |
13 | 0.412469 | -1.22474 | -8.88178e-16 | -8.88178e-16 |
14 | 1.64987 | -8.88178e-16 | -8.88178e-16 | -8.88178e-16 |
15 | 0.412469 | 1.22474 | -8.88178e-16 | -8.88178e-16 |
16 | 0.103117 | -1.22474 | 1.22474 | -8.88178e-16 |
17 | 0.412469 | -8.88178e-16 | 1.22474 | -8.88178e-16 |
18 | 0.103117 | 1.22474 | 1.22474 | -8.88178e-16 |
19 | 0.0257793 | -1.22474 | -1.22474 | 1.22474 |
20 | 0.103117 | -8.88178e-16 | -1.22474 | 1.22474 |
21 | 0.0257793 | 1.22474 | -1.22474 | 1.22474 |
22 | 0.103117 | -1.22474 | -8.88178e-16 | 1.22474 |
23 | 0.412469 | -8.88178e-16 | -8.88178e-16 | 1.22474 |
24 | 0.103117 | 1.22474 | -8.88178e-16 | 1.22474 |
25 | 0.0257793 | -1.22474 | 1.22474 | 1.22474 |
26 | 0.103117 | -8.88178e-16 | 1.22474 | 1.22474 |
27 | 0.0257793 | 1.22474 | 1.22474 | 1.22474 |
dimx
, multiply with the corresponding weight, and sum.{}
stands for the fractional part of a number. for $v=\sqrt{2}$,
$$ x_1 = \{1 \sqrt{2}\} = \{1.4142\} = 0.4142, x_2 = \{2 \sqrt{2}\} = \{2.8242\} = 0.8242,... $$# Pkg.add("Sobol")
using Sobol
using Plots
s = SobolSeq(2)
p = hcat([next(s) for i = 1:1024]...)'
scatter(p[:,1], p[:,2], m=(:red,:dot,1.0),legend=false)
ArgumentError: Module Sobol not found in current path. Run `Pkg.add("Sobol")` to install the Sobol package. Stacktrace: [1] _require(::Symbol) at ./loading.jl:428 [2] require(::Symbol) at ./loading.jl:398 [3] include_string(::String, ::String) at ./loading.jl:515