Esempio n. 1
0
    def test_randomly_weighted(self):

        # Random weights
        wu = np.random.uniform(low=0, high=2, size=self.y.size).astype('f')

        loss_wu = compute_weighted_value_loss(
            self.y, self.t, clip_delta=self.clip_delta,
            batch_accumulator=self.batch_accumulator,
            weights=wu).array
        if self.batch_accumulator == 'mean':
            gt_loss = (self.gt_losses * wu).mean()
        else:
            gt_loss = (self.gt_losses * wu).sum()
        self.assertAlmostEqual(loss_wu, gt_loss, places=5)
Esempio n. 2
0
    def test_uniformly_weighted(self):

        # Uniform weights
        w1 = np.ones(self.y.size, dtype='f')

        loss_w1 = compute_weighted_value_loss(
            self.y, self.t, clip_delta=self.clip_delta,
            batch_accumulator=self.batch_accumulator,
            weights=w1).array
        if self.batch_accumulator == 'mean':
            gt_loss = self.gt_losses.mean()
        else:
            gt_loss = self.gt_losses.sum()
        self.assertAlmostEqual(loss_w1, gt_loss, places=5)