Skip to content

Commit

Permalink
CONT-285: Let the user decide whether epsilon or avg_transition_toler…
Browse files Browse the repository at this point in the history
…ance should be used.
  • Loading branch information
Henning-Schulz committed Nov 21, 2019
1 parent 53c5893 commit c02d31e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion clustinator/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, sessions_json):
self.data = json.loads(sessions_json)

def cluster_param(self):
return self.data['avg-transition-tolerance'], self.data['min-sample-size']
return self.data.get('avg-transition-tolerance'), self.data.get('epsilon'), self.data['min-sample-size']

def get_header(self):
header_dict = {}
Expand Down
11 changes: 8 additions & 3 deletions clustinator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ def start(self):
start_time = datetime.now()

data_input = Input(self.sessions_file)
avg_tolerance, min_samples = data_input.cluster_param()
avg_tolerance, epsilon, min_samples = data_input.cluster_param()
header = data_input.get_header()
app_id = data_input.get_app_id()
tailoring = data_input.get_tailoring()
start_micros, interval_start_micros, end_micros = data_input.get_range_micros()

print(datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'), 'Clustering for app-id', app_id, 'with avg. transition tolerance', avg_tolerance, 'and min-sample-size', min_samples)
if epsilon is None:
print(datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'), 'Clustering for app-id', app_id, 'with avg. transition tolerance', avg_tolerance, 'and min-sample-size', min_samples)
else:
print(datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'), 'Clustering for app-id', app_id, 'with epsilon', epsilon, 'and min-sample-size', min_samples)

print(datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'), 'Loading previous Markov chains...')
prev_behavior_model = BehaviorModel(app_id, tailoring, interval_start_micros)
Expand All @@ -49,7 +52,9 @@ def start(self):

print(datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'), 'Converting to CSR...')
csr_matrix = matrix.as_csr_matrix()
epsilon = (len(matrix.states()) - 1) * avg_tolerance

if epsilon is None:
epsilon = (len(matrix.states()) - 1) * avg_tolerance

print(datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'), 'Matrix creation done. Starting the clustering with epsilon', epsilon, '...')

Expand Down

0 comments on commit c02d31e

Please sign in to comment.