def _impute2D(self, X_2D):
r"""Randomly impute a rank 2 tensor.
Parameters
----------
X_2D : Tensor
a rank 2 Tensor with missing data
scalars : Tensor 1 x D
these values are filled into the missing elements (per column)
Returns
-------
X_imputed : Tensor
a rank 2 Tensor with imputed data
"""
# Fill zeros in for missing data initially
data_zeroed_missing = X_2D * self.real_val_mask
# Make an vector of the impute values for each missing point
imputed_vals = tf.gather(self.impute_scalars[0, :],
self.missing_ind[:, 1])
# Fill the imputed values into the data tensor of zeros
shape = tf.cast(tf.shape(data_zeroed_missing), dtype=tf.int64)
missing_imputed = tf.scatter_nd(self.missing_ind, imputed_vals, shape)
X_with_impute = data_zeroed_missing + missing_imputed
return X_with_impute
评论列表
文章目录