echoflow package

Top-level package for EchoFlow.

class echoflow.EchoFlow(lr: float = 0.0001, nb_epochs: int = 1000, batch_size: int = 100, nb_blocks: int = 3, block_type: str = 'RNVP', use_kde: bool = False)[source]

Bases: object

Wrapper for training normalizing flow models.

fit(df: pandas.core.frame.DataFrame, context: Optional[pandas.core.frame.DataFrame] = None)[source]

Fit the flow model.

Parameters
  • df – The dataframe containing the samples to model.

  • contexts – The (optional) context dataframe for conditional sampling.

log_likelihood(df: pandas.core.frame.DataFrame, context: Optional[pandas.core.frame.DataFrame] = None)[source]

Compute the log-likelihood of the data.

Parameters
  • df – The dataframe containing the samples to model.

  • contexts – The (optional) context dataframe. If it was provided in the fit method, it must be provided here as well.

sample(num_samples: Optional[int] = None, context: Optional[pandas.core.frame.DataFrame] = None) → pandas.core.frame.DataFrame[source]

Generate samples via the inverse transform.

Either num_samples or contexts must be provided. If both are provided, then they must be consistent (i.e. there are num_samples rows in contexts).

Parameters
  • num_samples – The number of samples.

  • contexts – The (optional) context dataframe for conditional sampling.

Submodules

echoflow.echoflow module

class echoflow.echoflow.EchoFlow(lr: float = 0.0001, nb_epochs: int = 1000, batch_size: int = 100, nb_blocks: int = 3, block_type: str = 'RNVP', use_kde: bool = False)[source]

Bases: object

Wrapper for training normalizing flow models.

fit(df: pandas.core.frame.DataFrame, context: Optional[pandas.core.frame.DataFrame] = None)[source]

Fit the flow model.

Parameters
  • df – The dataframe containing the samples to model.

  • contexts – The (optional) context dataframe for conditional sampling.

log_likelihood(df: pandas.core.frame.DataFrame, context: Optional[pandas.core.frame.DataFrame] = None)[source]

Compute the log-likelihood of the data.

Parameters
  • df – The dataframe containing the samples to model.

  • contexts – The (optional) context dataframe. If it was provided in the fit method, it must be provided here as well.

sample(num_samples: Optional[int] = None, context: Optional[pandas.core.frame.DataFrame] = None) → pandas.core.frame.DataFrame[source]

Generate samples via the inverse transform.

Either num_samples or contexts must be provided. If both are provided, then they must be consistent (i.e. there are num_samples rows in contexts).

Parameters
  • num_samples – The number of samples.

  • contexts – The (optional) context dataframe for conditional sampling.

class echoflow.echoflow.FlowDataset(continuous, categorical, contexts)[source]

Bases: torch.utils.data.dataset.Dataset

echoflow.transformer module

class echoflow.transformer.KDETransformer[source]

Bases: object

Probability integral transform via KDE.

fit(X: numpy.ndarray)[source]
inverse_transform(Z: numpy.ndarray, maxiter=1000, tol=1e-06) → numpy.ndarray[source]
transform(X: numpy.ndarray) → numpy.ndarray[source]
class echoflow.transformer.SplitTransformer(use_kde)[source]

Bases: object

fit(df: pandas.core.frame.DataFrame)[source]
fit_transform(df: pandas.core.frame.DataFrame) → Tuple[Optional[torch.Tensor], Optional[torch.Tensor]][source]
inverse_transform(continuous: Optional[torch.Tensor], categorical: Optional[torch.Tensor]) → pandas.core.frame.DataFrame[source]
transform(df: pandas.core.frame.DataFrame) → Tuple[Optional[torch.Tensor], Optional[torch.Tensor]][source]
class echoflow.transformer.TableTransformer(use_kde)[source]

Bases: object

Transform a dataframe into a tensor.

dims = 0
fit_transform(df: pandas.core.frame.DataFrame) → torch.Tensor[source]

Fit and transform a dataframe into a tensor.

Continuous values are normalized to the [0.0, 1.0] range and categorical values are converted into a one-hot representation.

Parameters

df – The dataframe containing continuous and categorical values.

Returns

A tensor representation of the data.

Return type

torch.Tensor

inverse_transform(inputs: torch.Tensor) → pandas.core.frame.DataFrame[source]

Inverse transform a tensor into a dataframe.

Parameters

inputs – The tensor to apply the inverse transform to.

transform(df)[source]