def __init__(self, trainer: Trainer = None, weight_clamper: Clamper = None, device=None): super().__init__(trainer, device) self._weight_clamper = Clamper( ) if weight_clamper is None else weight_clamper
def __init__(self, weight_clamper: Clamper = None, weighted: bool = True, device=None): super().__init__(device) self._weight_clamper = (weight_clamper if weight_clamper is not None else Clamper()) self._weighted = weighted
def __init__(self, weight_clamper: Clamper = None, weighted: bool = False, device=None): super().__init__(device) self._weight_clamper = Clamper( ) if weight_clamper is None else weight_clamper self._weighted = weighted
def __init__( self, trainer: Optional[Trainer] = None, weight_clamper: Optional[Clamper] = None, device=None, ): super().__init__(trainer, device) self._weight_clamper = Clamper() if weight_clamper is None else weight_clamper
def test_clamper(self): with self.assertRaises(ValueError): clamper = Clamper(1.0, 0.0) list_value = [-1.1, 0.9, 0.0, 1.1, -0.9] tensor_value = torch.tensor(list_value) array_value = np.array(list_value) clamper = Clamper() self.assertEqual(clamper(list_value), list_value) self.assertTrue(torch.equal(clamper(tensor_value), tensor_value)) self.assertTrue(np.array_equal(clamper(array_value), array_value)) clamper = Clamper(-1.0, 1.0) self.assertEqual(clamper(list_value), [-1.0, 0.9, 0.0, 1.0, -0.9]) self.assertTrue( torch.equal(clamper(tensor_value), torch.tensor([-1.0, 0.9, 0.0, 1.0, -0.9]))) self.assertTrue( np.array_equal(clamper(array_value), np.array([-1.0, 0.9, 0.0, 1.0, -0.9])))
def __init__( self, trainer: Optional[Trainer] = None, weight_clamper: Optional[Clamper] = None, rmax: Optional[Reward] = None, device=None, ): """ rmax is an a priori upper bound on any possible reward. The tighter the bound, the better the estimator can estimate its bias. If not provided, the estimator will use the max reward seen in the sample data. """ super().__init__(trainer, device) self._rmax = rmax self._weight_clamper = Clamper() if weight_clamper is None else weight_clamper
anchor_url_features = (params["anchor_url_features"] if "anchor_url_features" in params else None) body_features = params[ "body_features"] if "body_features" in params else None # uncomment to train behavior and target models # train_models(params) test_dataset = load_dataset( params["second_set"], num_columns, anchor_url_features, body_features, "second_set", ) weight_clamper = Clamper(min_v=0.0) estimators = [ DMEstimator(DecisionTreeTrainer(), 0.5, device=device), IPSEstimator(weight_clamper=weight_clamper, device=device), DoublyRobustEstimator(DecisionTreeTrainer(), 0.5, weight_clamper, False, device), DoublyRobustEstimator(DecisionTreeTrainer(), 0.5, weight_clamper, True, device), PseudoInverseEstimator(weight_clamper=weight_clamper, device=device), PBMEstimator(weight_clamper=weight_clamper, device=device), ] metrics = ["ndcg", "err"] alphas = [0.0, 1.0, 2.0] trainers = [ (DecisionTreeTrainer(), LassoTrainer()),
anchor_url_features = (params["anchor_url_features"] if "anchor_url_features" in params else None) body_features = params[ "body_features"] if "body_features" in params else None # uncomment to train behavior and target models # train_models(params) test_dataset = load_dataset( params["second_set"], num_columns, anchor_url_features, body_features, "second_set", ) weight_clamper = Clamper(min=0.0) estimators = [ DMEstimator(DecisionTreeTrainer(), 0.5, device=device), IPSEstimator(weight_clamper=weight_clamper, device=device), DoublyRobustEstimator(DecisionTreeTrainer(), 0.5, weight_clamper, False, device), DoublyRobustEstimator(DecisionTreeTrainer(), 0.5, weight_clamper, True, device), PseudoInverseEstimator(weight_clamper=weight_clamper, device=device), PBMEstimator(weight_clamper=weight_clamper, device=device), ] metrics = ["ndcg", "err"] alphas = [0.0, 1.0, 2.0] trainers = [ (DecisionTreeTrainer(), LassoTrainer()),