def run(strategy, explanation_score_name = "mat_score", prediction_score_name = "mato_score", show_me = False, test_problems = None, test_name = "spm", test_anlgs = None, test_trans = None): start_time = time.time() probs = prob_anlg_tran_new.get_probs(test_problems, test_name) for prob in probs: print(prob.name) # initialize cache jaccard.load_jaccard_cache(prob.name) asymmetric_jaccard.load_asymmetric_jaccard_cache(prob.name) # run strategy anlg_tran_data, pred_data, pred_d = strategy(prob, explanation_score_name = explanation_score_name, prediction_score_name = prediction_score_name, test_anlgs = test_anlgs, test_trans = test_trans) # save data prob.data = utils.save_data(prob, anlg_tran_data, pred_data, pred_d, "./data/" + test_name + "_" + strategy.__name__ + "_" + prediction_score_name + "_" + prob.name, show_me) # update cache jaccard.save_jaccard_cache(prob.name) asymmetric_jaccard.save_asymmetric_jaccard_cache(prob.name) # generate report report.create_report(probs, test_name + "_" + strategy.__name__ + "_" + prediction_score_name + "_") end_time = time.time() print(end_time - start_time)
def run_raven_greedy(show_me=False, test_problems=None): start_time = time.time() print("run raven in greedy mode.") probs = prob_anlg_tran.get_probs(test_problems) for prob in probs: print(prob.name) jaccard.load_jaccard_cache(prob.name) asymmetric_jaccard.load_asymmetric_jaccard_cache(prob.name) anlgs = prob_anlg_tran.get_anlgs(prob) anlg_tran_data = [] anlg_data = [] for anlg in anlgs: # score all transformations given an analogy tran_data = run_prob_anlg(prob, anlg) anlg_tran_data.extend(tran_data) # optimize w.r.t. transformations for this analogy anlg_tran_d = utils.find_best(tran_data, "pat_score") anlg_data.append(anlg_tran_d) pred_data = [] for anlg_d in anlg_data: # predict with an analogy, and score all options with the prediction anlg_pred_data = predict(prob, anlg_d) pred_data.extend(anlg_pred_data) # optimize w.r.t. options pred_d = utils.find_best(pred_data, "pat_score", "pato_score") # imaging save_image(prob, pred_d.get("pred"), prob.options[pred_d.get("optn") - 1], "greedy", show_me) # data aggregation progression, TODO maybe save them as images for d in anlg_tran_data: del d["diff"] for d in anlg_data: del d["diff"] for d in pred_data: del d["diff"] del d["pred"] del pred_d["diff"] del pred_d["pred"] aggregation_progression = { "anlg_tran_data": anlg_tran_data, "anlg_data": anlg_data, "pred_data": pred_data, "pred_d": pred_d } with open("./data/greedy_" + prob.name + ".json", 'w+') as outfile: json.dump(aggregation_progression, outfile) outfile.close() # update cache jaccard.save_jaccard_cache(prob.name) asymmetric_jaccard.save_asymmetric_jaccard_cache(prob.name) prob.data = aggregation_progression # output report if test_problems is None: report.create_report(probs, "greedy_") end_time = time.time() print(end_time - start_time)