latte.functional.interpolatability.monotonicity

Module Contents

Functions

monotonicity(z, a[, reg_dim, liad_mode, reduce_mode, ...])

Calculate latent monotonicity.

monotonicity(z, a, reg_dim=None, liad_mode='forward', reduce_mode='attribute', liad_thresh=0.001, degenerate_val=np.nan, nanmean=True)

Calculate latent monotonicity.

Monotonicity is a measure of how monotonic an attribute changes with respect to a change in the regularizing dimension. Monotonicity of a latent vector \(\mathbf{z}\) is given by

\[\operatorname{Monotonicity}_{i,d}(\mathbf{z};\delta,\epsilon) = \dfrac{\sum_{k\in\mathfrak{K}}I_k\cdot \operatorname{sgn}(\mathcal{D}_{i,d}(\mathbf{z}+k\delta\mathbf{e}_d;\delta))}{\sum_{k\in\mathfrak{K}}I_k},\]

where \(\mathcal{D}_{i,d}(z; \delta)\) is the first-order latent-induced attribute difference (LIAD) as defined below, \(I_k = \mathbb{I}[|\mathcal{D}_{i,d}(\mathbf{z}+k\delta\mathbf{e}_d;\delta)| > \epsilon] \in \{0,1\}\), \(\mathbb{I}[\cdot]\) is the Iverson bracket operator, \(\epsilon > 0\) is a noise threshold for ignoring near-zero attribute changes, and \(\mathfrak{K}\) is the set of interpolating points (controlled by z) used during evaluation.

The first-order LIAD is defined by

\[\mathcal{D}_{i, d}(\mathbf{z}; \delta) = \dfrac{\mathcal{A}_i(\mathbf{z}+\delta \mathbf{e}_d) - \mathcal{A}_i(\mathbf{z})}{\delta}\]

where \(\mathcal{A}_i(\cdot)\) is the measurement of attribute \(a_i\) from a sample generated from its latent vector argument, \(d\) is the latent dimension regularizing \(a_i\), \(\delta>0\) is the latent step size.

Parameters:
  • z (np.ndarray, (n_samples, n_interp) or (n_samples, n_features or n_attributes, n_interp)) – a batch of latent vectors

  • a (np.ndarray, (n_samples, n_interp) or (n_samples, n_attributes, n_interp)) – a batch of attribute(s)

  • reg_dim (Optional[List], optional) – regularized dimensions, by default None Attribute a[:, i] is regularized by z[:, reg_dim[i]]. If None, a[:, i] is assumed to be regularized by z[:, i].

  • liad_mode (str, optional) – options for calculating LIAD, by default “forward”. Only “forward” is currently supported.

  • reduce_mode (str, optional) – options for reduction of the return array, by default “attribute”. Must be one of {“attribute”, “samples”, “all”, “none”}. If “all”, returns a scalar. If “attribute”, an average is taken along the sample axis and the return array is of shape (n_attributes,). If “samples”, an average is taken along the attribute axis and the return array is of shape (n_samples,). If “none”, returns a smoothness matrix of shape (n_samples, n_attributes,).

  • liad_thresh (float, optional) – threshold for ignoring noisy 1st order LIAD, by default 1e-3

  • degenerate_val (float, optional) – fill value for samples with all noisy LIAD (i.e., absolute value below liad_thresh), by default np.nan. Another possible option is to set this to 0.0.

  • nanmean (bool, optional) – whether to ignore the NaN values in calculating the return array, by default True. Ignored if reduce_mode is “none”. If all LIAD in an axis are NaNs, the return array in that axis is filled with NaNs.

Returns:

monotonicity array. See reduce mode for return shape.

Return type:

np.ndarray

References

[1]
    1. Watcharasupat, “Controllable Music: Supervised Learning of Disentangled Representations for Music Generation”, 2021.