Flow

General flow object

class sinflow.Flow(n_transforms=500, n_directions=None, n_knots=1000, validation_fraction=0.2, early_stopping=True, n_iter_no_change=10, reg_cov=1e-06, whiten=True, warm_start=False, p=2, learning_rate=1000.0, beta=0.2, max_iter=1000, tol=1e-06, random_state=None, verbose=False)

A class representing a normalizing flow model.

Attributes:

n_transformsint

Number of transformations to apply.

n_knotsint

Number of knots to use in the spline transformations.

validation_fractionfloat

Fraction of the data to use for validation.

early_stoppingbool

If True, stop training when the validation loss does not improve for n_iter_no_change iterations.

n_iter_no_changeint

Number of iterations with no improvement to wait before stopping training.

reg_covfloat

Regularization parameter for the covariance matrix in the affine transformation.

whitenbool

If True, apply an affine transformation to whiten the data.

warm_startbool

If True, continue training from the current state.

pint

Power for the Wasserstein distance calculation.

max_iterint

Maximum number of iterations for the gradient ascent algorithm.

tolfloat

Tolerance for the gradient norm to declare convergence.

n_directionsint

Number of directions to use in the sliced Wasserstein distance calculation.

verbosebool

If True, print progress information.

initializedbool

If True, the model has been initialized.

transformslist

List of transformations applied to the data.

train_historylist

List of maximum sliced Wasserstein distances on the training set.

val_historylist

List of maximum sliced Wasserstein distances on the validation set.

Methods:

fit(x)

Fit the model to the data.

forward(x)

Apply the forward transformation to the given data.

inverse(y)

Apply the inverse transformation to the given data.

log_prob(x)

Compute the log PDF of the Flow model at the given points.

sample(n)

Sample from the Flow model.

fit(x)

Fit the model to the data.

Parameters:

xnumpy.ndarray

Data to fit the model to.

forward(x)

Apply the forward transformation to the given data.

Parameters:

xnumpy.ndarray

Data to transform.

Returns:

ynumpy.ndarray

Transformed data.

log_detnumpy.ndarray

Log determinant of the Jacobian matrix.

inverse(y)

Apply the inverse transformation to the given data.

Parameters:

ynumpy.ndarray

Data to transform.

Returns:

xnumpy.ndarray

Transformed data.

log_prob(x)

Compute the log PDF of the Flow model at the given points.

Parameters:

xnumpy.ndarray

Points at which to evaluate the log PDF.

Returns:

numpy.ndarray

Log PDF values at the specified points.

sample(n)

Sample from the Flow model.

Parameters:

nint

Number of samples to generate.

Returns:

numpy.ndarray

Generated samples.