bgd.batch module

This module contains all the different batching methods that are implemented. Any new batching method needs to inherit from bgd.batch.Batching and to implement its abstract methods (_start and next).

class bgd.batch.Batching[source]

Bases: object

Base class for generating batches.

warm

Whether a dataset has been passed to the batching algorithm. Once it is warm, method ‘next’ can be called to retrieve a batch.

Type

bool

abstract _next()[source]

Wrapped method for retrieving a batch from the provided dataset. Subclasses must override this method.

abstract _start(X, y)[source]

Wrapped method for providing a dataset to the batching algorithm. Subclasses must override this method.

next()[source]

Wrapper method for retrieving a batch from the provided dataset.

Returns

X (np.ndarray):

Batch samples.

y (np.ndarray):

Batch target values.

start(X, y)[source]

Wrapper method for providing a dataset to the batching algorithm. This must be called before to method next() is called.

Parameters
  • X (np.ndarray) – Input samples

  • y (np.ndarray) – Target values

class bgd.batch.SGDBatching(batch_size, shuffle=True)[source]

Bases: bgd.batch.Batching

Stochastic Gradient Descent Batching algorithm.

Parameters
  • batch_size (int) – Size of each random batch.

  • shuffle (bool) – Whether to shuffle the dataset before extracting a batch from it.

_next()[source]

Retrieves next batch using a generator function.

Returns

X (np.ndarray):

Batch samples.

y (np.ndarray):

Batch target values.

_start(X, y)[source]

Provide a dataset to the batching algorithm. This must be called before to method next() is called.

Parameters
  • X (np.ndarray) – Input samples.

  • y (np.ndarray) – Target values.

mini_batches(X, y)[source]

Generator function that iteratively yields batches.

Parameters
  • X (np.ndarray) – Input samples.

  • y (np.ndarray) – Target values.

Yields
X (np.ndarray):

Batch samples.

y (np.ndarray):

Batch target values.