jeudi 25 novembre 2021

Simple method for generating a Sobol sequence

I am trying to implement a simple method of generating a Sobol seqeunce, which the author states can be done using the following syntax:

C#:

public IEnumerable<ulong> Sobol(ulong[] v)
{
    ulong s = 0;
    foreach (var r in Ruler()) yield return s ^= v[r];
}

public IEnumerable<int> Ruler()
{
    yield return 0;
    foreach (var r in Ruler())
    {
        yield return r + 1;
        yield return 0;
    }
}

VB.NET:

Public Iterator Function Sobol(ByVal v() As Double) As IEnumerable(Of ULong)
    Dim s As ULong = 0
    For Each r In Ruler()
        Yield s = s Xor v(r)
    Next
End Function

Public Iterator Function Ruler() As IEnumerable(Of Integer)
    Yield 0
    For Each r In Ruler()
        Yield r + 1
        Yield 0
    Next r
End Function

However, the author states that for example 0.100 = 1/2, which is obviously a binary to decimal conversion. Since the Sobol function returns large unsigned integers, I believe that modulo also needs to be applied, similar to x=(a*x mod c) for the linear congruential generator. Therefore, I don't think the author provided the entire solution.

I do have binary-to-decimal and decimal-to-binary, but just can't seem to be able to pick off Double values from the Sobol function which would represent the first elements in the Sobol sequence like 0, 1, 0.5, etc. I also have a Halton sequence generator, and I believe those values could be transformed into binary as the direction vectors.

Either way, if you could show a way to generate 1000 Double values from the Sobol function, it would be tremendously helpful.




Aucun commentaire:

Enregistrer un commentaire