def __call__(self, X, y=None):
     if y is not None:
         alpha = self.config.cnf['balance_ratio'] ** self.count
         class_weights = self.config.cnf['balance_weights'] * alpha \
             + self.config.cnf['final_balance_weights'] * (1 - alpha)
         self.count += 1
         indices = data.balance_per_class_indices(y, weights=class_weights)
         X = X[indices]
         y = y[indices]
     return super(ResampleIterator, self).__call__(X, y, weight=None)
Esempio n. 2
0
 def __call__(self, X, y=None, transform=None, color_vec=None):
     if y is not None:
         alpha = self.config.cnf['balance_ratio'] ** self.count
         class_weights = self.config.cnf['balance_weights'] * alpha \
             + self.config.cnf['final_balance_weights'] * (1 - alpha)
         self.count += 1
         indices = data.balance_per_class_indices(y, weights=class_weights)
         X = X[indices]
         y = y[indices]
     return super(ResampleIterator, self).__call__(X, y, transform=transform,
                                                   color_vec=color_vec)
Esempio n. 3
0
 def __iter__(self):
     n_samples = self.X.shape[0]
     bs = self.batch_size
     indices = data.balance_per_class_indices(self.y.ravel())
     for i in range((n_samples + bs - 1) // bs):
         r = np.random.rand()
         if r < self.resample_prob:
             sl = indices[np.random.randint(0, n_samples, size=bs)]
         elif r < self.shuffle_prob:
             sl = np.random.randint(0, n_samples, size=bs)
         else:
             sl = slice(i * bs, (i + 1) * bs)
         Xb = self.X[sl]
         if self.y is not None:
             yb = self.y[sl]
         else:
             yb = None
         yield self.transform(Xb, yb)
Esempio n. 4
0
 def __iter__(self):
     n_samples = self.X.shape[0]
     bs = self.batch_size
     indices = data.balance_per_class_indices(self.y.ravel())
     for i in range((n_samples + bs - 1) // bs):
         r = np.random.rand()
         if r < self.resample_prob:
             sl = indices[np.random.randint(0, n_samples, size=bs)]
         elif r < self.shuffle_prob:
             sl = np.random.randint(0, n_samples, size=bs)
         else:
             sl = slice(i * bs, (i + 1) * bs)
         Xb = self.X[sl]
         if self.y is not None:
             yb = self.y[sl]
         else:
             yb = None
         yield self.transform(Xb, yb)