Exemple #1
0
 def test_gan_train_match(self):
     
     rea = Realism()
     
     n = 1000
     m_2 = 3
     threshold = 0.05
     max_beta = 10
     n_epoch = 100
     
     beta = np.append(np.random.randint(low=-max_beta,high=0,size=(m_2,1)), 
                      np.random.randint(low=0,high=max_beta,size=(m_2,1)))
     x_real = np.random.randint(low=0, high=2, size=(n,m_2*2))
     x_for_e = np.reshape(np.matmul(x_real, beta), (n,1)) + 0.5 * np.random.random(size=(n,1))
     y_real = np.reshape(np.round(1.0 / (1.0 + np.exp(-x_for_e))), (n,))
     
     res_real = rea.gan_train(x_synth=x_real, y_synth=y_real, 
                                   x_real=x_real, y_real=y_real, n_epoch=n_epoch)
     res_gan_train1 = rea.gan_train(x_synth=x_real, y_synth=y_real, 
                                   x_real=x_real, y_real=y_real, n_epoch=n_epoch)
     
     assert (abs(res_real['auc'] - res_gan_train1['auc']) < threshold)
Exemple #2
0
 def test_gan_test_mismatch(self):
     
     rea = Realism()
     
     n = 1000
     m_2 = 3
     threshold = 0.05
     max_beta = 10
     n_epoch = 100
     
     beta = np.append(np.random.randint(low=-max_beta,high=0,size=(m_2,1)), 
                      np.random.randint(low=0,high=max_beta,size=(m_2,1)))
     x_real = np.random.randint(low=0, high=2, size=(n,m_2*2))
     x_for_e = np.reshape(np.matmul(x_real, beta), (n,1)) + 0.5 * np.random.random(size=(n,1))
     y_real = np.reshape(np.round(1.0 / (1.0 + np.exp(-x_for_e))), (n,))
     
     # flip label to ensure AUCs are very different
     x_synth = x_real
     y_synth = 1 - y_real
     res_real = rea.gan_train(x_synth=x_real, y_synth=y_real, 
                                   x_real=x_real, y_real=y_real, n_epoch=n_epoch)
     res_gan_test2 = rea.gan_test(x_synth, y_synth, x_real, y_real, n_epoch=n_epoch)
     
     assert (abs(res_real['auc'] - res_gan_test2['auc']) > threshold)