Skip to content

Commit

Permalink
search for files in LDData repo + format
Browse files Browse the repository at this point in the history
  • Loading branch information
alegresor committed Feb 8, 2024
1 parent d1525e9 commit 223b5ab
Show file tree
Hide file tree
Showing 6 changed files with 21,265 additions and 21,248 deletions.
33 changes: 13 additions & 20 deletions docs/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,12 @@ Reset!(rls)

#### Pregenerated

We include many alternative generating matrices for digital sequences in [this directory](https://bitbucket.org/dnuyens/qmc-generators/src/master/DIGSEQ/). To use an alternative, simply supply the relative path
We support user defined generating matrices for digital sequences and lattice sequences in the formats specified by the [LDData repository](https://github.com/QMCSoftware/LDData/tree/main).

For digital sequences, you may supply a path to a local file or a relative path from [`https://github.com/QMCSoftware/LDData/tree/main/dnet`](https://github.com/QMCSoftware/LDData/tree/main/dnet) as shown below

```jldoctest
ds = DigitalSeqB2G(3,"sobolmats/sobol_alpha2_Bs64.col")
ds = DigitalSeqB2G(3,"mps.sobol_alpha2_Bs64.txt")
Next(ds,4)
# output
4×3 Matrix{Float64}:
Expand All @@ -341,10 +343,10 @@ Next(ds,4)
0.4375 0.9375 0.1875
```

Linear matrix scrambling also accepts these relative paths
Linear matrix scrambling also accepts these paths

```jldoctest
ds = DigitalSeqB2G(LinearMatrixScramble(3,"sobolmats/sobol_alpha2_Bs64.col",11))
ds = DigitalSeqB2G(LinearMatrixScramble(3,"mps.sobol_alpha2_Bs64.txt",11))
Next(ds,4)
# output
4×3 Matrix{Float64}:
Expand All @@ -354,10 +356,10 @@ Next(ds,4)
0.251783 0.983926 0.233902
```

Alternative lattice generating vectors are available in [this directory](https://bitbucket.org/dnuyens/qmc-generators/src/master/LATSEQ/). For Lattices, after supplying the path you also need to pass the $m$ value in the file name
For lattice sequences, you may supply a path to a local file or a relative path from [`https://github.com/QMCSoftware/LDData/tree/main/lattice`](https://github.com/QMCSoftware/LDData/tree/main/lattice) as shown below

```jldoctest
ls = LatticeSeqB2(3,"exod8_base2_m13.txt",13)
ls = LatticeSeqB2(3,"mps.exod8_base2_m13.txt")
Next(ls,4)
# output
4×3 Matrix{Float64}:
Expand All @@ -369,21 +371,12 @@ Next(ls,4)

#### User Defined

One may supply their own generating matrix to construct a base 2 digital sequence, for example
For digital sequences, you may supply the generating matrix followed by $t$ where $t$ is the number of bits in each integer representations

```jldoctest tut_ds_custom_matrix
m = 5
C1 = [BigInt(2^i) for i=0:(m-1)]
C2 = [BigInt(1) for i=1:m]
for i in 2:m C2[i] = (C2[i-1] << 1) ⊻ C2[i-1] end
generating_matrix = vcat(C1',C2')
# output
2×5 Matrix{BigInt}:
1 2 4 8 16
1 3 5 15 17
```
```jldoctest tut_ds_custom_matrix
ds = DigitalSeqB2G(2,generating_matrix)
t = 5
generating_matrix = Matrix{BigInt}([16 8 4 2 1; 16 24 20 30 17])
ds = DigitalSeqB2G(2,generating_matrix,t)
Next(ds,4)
# output
4×2 Matrix{Float64}:
Expand All @@ -396,7 +389,7 @@ Next(ds,4)
Linear matrix scrambling also accommodates such constructions

```jldoctest tut_ds_custom_matrix
ds = DigitalSeqB2G(LinearMatrixScramble(2,generating_matrix,11))
ds = DigitalSeqB2G(LinearMatrixScramble(2,generating_matrix,t,11))
Next(ds,4)
# output
4×2 Matrix{Float64}:
Expand Down
2 changes: 1 addition & 1 deletion src/QMCGenerators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CairoMakie
using LaTeXStrings

include("util.jl")
export bitreverse,spawn
export spawn

include("digitalseqb2g_default_gmatrix.jl")
include("digitalseqb2g.jl")
Expand Down
66 changes: 43 additions & 23 deletions src/digitalseqb2g.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ struct LinearMatrixScramble
t::Int64
end

function LinearMatrixScramble(s::Int64,Cs::Matrix{BigInt},rng::Xoshiro) # Matousek
@assert s <= size(Cs,1)
m = size(Cs,2)
tog = maximum(ndigits.(Cs[1:s,:],base=2))
@assert tog<=64
function LinearMatrixScramble(s::Int64,Csr::Matrix{BigInt},tog::Int64,rng::Xoshiro) # Matousek
@assert s <= size(Csr,1)
Csr = Csr[1:s,:]
m = size(Csr,2)
if tog>64
Csr .>>= (tog-64)
tog = 64
end
Csr = convert.(UInt64,Csr)
t = max(53,tog)
Csr = convert.(UInt64,bitreverse.(Cs[1:s,:],tog))
Csrlms = zeros(UInt64,s,m)
for j=1:s
for k=0:t-1
Expand All @@ -31,47 +34,64 @@ function LinearMatrixScramble(s::Int64,Cs::Matrix{BigInt},rng::Xoshiro) # Matous
LinearMatrixScramble(s,Csrlms,m,t)
end

LinearMatrixScramble(s::Int64,Cs::Matrix{BigInt},seed::Int64) = LinearMatrixScramble(s,Cs,Xoshiro(seed))
LinearMatrixScramble(s::Int64,Csr::Matrix{BigInt},tog::Int64,seed::Int64) = LinearMatrixScramble(s,Csr,tog,Xoshiro(seed))
LinearMatrixScramble(s::Int64,Csr::Matrix{BigInt},tog::Int64) = LinearMatrixScramble(s,Csr,tog,Xoshiro())

LinearMatrixScramble(s::Int64,Cs::Matrix{BigInt}) = LinearMatrixScramble(s,Cs,Xoshiro())
function LinearMatrixScramble(s::Int64,path::String,rng::Xoshiro)
if !isfile(path) path = download(joinpath("https://raw.githubusercontent.com/QMCSoftware/LDData/main/dnet/",path)) end
datafile = readdlm(path,String;comments=true)
b = parse(Int64,datafile[1,1]); @assert b == 2
tog = parse(Int64,datafile[4,1])
Csr = parse.(BigInt,datafile[5:end,:])
LinearMatrixScramble(s,Csr,tog,rng)
end

LinearMatrixScramble(s::Int64,path::String,rng::Xoshiro) = LinearMatrixScramble(s,readdlm(download(joinpath("https://bitbucket.org/dnuyens/qmc-generators/raw/cb0f2fb10fa9c9f2665e41419097781b611daa1e/DIGSEQ/",path)),BigInt),rng)
LinearMatrixScramble(s::Int64,path::String,seed::Int64) = LinearMatrixScramble(s,readdlm(download(joinpath("https://bitbucket.org/dnuyens/qmc-generators/raw/cb0f2fb10fa9c9f2665e41419097781b611daa1e/DIGSEQ/",path)),BigInt),seed)
LinearMatrixScramble(s::Int64,path::String) = LinearMatrixScramble(s,readdlm(download(joinpath("https://bitbucket.org/dnuyens/qmc-generators/raw/cb0f2fb10fa9c9f2665e41419097781b611daa1e/DIGSEQ/",path)),BigInt))
LinearMatrixScramble(s::Int64,path::String,seed::Int64) = LinearMatrixScramble(s,path,Xoshiro(seed))
LinearMatrixScramble(s::Int64,path::String) = LinearMatrixScramble(s,path,Xoshiro())

LinearMatrixScramble(s::Int64,rng::Xoshiro) = LinearMatrixScramble(s,DEFAULT_DIGITALSEQB2G_GMATRIX,rng)
LinearMatrixScramble(s::Int64,seed::Int64) = LinearMatrixScramble(s,DEFAULT_DIGITALSEQB2G_GMATRIX,seed)
LinearMatrixScramble(s::Int64) = LinearMatrixScramble(s,DEFAULT_DIGITALSEQB2G_GMATRIX)
LinearMatrixScramble(s::Int64,rng::Xoshiro) = LinearMatrixScramble(s,DEFAULT_DIGITALSEQB2G_GMATRIX,Int64(32),rng)
LinearMatrixScramble(s::Int64,seed::Int64) = LinearMatrixScramble(s,DEFAULT_DIGITALSEQB2G_GMATRIX,Int64(32),Xoshiro(seed))
LinearMatrixScramble(s::Int64) = LinearMatrixScramble(s,DEFAULT_DIGITALSEQB2G_GMATRIX,Int64(32),Xoshiro())

mutable struct DigitalSeqB2G
const name::String
const s::Int64 # dimension
const Csr::Matrix{UInt64}
const m::Int64 # number of columns, can generate 2^m points
const t::Int64 # maximum number of bits in an element of Cs
const t::Int64 # maximum number of bits in an element of Csr
const alpha::Float64 # t/m, the order of the net
const n::Int64 # maximum number of supported points
const recipd::Union{BigFloat,Float64} # multiplication factor
k::Int64 # index in the sequence
cur::Vector{UInt64}
end

function DigitalSeqB2G(s::Int64,Cs::Matrix{BigInt})
@assert s <= size(Cs,1)
m = size(Cs,2)
t = maximum(ndigits.(Cs[1:s,:],base=2))
@assert t<=64
function DigitalSeqB2G(s::Int64,Csr::Matrix{BigInt},t::Int64)
@assert s <= size(Csr,1)
Csr = Csr[1:s,:]
m = size(Csr,2)
if t>64
Csr .>>= (t-64)
t = 64
end
Csr = convert.(UInt64,Csr)
alpha = t/m
n = 2^m
recipd = t>53 ? BigFloat(2)^(-t) : Float64(2)^(-t)
Csr = convert.(UInt64,bitreverse.(Cs[1:s,:],t))
cur = zeros(UInt64,s)
DigitalSeqB2G("Digital Seq B2",s,Csr,m,t,alpha,n,recipd,-1,cur)
end

DigitalSeqB2G(s::Int64,path::String) = DigitalSeqB2G(s,readdlm(download(joinpath("https://bitbucket.org/dnuyens/qmc-generators/raw/cb0f2fb10fa9c9f2665e41419097781b611daa1e/DIGSEQ/",path)),BigInt))
function DigitalSeqB2G(s::Int64,path::String)
if !isfile(path) path = download(joinpath("https://raw.githubusercontent.com/QMCSoftware/LDData/main/dnet/",path)) end
datafile = readdlm(path,String;comments=true)
b = parse(Int64,datafile[1,1]); @assert b == 2
t = parse(Int64,datafile[4,1])
Csr = parse.(BigInt,datafile[5:end,:])
DigitalSeqB2G(s,Csr,t)
end

DigitalSeqB2G(s::Int64) = DigitalSeqB2G(s,DEFAULT_DIGITALSEQB2G_GMATRIX)
DigitalSeqB2G(s::Int64) = DigitalSeqB2G(s,DEFAULT_DIGITALSEQB2G_GMATRIX,Int64(32))

function DigitalSeqB2G(rlms::LinearMatrixScramble)
alpha = rlms.t/rlms.m
Expand Down
Loading

0 comments on commit 223b5ab

Please sign in to comment.