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

stateful iteration #15

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

stateful iteration #15

wants to merge 3 commits into from

Conversation

cscherrer
Copy link
Owner

@cscherrer cscherrer commented May 24, 2021

Using Iterators.Stateful, we can rewrite our Sobol sequence interface as

export SobolHypercube

struct SobolHypercube{k} <: Hypercube{k}
    seq :: SobolSeq{k}
    value :: Vector{Float64}
    iter :: Iterators.Stateful{Vector{Float64}, Union{Nothing, Tuple{Float64, Int64}}}

    function SobolHypercube(k::Int)
        seq = SobolSeq(k)
        value = Sobol.next!(seq)
        return new{k}(seq, value, Iterators.Stateful(value))
    end
end

export next!

function next!::SobolHypercube)
    Sobol.next!.seq, ω.value)
    ω.iter.nextvalstate = iterate.value)
    ω.iter.taken = 0
    return ω
end

Base.rand::SobolHypercube) = popfirst!.iter)

@cscherrer
Copy link
Owner Author

@ParadaCarleton @mschauer how does this look?

@codecov
Copy link

codecov bot commented May 24, 2021

Codecov Report

Merging #15 (9fa3e43) into main (8725354) will decrease coverage by 2.12%.
The diff coverage is 43.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #15      +/-   ##
==========================================
- Coverage   42.25%   40.13%   -2.13%     
==========================================
  Files           8        8              
  Lines         142      152      +10     
==========================================
+ Hits           60       61       +1     
- Misses         82       91       +9     
Impacted Files Coverage Δ
src/hypercube.jl 29.03% <0.00%> (-11.88%) ⬇️
src/optional/Sobol.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8725354...9fa3e43. Read the comment docs.

@cscherrer
Copy link
Owner Author

We can abstract this a little, then Sobol and GoldenSequences should be able to share the same code

@ParadaCarleton
Copy link

Looks good! Don't see any issues.

@mschauer
Copy link

Am I right to assume we only need ever infinite sequences (which perhaps repeat?). In that case I think we should implement our own version of stateful.

@cscherrer
Copy link
Owner Author

@mschauer I think I know what you mean, but maybe we should introduce some terminology to be safe. For both Sobol and GoldenSequences, the user selects a dimensionality at construction time (well, GS can do some other fancy things, but let's ignore those for now). If we ask for a k-dimensional sequence, let's call those k elements "inner", so "inner traversal" or "inner iteration".

So we generally step through these k elements, and then "step" or "reset" or next! (or whatever) the sequence. This loads the next k elements. Let's call this reloading an "outer" operation.

Ok, so with that I think the inner iteration will generally be finite (I think it has to be?), but the outer iteration will not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants