def _process_sample_weight(self, interactions, sample_weight):
if sample_weight is not None:
if self.loss == 'warp-kos':
raise NotImplementedError('k-OS loss with sample weights '
'not implemented.')
if not isinstance(sample_weight, sp.coo_matrix):
raise ValueError('Sample_weight must be a COO matrix.')
if sample_weight.shape != interactions.shape:
raise ValueError('Sample weight and interactions '
'matrices must be the same shape')
if not (np.array_equal(interactions.row,
sample_weight.row) and
np.array_equal(interactions.col,
sample_weight.col)):
raise ValueError('Sample weight and interaction matrix '
'entries must be in the same order')
if sample_weight.data.dtype != CYTHON_DTYPE:
sample_weight_data = sample_weight.data.astype(CYTHON_DTYPE)
else:
sample_weight_data = sample_weight.data
else:
if np.array_equiv(interactions.data, 1.0):
# Re-use interactions data if they are all
# ones
sample_weight_data = interactions.data
else:
# Otherwise allocate a new array of ones
sample_weight_data = np.ones_like(interactions.data,
dtype=CYTHON_DTYPE)
return sample_weight_data
评论列表
文章目录