Exemplo n.º 1
0
 def test_one_class_empty(self):
    w = np.array([  1,   1,   0,   1])
    y = np.array([  1,   1,   0,   1])
    resp1 = balance_masked_weights(y, w)
    resp2 = balance_masked_weights(1-y, w)
    self.assertTrue((w==resp1).all())
    self.assertTrue((w==resp2).all())
Exemplo n.º 2
0
    input_shape = x.shape[1]
else:
    input_shape = [arr.shape for arr in x]

data_shapes = config.get('data_shapes', 'none')
if data_shapes != 'none':
    input_shape = data_shapes

for cv_train_idx, cv_val_idx in cv_splits:
    train = slice_data(data_stuff, cv_train_idx, N_inputs)
    val = slice_data(data_stuff, cv_val_idx, N_inputs)
    if is_multitask:
        logger.info('Train Y: %s' % str(np.sum(train[1], axis=1)))
        for i, vy in enumerate(train[1]):
            key = 'out%i' % i
            train[2][key] = balance_masked_weights(vy, train[2][key])
            val[2][key] = balance_masked_weights(val[1][i], val[2][key])
    else:
        train[2] = scale_weights(train[1], train[2], args.scale_positive)
        val[2] = scale_weights(val[1], val[2], args.scale_positive)
        logger.info('Train Y: %s' % str(np.sum(train[1], axis=0)))
    model, metric = make_model(input_shape, np.shape(y),
                               config['model_params'])
    logger.info('Model build')
    result = model.fit(train[0],
                       train[1],
                       sample_weight=train[2],
                       validation_data=val,
                       batch_size=batch_size,
                       epochs=epochs,
                       shuffle=True,
Exemplo n.º 3
0
   def test_balance_masked_weights(self):
      resp = balance_masked_weights(self.known_values['y'], self.known_values['w'])
      msg = '\nGot: %s\nShould be: %s'%( str(resp), str(self.known_values['o']))

      self.assertTrue((resp==self.known_values['o']).all(), msg)
Exemplo n.º 4
0
 def test_source_unchanged(self):
    prev = hash(tuple(self.known_values['w']))
    new = balance_masked_weights(self.known_values['y'], self.known_values['w'])
    after = hash(tuple(self.known_values['w']))
    self.assertEqual(prev, after)
Exemplo n.º 5
0
 def test_detect_is_none(self):
    self.assertTrue(balance_masked_weights(self.known_values['y'], None) is None)