def train(self, features, y, pred=False): # y:-1 or 1, features:[(index, value), (index, value), ...] total_mean, total_variance = self._active_mean_variance(features) v, w = util.gaussian_corrections(y * total_mean / np.sqrt(total_variance)) for feature_index, feature_value in features: weight = self._get_weight(feature_index) mean_delta = y * weight._variance / np.sqrt(total_variance) * v * feature_value variance_multiplier = 1.0 - weight._variance / total_variance * w * (feature_value ** 2) weight.update(mean_delta, variance_multiplier) self._apply_dynamics(weight) self._set_weight(feature_index, weight) if pred: return norm.cdf(total_mean / total_variance)
def train(self, features, label): logger.info("Training: %s, %s features", label, len(features)) assert len(features) == self._config.num_features y = util.label_to_float(label) total_mean, total_variance = self._active_mean_variance(features) v, w = util.gaussian_corrections(y * total_mean / np.sqrt(total_variance)) for feature in features: weight = self._get_weight(feature) mean_delta = y * weight.variance / np.sqrt(total_variance) * v variance_multiplier = 1.0 - weight.variance / total_variance * w updated = pb.Gaussian( mean=weight.mean + mean_delta, variance=weight.variance * variance_multiplier) self._set_weight(feature, self._apply_dynamics(updated))
def train(self, features, label): logger.info("Training: %s, %s features", label, len(features)) assert len(features) == self._config.num_features y = util.label_to_float(label) total_mean, total_variance = self._active_mean_variance(features) v, w = util.gaussian_corrections(y * total_mean / np.sqrt(total_variance)) for feature in features: weight = self._get_weight(feature) mean_delta = y * weight.variance / np.sqrt(total_variance) * v variance_multiplier = 1.0 - weight.variance / total_variance * w updated = pb.Gaussian(mean=weight.mean + mean_delta, variance=weight.variance * variance_multiplier) self._set_weight(feature, self._apply_dynamics(updated))