def train(self, X, y, domain, featurizer, **kwargs): if not utils.is_training_data_empty(X): for policy in self.policies: policy.prepare(featurizer, max_history=X.shape[1]) policy.train(X, y, domain, **kwargs) else: logger.info("Skipped training, because there are no " "training samples.")
def _deduplicate_training_data(X, y): # type: (ndarray, ndarray) -> Tuple[ndarray, ndarray] """Make sure every training example in X occurs exactly once.""" # we need to concat X and y to make sure that # we do NOT throw out contradicting examples # (same featurization but different labels). # appends y to X so it appears to be just another feature if not utils.is_training_data_empty(X): casted_y = np.broadcast_to(np.reshape(y, (y.shape[0], 1, 1)), (y.shape[0], X.shape[1], 1)) concatenated = np.concatenate((X, casted_y), axis=2) t_data = np.unique(concatenated, axis=0) X_unique = t_data[:, :, :-1] y_unique = np.array(t_data[:, 0, -1], dtype=casted_y.dtype) return X_unique, y_unique else: return X, y
def is_empty(self): return utils.is_training_data_empty(self.X)