def test_model_specification_error(self): n_l, prior_l = 30, .3 n_u, prior_u = 200, .5 n_t = 100 x, y, x_tp, x_tn = gendata(n_l, prior_l, n_u, prior_u, n_t) eta_list = [ pnu_mr.calc_etab(np.sum(y == +1), np.sum(y == -1), prior_u) ] with self.assertRaises(ValueError): pnu_mr.PNU_SL(x, y, prior_u, eta_list, model='DNN')
def test_linear_model(self): n_l, prior_l = 30, .3 n_u, prior_u = 200, .5 n_t = 100 eta_list = np.arange(-.9, 1, .1) x, y, x_tp, x_tn = gendata(n_l, prior_l, n_u, prior_u, n_t) f_dec, outs, funcs = pnu_mr.PNU_SL(x, y, prior_u, eta_list, model='lm', nargout=3) err = 100 * calc_err(f_dec, x_tp, x_tn, prior_u)
def test_linear_model_one_eta(self): n_l, prior_l = 30, .5 n_u, prior_u = 200, .3 n_t = 100 x, y, x_tp, x_tn = gendata(n_l, prior_l, n_u, prior_u, n_t) eta_list = [ pnu_mr.calc_etab(np.sum(y == +1), np.sum(y == -1), prior_u) ] f_dec, outs, funcs = pnu_mr.PNU_SL(x, y, prior_u, eta_list, model='lm', nargout=3) err = 100 * calc_err(f_dec, x_tp, x_tn, prior_u)
def test_model_nargout2(self): n_l, prior_l = 30, .5 n_u, prior_u = 200, .3 n_t = 100 x, y, x_tp, x_tn = gendata(n_l, prior_l, n_u, prior_u, n_t) eta_list = [ pnu_mr.calc_etab(np.sum(y == +1), np.sum(y == -1), prior_u) ] lambda_list = [.1] f_dec, outs = pnu_mr.PNU_SL(x, y, prior_u, eta_list, lambda_list=lambda_list, model='lm', nargout=2) err = 100 * calc_err(f_dec, x_tp, x_tn, prior_u)
def test_gauss_model(self): n_l, prior_l = 30, .3 n_u, prior_u = 200, .5 n_t = 100 lambda_list = [.1] x, y, x_tp, x_tn = gendata(n_l, prior_l, n_u, prior_u, n_t) eta_list = [ pnu_mr.calc_etab(np.sum(y == +1), np.sum(y == -1), prior_u) ] f_dec, outs, funcs = pnu_mr.PNU_SL(x, y, prior_u, eta_list, model='gauss', lambda_list=lambda_list, nargout=3) err = 100 * calc_err(f_dec, x_tp, x_tn, prior_u)
prior_u = .3 eta_list = np.arange(-.9, 1, .1) n_trial = 20 best_err = np.inf errs1 = np.empty(n_trial) errs2 = np.empty((n_trial, len(eta_list))) priors = np.empty(n_trial) for ite in range(n_trial): x, y, x_tp, x_tn = gendata(n_l, prior_l, n_u, prior_u, n_t) priorh = cpe.cpe(x[y != 0, :], y[y != 0], x[y == 0, :]) f_dec, outs, funcs = pnu.PNU_SL(x, y, priorh, eta_list, model='lm', nargout=3) errs1[ite] = 100 * calc_err(f_dec, x_tp, x_tn, prior_u) if errs1[ite] < best_err: best_err = errs1[ite] best_w = outs['w'] best_x, best_y = x, y for ite_eta in range(len(eta_list)): errs2[ite, ite_eta] = 100 * calc_err(funcs[ite_eta], x_tp, x_tn, prior_u) priors[ite] = priorh print("Average of misclassification rates: {:.1f} ({:.2f})".format( np.mean(errs1),