LRSampler

class jlpy.pytorch.base.linear_regression.base_impl.LRSampler

Bases: Sampler[list[int]]

A custom torch batched Sampler - LRSampler.

  • Custom Sampler:
    • Controlling how to shuffle.

    • Return the size for iteration.

  • Custom batched sampler:
    • Control how to shuffle.

    • Control batch size.

    • Control the drop_last.

    • Return the size for batched iteration.

  • Sampler __iter__():
    • Return a list of indices.

    • Using the list of indices to get elements from Dataset class.

    • Sampler will call __getitems__() first, then fall back to call __getitem__().

  • Dataset class:
    • Sampler class only need to get the len of the dataset.

    • According to the len of the dataset, Sampler will procee all the rest itself.

    • Dataloader will iterate the Sampler and get the samples from Dataset.

Methods

__init__

Construct a class instance.

__init__(dsize: int, batch_size: int = 32, shuffle: bool = False, drop_last: bool = True) None

Construct a class instance.