def get_structure_stats_dict(node): node_types = dict(Counter([type(n) for n in get_nodes_by_type(node)])) num_nodes = len(get_nodes_by_type(node, Node)) edges = get_number_of_edges(node) layers = get_number_of_layers(node) return { 'nodes': num_nodes, 'edges': edges, 'layers': layers }.update(node_types)
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()
def get_structure_stats(node): num_nodes = len(get_nodes_by_type(node, Node)) sum_nodes = len(get_nodes_by_type(node, Sum)) prod_nodes = len(get_nodes_by_type(node, Product)) leaf_nodes = len(get_nodes_by_type(node, Leaf)) edges = get_number_of_edges(node) layers = get_number_of_layers(node) return """---Structure Statistics--- # nodes %s # sum nodes %s # prod nodes %s # leaf nodes %s # edges %s # layers %s""" % (num_nodes, sum_nodes, prod_nodes, leaf_nodes, edges, layers)
def get_structure_stats_dict(node): num_nodes = len(get_nodes_by_type(node, Node)) sum_nodes = len( [s for s in get_nodes_by_type(node, Sum) if type(s) == Sum]) prod_nodes = len(get_nodes_by_type(node, Product)) leaf_nodes = len(get_nodes_by_type(node, Leaf)) param_leaf_nodes = len(get_nodes_by_type(node, Parametric)) type_leaf_nodes = len(get_nodes_by_type(node, TypeLeaf)) edges = get_number_of_edges(node) layers = get_number_of_layers(node) return { 'nodes': num_nodes, 'edges': edges, 'layers': layers, 'sum': sum_nodes, 'prod': prod_nodes, 'leaf': leaf_nodes, 'param-leaf': param_leaf_nodes, 'type-leaf': type_leaf_nodes }