def run_experiment(exp, spn, test_data, test_type, exp_lambda): outprefix = path + "/spns/%s/" % (exp) results_file = "%stime_test_%s_ll_%s.txt" % (outprefix, test_type, OS_name) if os.path.isfile(results_file): return print(exp, test_data.shape, test_type) ll, test_time = exp_lambda() np.savetxt(results_file, ll, delimiter=";") import cpuinfo machine = cpuinfo.get_cpu_info()["brand"] adds, muls = fpga_count_ops(spn) test_n = test_data.shape[0] results = OrderedDict() results["Experiment"] = exp results["OS"] = OS_name results["machine"] = machine results["test type"] = test_type results["expected adds"] = adds results["expected muls"] = muls results["input rows"] = test_n results["input cols"] = test_data.shape[1] results["spn nodes"] = len(get_nodes_by_type(spn, Node)) results["spn sum nodes"] = len(get_nodes_by_type(spn, Sum)) results["spn prod nodes"] = len(get_nodes_by_type(spn, Product)) results["spn leaves"] = len(get_nodes_by_type(spn, Leaf)) results["spn edges"] = get_number_of_edges(spn) results["spn layers"] = get_number_of_layers(spn) results["time per task"] = test_time results["time per instance"] = test_time / test_n results["avg ll"] = np.mean(ll, dtype=np.float128) results_file_name = "results.csv" if not os.path.isfile(results_file_name): results_file = open(results_file_name, "w") results_file.write(";".join(results.keys())) results_file.write("\n") else: results_file = open(results_file_name, "a") results_file.write(";".join(map(str, results.values()))) results_file.write("\n") results_file.close()
results_file.write(";".join(map(str, results.values()))) results_file.write("\n") results_file.close() if __name__ == '__main__': for exp in natsorted(map(os.path.basename, glob.glob(path + '/spns/*'))): outprefix = path + "/spns/%s/" % (exp) spn, words, _ = load_spn_from_file(outprefix) print(exp, fpga_count_ops(spn)) data = np.loadtxt(outprefix + "all_data.txt", delimiter=";") if data.shape[0] < 10000: r = np.random.RandomState(17) test_data = data[r.choice(data.shape[0], 10000), :] else: test_data = data test_data_fname = outprefix + "time_test_data.txt" if not os.path.isfile(test_data_fname): np.savetxt(test_data_fname, test_data, delimiter=";", header=";".join(words))
''' Created on March 29, 2018 @author: Alejandro Molina ''' from spn.leaves.Histograms import Histogram_str_to_spn from spn.experiments.FPGA.GenerateSPNs import fpga_count_ops from spn.io.Graphics import plot_spn from spn.io.Text import str_to_spn if __name__ == '__main__': with open('../experiments/FPGA/spns/NIPS_30/eqq.txt', 'r') as myfile: eq = myfile.read() with open('../experiments/FPGA/spns/NIPS_30/all_data.txt', 'r') as myfile: words = myfile.readline().strip() words = words[2:] words = words.split(';') print(words) spn = str_to_spn(eq, words, Histogram_str_to_spn) print(spn) print(fpga_count_ops(spn)) plot_spn(spn)