backend/sweettweet/services/utils.py
def alarm_metric(a_true, a_pred):  
	'''
	Returned a modified precision and recall score for the alarm prediction
	task that counts an alarm prediction as positive if it happens
	withing 15 min of a real hypoglycemic event
	'''
	a_pred_padded = np.pad(a_pred, pad_width = ((0, 0),(3,3)), constant_values = 0) # pad array to acount for +/- 15 min
	a_true_padded = np.pad(a_true, pad_width = ((0, 0),(3,3)), constant_values = 0)
	
	r = rolling_window(a_pred_padded, 7)
	a_pred_all = (np.sum(r, axis = 2) >= 1).astype(int).flatten()

	t = rolling_window(a_true_padded, 7)
	a_true_all = (np.sum(t, axis = 2) >= 1).astype(int).flatten()

	TP_p = np.sum(np.logical_and(a_pred, a_true_all)) # true positive for precision
	FP = np.sum(a_true) - np.sum(np.logical_and(a_pred, a_true_all)) # false positive
	TP_r = np.sum(np.logical_and(a_pred_all, a_true)) # true positive for recall
	FN = np.sum(a_pred) - np.sum(np.logical_and(a_pred_all, a_true)) # false negative
	return (TP_p, FN, TP_r, FP)

	Returned a modified precision and recall score for the alarm prediction
	task that counts an alarm prediction as positive if it happens
	withing 15 min of a real hypoglycemic event
	
Returned a modified precision and recall score for the alarm prediction
task that counts an alarm prediction as positive if it happens
withing 15 min of a real hypoglycemic event
Returned a modified precision and recall score for the alarm prediction task that counts an alarm prediction as positive if it happens withing 15 min of a real hypoglycemic event
def alarm_metric(a_true, a_pred):  
	a_pred_padded = np.pad(a_pred, pad_width = ((0, 0),(3,3)), constant_values = 0) 
	a_true_padded = np.pad(a_true, pad_width = ((0, 0),(3,3)), constant_values = 0)
	r = rolling_window(a_pred_padded, 7)
	a_pred_all = (np.sum(r, axis = 2) >= 1).astype(int).flatten()
	t = rolling_window(a_true_padded, 7)
	a_true_all = (np.sum(t, axis = 2) >= 1).astype(int).flatten()
	TP_p = np.sum(np.logical_and(a_pred, a_true_all)) 
	FP = np.sum(a_true) - np.sum(np.logical_and(a_pred, a_true_all)) 
	TP_r = np.sum(np.logical_and(a_pred_all, a_true)) 
	FN = np.sum(a_pred) - np.sum(np.logical_and(a_pred_all, a_true)) 
	return (TP_p, FN, TP_r, FP)
def alarm_metric ( a_true , a_pred ) : a_pred_padded = np . pad ( a_pred , pad_width = ( ( 0 , 0 ) , ( 3 , 3 ) ) , constant_values = 0 ) a_true_padded = np . pad ( a_true , pad_width = ( ( 0 , 0 ) , ( 3 , 3 ) ) , constant_values = 0 ) r = rolling_window ( a_pred_padded , 7 ) a_pred_all = ( np . sum ( r , axis = 2 ) >= 1 ) . astype ( int ) . flatten ( ) t = rolling_window ( a_true_padded , 7 ) a_true_all = ( np . sum ( t , axis = 2 ) >= 1 ) . astype ( int ) . flatten ( ) TP_p = np . sum ( np . logical_and ( a_pred , a_true_all ) ) FP = np . sum ( a_true ) - np . sum ( np . logical_and ( a_pred , a_true_all ) ) TP_r = np . sum ( np . logical_and ( a_pred_all , a_true ) ) FN = np . sum ( a_pred ) - np . sum ( np . logical_and ( a_pred_all , a_true ) ) return ( TP_p , FN , TP_r , FP )
Returned a modified precision and recall score for the alarm prediction
task that counts an alarm prediction as positive if it happens
withing 15 min of a real hypoglycemic event
Returned a modified precision and recall score for the alarm prediction task that counts an alarm prediction as positive if it happens withing 15 min of a real hypoglycemic event
'''
	Returned a modified precision and recall score for the alarm prediction
	task that counts an alarm prediction as positive if it happens
	withing 15 min of a real hypoglycemic event
	''' # pad array to acount for +/- 15 min # true positive for precision # false positive # true positive for recall # false negative
a_true
a_pred