def __init__(self, dataX, dataA, dataY, learner, cons_class, eps, B, opt_lambda=True, debug=False): self.X = dataX self.obj = moments.MisclassError(dataX, dataA, dataY) self.cons = cons_class(dataX, dataA, dataY) self.pickled_learner = pickle.dumps(learner) self.eps = eps self.B = B self.opt_lambda = opt_lambda self.debug = debug self.hs = pd.Series() self.classifiers = pd.Series() self.errors = pd.Series() self.gammas = pd.DataFrame() self.n = self.X.shape[0] self.n_oracle_calls = 0 self.last_linprog_n_hs = 0 self.last_linprog_result = None
for test in tests: res_tuple = red.expgrad(dataX, dataA, dataY, learner, cons=test["cons_class"](), eps=test["eps"]) res = res_tuple._asdict() Q = res["best_classifier"] res["n_classifiers"] = len(res["classifiers"]) disp = test["cons_class"]() disp.init(dataX, dataA, dataY) error = moments.MisclassError() error.init(dataX, dataA, dataY) res["disp"] = disp.gamma(Q).max() res["error"] = error.gamma(Q)[0] report_header = "testing (%s, eps=%.3f)" \ % (test["cons_class"].short_name, test["eps"]) report_list = [] test_res_float("best_gap", res, test, report_list) test_res_int("last_t", res, test, report_list) test_res_int("best_t", res, test, report_list) test_res_float("disp", res, test, report_list) test_res_float("error", res, test, report_list) test_res_int("n_oracle_calls", res, test, report_list) test_res_int("n_classifiers", res, test, report_list) if report_list:
learner = LeastSquaresLearner() for test in tests: res_tuple = red.expgrad(dataX, dataA, dataY, learner, cons_class=test["cons_class"], eps=test["eps"]) res = res_tuple._asdict() Q = res["best_classifier"] res["n_classifiers"] = len(res["classifiers"]) res["disp"] = test["cons_class"](dataX, dataA, dataY).gamma(Q).max() res["error"] = moments.MisclassError(dataX, dataA, dataY).gamma(Q)[0] report_header = "testing (%s, eps=%.3f)" \ % (test["cons_class"].short_name, test["eps"]) report_list = [] test_res_float("best_gap", res, test, report_list) test_res_int("last_t", res, test, report_list) test_res_int("best_t", res, test, report_list) test_res_float("disp", res, test, report_list) test_res_float("error", res, test, report_list) test_res_int("n_oracle_calls", res, test, report_list) test_res_int("n_classifiers", res, test, report_list) if report_list: print("%s: %s" % (report_header, ", ".join(report_list))) else: print("%s: ok" % report_header)