From c7a7b48c6739e193ba24eec4d41082271df164ce Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 2 Nov 2020 13:28:40 +0100 Subject: Simplify PELT usage. remove kneedle, refactor code --- lib/model.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'lib/model.py') diff --git a/lib/model.py b/lib/model.py index 57507e7..192cea3 100644 --- a/lib/model.py +++ b/lib/model.py @@ -938,18 +938,26 @@ class PTAModel: def get_substates(self): states = self.states() for k in self.by_param.keys(): - if k[0] == "TX": + if k[0] in states: if self.pelt.needs_refinement(self.by_param[k]["power_traces"]): - print(f"PELT: {k} needs refinement") - penalty = self.pelt.get_penalty_value( - self.by_param[k]["power_traces"] - ) - print( - f" we found {penalty[1]} changepoints with penalty {penalty[0]}" - ) - self.pelt.calc_raw_states( - self.by_param[k]["power_traces"], penalty[0] + logger.debug(f"PELT: {k} needs refinement") + # Assumption: All power traces for this parameter setting + # are similar, so determining the penalty for the first one + # is sufficient. + penalty, changepoints = self.pelt.get_penalty_and_changepoints( + self.by_param[k]["power_traces"][0] ) + if len(changepoints): + logger.debug( + f" we found {len(changepoints)} changepoints with penalty {penalty}" + ) + self.pelt.calc_raw_states( + self.by_param[k]["power_traces"], penalty + ) + else: + logger.debug( + f" we found no changepoints with penalty {penalty}" + ) return None, None -- cgit v1.2.3