lds_gen package

Submodules

lds_gen.ilds module

class lds_gen.ilds.Halton(base: Sequence[int], scale: Sequence[int])[source]

Bases: object

Halton sequence generator

The Halton class is a sequence generator that generates points in a 2-dimensional space using the Halton sequence. The Halton sequence is a low-discrepancy sequence that is often used in quasi-Monte Carlo methods. It is generated by iterating over two different bases and calculating the fractional parts of the numbers in those bases. The Halton class keeps track of the current count and bases, and provides a pop() method that returns the next point in the sequence as a List[int].

Examples

>>> hgen = Halton([2, 3], [11, 7])
>>> hgen.reseed(0)
>>> for _ in range(10):
...     print(hgen.pop())
...
[1024, 729]
[512, 1458]
[1536, 243]
[256, 972]
[1280, 1701]
[768, 486]
[1792, 1215]
[128, 1944]
[1152, 81]
[640, 810]
pop() List[int][source]

The pop function returns a list of two integers by popping elements from vdc0 and vdc1.

Returns:

The pop method is returning a list of two integers.

reseed(seed: int) None[source]

The reseed function resets the state of a sequence generator to a specific seed value.

Parameters:

seed (int) – The seed parameter is an integer value that is used to reset the state of the sequence generator. It determines the starting point of the sequence generation

class lds_gen.ilds.VdCorput(base: int = 2, scale: int = 10)[source]

Bases: object

pop() int[source]

The pop() function is a member function of the VdCorput class that increments the count and calculates the next value in the Van der Corput sequence.

Returns:

The pop() function is returning an int value.

Examples

>>> vdc = VdCorput(2, 10)
>>> vdc.pop()
512
reseed(seed: int) None[source]

The reseed function resets the state of a sequence generator to a specific seed value.

Parameters:

seed (int) – The seed parameter is an integer value that is used to reset the state of the sequence generator. It determines the starting point of the sequence generation

Examples

>>> vdc = VdCorput(2, 10)
>>> vdc.reseed(0)
>>> vdc.pop()
512
lds_gen.ilds.vdc_i(k: int, base: int = 2, scale: int = 10) int[source]

The function vdc_i converts a given number k from base base to a decimal number using a specified scale.

Parameters:
  • k (int) – The parameter k represents the number for which we want to calculate the van der Corput sequence value

  • base (int (optional)) – The base parameter represents the base of the number system being used. In this case, it is set to 2, which means the number system is binary (base 2), defaults to 2

  • scale (int (optional)) – The scale parameter determines the precision or number of digits after the decimal point in the resulting VDC (Van der Corput) sequence. It specifies the number of times the base is raised to calculate the factor, defaults to 10

Returns:

The function vdc_i returns an integer value.

Examples

>>> vdc_i(1, 2, 10)
512

lds_gen.lds module

This module contains low-discrepancy sequence generators

class lds_gen.lds.Circle(base: int)[source]

Bases: object

Circle sequence generator

Examples

>>> cgen = Circle(2)
>>> cgen.reseed(0)
>>> for _ in range(2):
...     print(cgen.pop())
...
[1.2246467991473532e-16, -1.0]
[1.0, 6.123233995736766e-17]
pop() List[float][source]

The pop() function is used to generate the next value in the sequence. For example, in the VdCorput class, pop() increments the count and calculates the Van der Corput sequence value for that count and base. In the Halton class, pop() returns the next point in the Halton sequence as a List[float; 2]. Similarly, in the Circle class, pop() returns the next point on the unit circle as a List[float; 2]. In the Sphere class, pop() returns the next point on the unit sphere as a List[float; 3]. And in the Sphere3Hopf class, pop() returns the next point on the 3-sphere using the Hopf fibration as a List[float; 4].

Examples

>>> cgen = Circle(2)
>>> cgen.pop()
[1.2246467991473532e-16, -1.0]
reseed(seed: int) None[source]

The reseed function resets the state of a sequence generator to a specific seed value.

Parameters:

seed (int) – The seed parameter is an integer value that is used to reset the state of the sequence generator. It determines the starting point of the sequence generation

vdc: VdCorput
class lds_gen.lds.Halton(base: Sequence[int])[source]

Bases: object

Halton sequence generator

The Halton class is a sequence generator that generates points in a 2-dimensional space using the Halton sequence. The Halton sequence is a low-discrepancy sequence that is often used in quasi-Monte Carlo methods. It is generated by iterating over two different bases and calculating the fractional parts of the numbers in those bases. The Halton class keeps track of the current count and bases, and provides a pop() method that returns the next point in the sequence as a List[float].

Examples

>>> hgen = Halton([2, 3])
>>> hgen.reseed(0)
>>> for _ in range(10):
...     print(hgen.pop())
...
[0.5, 0.3333333333333333]
[0.25, 0.6666666666666666]
[0.75, 0.1111111111111111]
[0.125, 0.4444444444444444]
[0.625, 0.7777777777777777]
[0.375, 0.2222222222222222]
[0.875, 0.5555555555555556]
[0.0625, 0.8888888888888888]
[0.5625, 0.037037037037037035]
[0.3125, 0.37037037037037035]
pop() List[float][source]

The pop() function is used to generate the next value in the sequence. For example, in the VdCorput class, pop() increments the count and calculates the Van der Corput sequence value for that count and base. In the Halton class, pop() returns the next point in the Halton sequence as a List[float; 2]. Similarly, in the Circle class, pop() returns the next point on the unit circle as a List[float; 2]. In the Sphere class, pop() returns the next point on the unit sphere as a List[float; 3]. And in the Sphere3Hopf class, pop() returns the next point on the 3-sphere using the Hopf fibration as a List[float; 4].

Examples

>>> hgen = Halton([2, 3])
>>> hgen.pop()
[0.5, 0.3333333333333333]
reseed(seed: int) None[source]

The reseed function resets the state of a sequence generator to a specific seed value.

Parameters:

seed (int) – The seed parameter is an integer value that is used to reset the state of the sequence generator. It determines the starting point of the sequence generation

vdc0: VdCorput
vdc1: VdCorput
class lds_gen.lds.HaltonN(base: Sequence[int])[source]

Bases: object

HaltonN sequence generator

Examples

>>> hgen = HaltonN([2, 3, 5])
>>> hgen.reseed(0)
>>> for _ in range(2):
...     print(hgen.pop())
...
[0.5, 0.3333333333333333, 0.2]
[0.25, 0.6666666666666666, 0.4]
pop() List[float][source]

The pop() function is used to generate the next value in the sequence. For example, in the VdCorput class, pop() increments the count and calculates the Van der Corput sequence value for that count and base. In the Halton class, pop() returns the next point in the Halton sequence as a List[float; 2]. Similarly, in the Circle class, pop() returns the next point on the unit circle as a List[float; 2]. In the Sphere class, pop() returns the next point on the unit sphere as a List[float; 3]. And in the Sphere3Hopf class, pop() returns the next point on the 3-sphere using the Hopf fibration as a List[float; 4].

Examples

>>> hgen = HaltonN([2, 3, 5])
>>> hgen.pop()
[0.5, 0.3333333333333333, 0.2]
reseed(seed: int) None[source]

The reseed function resets the state of a sequence generator to a specific seed value.

Parameters:

seed (int) – The seed parameter is an integer value that is used to reset the state of the sequence generator. It determines the starting point of the sequence generation

vdcs: List[VdCorput]
class lds_gen.lds.Sphere(base: Sequence[int])[source]

Bases: object

Sphere sequence generator

Examples

>>> sgen = Sphere([2, 3])
>>> sgen.reseed(0)
>>> res = sgen.pop()
>>> res[2]
0.0
>>> res = sgen.pop()
>>> res[2]
-0.5
cirgen: Circle
pop() List[float][source]

The pop() function is used to generate the next value in the sequence. For example, in the VdCorput class, pop() increments the count and calculates the Van der Corput sequence value for that count and base. In the Halton class, pop() returns the next point in the Halton sequence as a List[float; 2]. Similarly, in the Circle class, pop() returns the next point on the unit circle as a List[float; 2]. In the Sphere class, pop() returns the next point on the unit sphere as a List[float; 3]. And in the Sphere3Hopf class, pop() returns the next point on the 3-sphere using the Hopf fibration as a List[float; 4].

reseed(seed: int) None[source]

The reseed function resets the state of a sequence generator to a specific seed value.

Parameters:

seed (int) – The seed parameter is an integer value that is used to reset the state of the sequence generator. It determines the starting point of the sequence generation

vdc: VdCorput
class lds_gen.lds.Sphere3Hopf(base: Sequence[int])[source]

Bases: object

Sphere3Hopf sequence generator

pop() List[float][source]

The pop() function is used to generate the next value in the sequence. For example, in the VdCorput class, pop() increments the count and calculates the Van der Corput sequence value for that count and base. In the Halton class, pop() returns the next point in the Halton sequence as a List[float; 2]. Similarly, in the Circle class, pop() returns the next point on the unit circle as a List[float; 2]. In the Sphere class, pop() returns the next point on the unit sphere as a List[float; 3]. And in the Sphere3Hopf class, pop() returns the next point on the 3-sphere using the Hopf fibration as a List[float; 4].

reseed(seed: int) None[source]

The reseed function resets the state of a sequence generator to a specific seed value.

Parameters:

seed (int) – The seed parameter is an integer value that is used to reset the state of the sequence generator. It determines the starting point of the sequence generation

vdc0: VdCorput
vdc1: VdCorput
vdc2: VdCorput
class lds_gen.lds.VdCorput(base: int = 2)[source]

Bases: object

Van der Corput sequence generator

VdCorput is a class that generates the Van der Corput sequence. The Van def Corput sequence is a low-discrepancy sequence that is commonly used in quasi-Monte Carlo methods. The sequence is generated by iterating over a base and calculating the fractional part of the number in that base. The VdCorput class keeps track of the current count and base, and provides a pop() method that returns the next value in the sequence.

Examples

>>> vgen = VdCorput(2)
>>> vgen.reseed(0)
>>> for _ in range(10):
...     print(vgen.pop())
...
0.5
0.25
0.75
0.125
0.625
0.375
0.875
0.0625
0.5625
0.3125
base: int
count: int
pop() float[source]

The pop() function is used to generate the next value in the sequence. For example, in the VdCorput class, pop() increments the count and calculates the Van der Corput sequence value for that count and base. In the Halton class, pop() returns the next point in the Halton sequence as a List[float; 2]. Similarly, in the Circle class, pop() returns the next point on the unit circle as a List[float; 2]. In the Sphere class, pop() returns the next point on the unit sphere as a List[float; 3]. And in the Sphere3Hopf class, pop() returns the next point on the 3-sphere using the Hopf fibration as a List[float; 4].

Examples

>>> vgen = VdCorput(2)
>>> vgen.pop()
0.5
reseed(seed: int) None[source]

The reseed function resets the state of a sequence generator to a specific seed value.

Parameters:

seed (int) – The seed parameter is an integer value that is used to reset the state of the sequence generator. It determines the starting point of the sequence generation

lds_gen.lds.vdc(k: int, base: int = 2) float[source]

Van der Corput sequence

The function vdc converts a given number k from base base to a floating point number.

Parameters:
  • k (int) – The parameter k represents the number for which we want to calculate the van der Corput sequence value

  • base (int (optional)) – The base parameter represents the base of the number system being used. In this case, it is set to 2, which means the number system is binary (base 2), defaults to 2

Returns:

The function vdc returns a floating point value.

Examples

>>> vdc(11, 2)
0.8125

lds_gen.skeleton module

This is a skeleton file that can serve as a starting point for a Python console script. To run this script uncomment the following lines in the [options.entry_points] section in setup.cfg:

console_scripts =
     fibonacci = lds_gen.skeleton:run

Then run pip install . (or pip install -e . for editable mode) which will install the command fibonacci inside your current environment.

Besides console scripts, the header (i.e. until _logger…) of this file can also be used as template for Python modules.

Note

This file can be renamed depending on your needs or safely removed if not needed.

References

lds_gen.skeleton.fib(n)[source]

Fibonacci example function

Parameters:

n (int) – integer

Returns:

n-th Fibonacci number

Return type:

int

lds_gen.skeleton.main(args)[source]

Wrapper allowing fib() to be called with string arguments in a CLI fashion

Instead of returning the value from fib(), it prints the result to the stdout in a nicely formatted message.

Parameters:

args (List[str]) – command line parameters as list of strings (for example ["--verbose", "42"]).

lds_gen.skeleton.parse_args(args)[source]

Parse command line parameters

Parameters:

args (List[str]) – command line parameters as list of strings (for example ["--help"]).

Returns:

command line parameters namespace

Return type:

argparse.Namespace

lds_gen.skeleton.run()[source]

Calls main() passing the CLI arguments extracted from sys.argv

This function can be used as entry point to create console scripts with setuptools.

lds_gen.skeleton.setup_logging(loglevel)[source]

Setup basic logging

Parameters:

loglevel (int) – minimum loglevel for emitting messages

Module contents