Skip to content

Module streamgen.samplers

🎲 this module contain implementations for different samplers.

Samplers are objects that represent distributions.

View Source
"""🎲 this module contain implementations for different samplers.

Samplers are objects that represent distributions.

"""

from collections.abc import Iterator

from typing import Any, Protocol, runtime_checkable

@runtime_checkable

class Sampler(Iterator, Protocol):

    """📊 sampler protocol `() -> sample`.

    Sampler also implement the iterator protocol.

    """

    def sample(self) -> Any:  # noqa: ANN401

        """🎲 sample from the `Sampler`s distribution.

        Returns:

            Any: a sample

        """

        ...

    def collect(self, num_samples: int) -> Any:  # noqa: ANN401

        """🪺 collect and concatenate `num_samples` using `sample()`.

        Args:

            num_samples (int): number of samples to collect

        Returns:

            Any: collection of samples

        """

        ...

    def update(self) -> None:

        """🆙 updates every parameter."""

        ...

Sub-modules

Classes

Sampler

class Sampler(
    *args,
    **kwargs
)

📊 sampler protocol () -> sample.

Sampler also implement the iterator protocol.

View Source
@runtime_checkable

class Sampler(Iterator, Protocol):

    """📊 sampler protocol `() -> sample`.

    Sampler also implement the iterator protocol.

    """

    def sample(self) -> Any:  # noqa: ANN401

        """🎲 sample from the `Sampler`s distribution.

        Returns:

            Any: a sample

        """

        ...

    def collect(self, num_samples: int) -> Any:  # noqa: ANN401

        """🪺 collect and concatenate `num_samples` using `sample()`.

        Args:

            num_samples (int): number of samples to collect

        Returns:

            Any: collection of samples

        """

        ...

    def update(self) -> None:

        """🆙 updates every parameter."""

        ...

Ancestors (in MRO)

  • collections.abc.Iterator
  • collections.abc.Iterable
  • typing.Protocol
  • typing.Generic

Descendants

  • streamgen.samplers.tree.SamplingTree

Methods

collect

def collect(
    self,
    num_samples: int
) -> Any

🪺 collect and concatenate num_samples using sample().

Parameters:

Name Type Description Default
num_samples int number of samples to collect None

Returns:

Type Description
Any collection of samples
View Source
    def collect(self, num_samples: int) -> Any:  # noqa: ANN401

        """🪺 collect and concatenate `num_samples` using `sample()`.

        Args:

            num_samples (int): number of samples to collect

        Returns:

            Any: collection of samples

        """

        ...

sample

def sample(
    self
) -> Any

🎲 sample from the Samplers distribution.

Returns:

Type Description
Any a sample
View Source
    def sample(self) -> Any:  # noqa: ANN401

        """🎲 sample from the `Sampler`s distribution.

        Returns:

            Any: a sample

        """

        ...

update

def update(
    self
) -> None

🆙 updates every parameter.

View Source
    def update(self) -> None:

        """🆙 updates every parameter."""

        ...