diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2020-10-08 16:16:12 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2020-10-08 16:16:12 +0200 |
commit | 6fce6af60e7c99e77fcc24084db001367a7813be (patch) | |
tree | e70495cc5dd9f60e9976ac52c4429e0b15c280a9 /bin | |
parent | d5ace16a8efb627aa9882e595a8bfd1778b6ae36 (diff) |
BA Janis import: working detection of optimal number of changepoints
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/analyze-archive.py | 100 |
1 files changed, 19 insertions, 81 deletions
diff --git a/bin/analyze-archive.py b/bin/analyze-archive.py index e9694b4..1217be6 100755 --- a/bin/analyze-archive.py +++ b/bin/analyze-archive.py @@ -49,32 +49,6 @@ from dfatool.validation import CrossValidator from dfatool.utils import filter_aggregate_by_param from dfatool.automata import PTA -### PELT -import numpy as np - -# Very short benchmark yielded approx. 3 times the speed of solution not using sort -# checks the percentiles if refinement is necessary -def needs_refinement(signal, thresh): - sorted_signal = sorted(signal) - length_of_signal = len(signal) - percentile_size = int() - percentile_size = length_of_signal // 100 - lower_percentile = sorted_signal[0:percentile_size] - upper_percentile = sorted_signal[ - length_of_signal - percentile_size : length_of_signal - ] - lower_percentile_mean = np.mean(lower_percentile) - upper_percentile_mean = np.mean(upper_percentile) - median = np.median(sorted_signal) - dist = median - lower_percentile_mean - if dist > thresh: - return True - dist = upper_percentile_mean - median - if dist > thresh: - return True - return False - -### /PELT def print_model_quality(results): for state_or_tran in results.keys(): @@ -378,8 +352,9 @@ if __name__ == "__main__": ) parser.add_argument( "--with-substates", - action="store_true", - help="Perform substate analysis" + metavar="PELT_CONFIG", + type=str, + help="Perform substate analysis", ) parser.add_argument("measurement", nargs="+") @@ -427,7 +402,11 @@ if __name__ == "__main__": raw_data = RawData( args.measurement, - with_traces=(args.export_traces is not None or args.plot_traces is not None or args.with_substates is not None), + with_traces=( + args.export_traces is not None + or args.plot_traces is not None + or args.with_substates is not None + ), skip_cache=args.no_cache, ) @@ -476,58 +455,13 @@ if __name__ == "__main__": with open(target, "w") as f: json.dump(data, f) - if args.with_substates: - opt_refinement_thresh = 100 - uw_per_sot = dict() - for trace in preprocessed_data: - for state_or_transition in trace["trace"]: - if state_or_transition["isa"] == "state": - name = state_or_transition["name"] - if name not in uw_per_sot: - uw_per_sot[name] = list() - for elem in state_or_transition["offline"]: - elem["uW"] = list(elem["uW"]) - uw_per_sot[name].append(state_or_transition) - for name, configurations in uw_per_sot.items(): - for num_config, measurements_by_config in enumerate(configurations): - logging.debug( - "Looking at state '" - + measurements_by_config["name"] - + "' with params: " - + str(measurements_by_config["parameter"]) - + "(" - + str(num_config + 1) - + "/" - + str(len(configurations)) - + ")" - ) - num_needs_refine = 0 - logging.debug("Checking if refinement is necessary...") - for measurement in measurements_by_config["offline"]: - # loop through measurements of particular state - # and check if state needs refinement - signal = measurement["uW"] - # mean = measurement['uW_mean'] - if needs_refinement(signal, opt_refinement_thresh): - num_needs_refine = num_needs_refine + 1 - if num_needs_refine == 0: - logging.debug( - "No refinement necessary for state '" - + measurements_by_config["name"] - + "' with params: " - + str(measurements_by_config["parameter"]) - ) - elif num_needs_refine < len(measurements_by_config["offline"]) / 2: - logging.debug( - "No refinement necessary for state '" - + measurements_by_config["name"] - + "' with params: " - + str(measurements_by_config["parameter"]) - ) - logging.debug( - "However this decision was not unanimously. This could hint at poor " - "measurement quality." - ) + if args.with_substates is not None: + arg_dict = dict() + if args.with_substates != "": + for kv in args.with_substates.split(","): + k, v = kv.split("=") + arg_dict[k] = v + args.with_substates = arg_dict if args.plot_traces: traces = list() @@ -576,6 +510,7 @@ if __name__ == "__main__": traces=preprocessed_data, function_override=function_override, pta=pta, + pelt=args.with_substates, ) if xv_method: @@ -698,6 +633,9 @@ if __name__ == "__main__": safe_functions_enabled=safe_functions_enabled ) + if args.with_substates is not None: + substate_model, substate_info = model.get_substates() + if "paramdetection" in show_models or "all" in show_models: for state in model.states_and_transitions(): for attribute in model.attributes(state): |