def kneedle_novel(points, args): reduced, removed = rdp.rdp(points, args.r) points_reduced = points[reduced] knees = kneedle.auto_knees(points_reduced, p=kneedle.PeakDetection.All) #x = points_reduced[:, 0] #y = points_reduced[:, 1] #plt.plot(x, y) #plt.plot(x[knees], y[knees], 'r+') #plt.show() knees = pp.filter_worst_knees(points_reduced, knees) knees = pp.filter_corner_knees(points_reduced, knees, t=args.c) knees = pp.filter_clusters(points_reduced, knees, clustering.average_linkage, args.t, args.k) knees = rdp.mapping(knees, reduced, removed) return knees
def main(args): # get the expected file from the input file dirname = os.path.dirname(args.i) filename = os.path.splitext(os.path.basename(args.i))[0] expected_file = os.path.join(os.path.normpath(dirname), f'{filename}_expected.csv') expected = None if os.path.exists(expected_file): with open(expected_file, 'r') as f: reader = csv.reader(f, quoting=csv.QUOTE_NONNUMERIC) expected = list(reader) else: expected = [] expected = np.array(expected) points = np.genfromtxt(args.i, delimiter=',') ## Knee detection code ## reduced, removed = rdp.rdp(points, args.r) points_reduced = points[reduced] knees = np.arange(1, len(reduced)) t_k = pp.filter_worst_knees(points_reduced, knees) t_k = pp.filter_corner_knees(points_reduced, t_k, t=args.c) filtered_knees = pp.filter_clusters(points_reduced, t_k, clustering.average_linkage, args.t, args.k) ########################################################################################## # add even points if args.a: knees = pp.add_points_even(points, reduced, filtered_knees, removed) else: knees = rdp.mapping(filtered_knees, reduced, removed) rmspe_k = evaluation.rmspe(points, knees, expected, evaluation.Strategy.knees) rmspe_e = evaluation.rmspe(points, knees, expected, evaluation.Strategy.expected) cm = evaluation.cm(points, knees, expected, t = 0.01) mcc = evaluation.mcc(cm) logger.info(f'RMSE(knees) RMSE(exp) MCC') logger.info(f'-------------------------------------------') logger.info(f'{rmspe_k:10.2E} {rmspe_e:10.2E} {mcc:10.2E}') # store outpout if args.o: dirname = os.path.dirname(args.i) filename = os.path.splitext(os.path.basename(args.i))[0] output = os.path.join(os.path.normpath(dirname), f'{filename}_output.csv') dataset = points[knees] with open(output, 'w') as f: writer = csv.writer(f) writer.writerows(dataset) # display result if args.g: x = points[:, 0] y = points[:, 1] plt.plot(x, y) plt.plot(x[knees], y[knees], 'r+') plt.show()