|
@@ 384-463 (lines=80) @@
|
| 381 |
|
return start_mismatch, stop_mismatch |
| 382 |
|
|
| 383 |
|
|
| 384 |
|
def _get_timeliness_measures(classes, truth, prediction, time_list): |
| 385 |
|
num_classes = len(classes) |
| 386 |
|
start_mismatch = [list([]) for i in range(num_classes)] |
| 387 |
|
stop_mismatch = [list([]) for i in range(num_classes)] |
| 388 |
|
# Processing segmentation first! |
| 389 |
|
for j in range(num_classes): |
| 390 |
|
pred_segs = [] |
| 391 |
|
truth_segs = [] |
| 392 |
|
prev_pred = False |
| 393 |
|
prev_truth = False |
| 394 |
|
tseg_start = 0 |
| 395 |
|
tseg_stop = 0 |
| 396 |
|
pseg_start = 0 |
| 397 |
|
pseg_stop = 0 |
| 398 |
|
for i in range(truth.shape[0]): |
| 399 |
|
cur_truth = (int(truth[i]) == j) |
| 400 |
|
cur_pred = (int(prediction[i]) == j) |
| 401 |
|
# Truth segments |
| 402 |
|
if cur_truth != prev_truth: |
| 403 |
|
if cur_truth: |
| 404 |
|
tseg_start = i |
| 405 |
|
elif tseg_stop != 0: |
| 406 |
|
truth_segs.append((tseg_start, tseg_stop)) |
| 407 |
|
tseg_stop = i |
| 408 |
|
# Prediction segments |
| 409 |
|
if cur_pred != prev_pred: |
| 410 |
|
if cur_pred: |
| 411 |
|
pseg_start = i |
| 412 |
|
elif pseg_stop != 0: |
| 413 |
|
pred_segs.append((pseg_start, pseg_stop)) |
| 414 |
|
pseg_stop = i |
| 415 |
|
prev_truth = cur_truth |
| 416 |
|
prev_pred = cur_pred |
| 417 |
|
# Add compensated segments to predictions egments |
| 418 |
|
for ts, (tseg_start, tseg_stop) in enumerate(truth_segs): |
| 419 |
|
ps = _find_overlap_seg(pred_segs, tseg_start) |
| 420 |
|
if ps == -1: |
| 421 |
|
# potential underfill or deletion |
| 422 |
|
ps = _find_seg_start_within(pred_segs, tseg_start, tseg_stop) |
| 423 |
|
if ps != -1: |
| 424 |
|
pseg_start = pred_segs[ps][0] |
| 425 |
|
offset = (time_list[tseg_start] - time_list[pseg_start]).total_seconds() |
| 426 |
|
if tseg_start != pseg_start and abs(offset) < 18000: |
| 427 |
|
start_mismatch[j].append(offset) |
| 428 |
|
else: |
| 429 |
|
pseg_start = pred_segs[ps][0] |
| 430 |
|
# Check the end of previous truth |
| 431 |
|
if ts > 1 and truth_segs[ts-1][1] >= pseg_start: |
| 432 |
|
continue |
| 433 |
|
else: |
| 434 |
|
offset = (time_list[tseg_start] - time_list[pseg_start]).total_seconds() |
| 435 |
|
if tseg_start != pseg_start and abs(offset) < 18000: |
| 436 |
|
# Calculate overfill |
| 437 |
|
start_mismatch[j].append((time_list[tseg_start] - time_list[pseg_start]).total_seconds()) |
| 438 |
|
for ts, (tseg_start, tseg_stop) in enumerate(truth_segs): |
| 439 |
|
ps = _find_overlap_seg(pred_segs, tseg_stop) |
| 440 |
|
if ps == -1: |
| 441 |
|
# potential underfill or deletion |
| 442 |
|
ps = _find_seg_end_within(pred_segs, tseg_start, tseg_stop) |
| 443 |
|
if ps != -1: |
| 444 |
|
pseg_stop = pred_segs[ps][1] |
| 445 |
|
offset = (time_list[tseg_stop] - time_list[pseg_stop]).total_seconds() |
| 446 |
|
if tseg_stop != pseg_stop and abs(offset) < 18000: |
| 447 |
|
stop_mismatch[j].append(offset) |
| 448 |
|
else: |
| 449 |
|
pseg_stop = pred_segs[ps][1] |
| 450 |
|
# Check the end of previous truth |
| 451 |
|
if ts < len(truth_segs) - 1 and truth_segs[ts-1][0] <= pseg_stop: |
| 452 |
|
continue |
| 453 |
|
else: |
| 454 |
|
offset = (time_list[tseg_stop] - time_list[pseg_stop]).total_seconds() |
| 455 |
|
if tseg_stop != pseg_stop and abs(offset) < 18000: |
| 456 |
|
# Calculate overfill |
| 457 |
|
stop_mismatch[j].append(offset) |
| 458 |
|
# print("class: %d" % j) |
| 459 |
|
# print("pred_segs: %d %s" % (len(pred_segs), str(pred_segs))) |
| 460 |
|
# print("truth_segs: %d %s" % (len(truth_segs), str(truth_segs))) |
| 461 |
|
# print("start_mismatch: %s" % start_mismatch) |
| 462 |
|
# print("stop_mismatch: %s" % stop_mismatch) |
| 463 |
|
return start_mismatch, stop_mismatch |
| 464 |
|
|
| 465 |
|
|
| 466 |
|
def _get_timeliness_measures_depricated(classes, truth, prediction, truth_scoring, prediction_scoring, time_list): |
|
@@ 302-381 (lines=80) @@
|
| 299 |
|
return found_seg_id |
| 300 |
|
|
| 301 |
|
|
| 302 |
|
def _get_timeoffset_measures(classes, truth, prediction, time_list): |
| 303 |
|
num_classes = len(classes) |
| 304 |
|
start_mismatch = [list([]) for i in range(num_classes)] |
| 305 |
|
stop_mismatch = [list([]) for i in range(num_classes)] |
| 306 |
|
# Processing segmentation first! |
| 307 |
|
for j in range(num_classes): |
| 308 |
|
pred_segs = [] |
| 309 |
|
truth_segs = [] |
| 310 |
|
prev_pred = False |
| 311 |
|
prev_truth = False |
| 312 |
|
tseg_start = 0 |
| 313 |
|
tseg_stop = 0 |
| 314 |
|
pseg_start = 0 |
| 315 |
|
pseg_stop = 0 |
| 316 |
|
for i in range(truth.shape[0]): |
| 317 |
|
cur_truth = (int(truth[i]) == j) |
| 318 |
|
cur_pred = (int(prediction[i]) == j) |
| 319 |
|
# Truth segments |
| 320 |
|
if cur_truth != prev_truth: |
| 321 |
|
if cur_truth: |
| 322 |
|
tseg_start = i |
| 323 |
|
elif tseg_stop != 0: |
| 324 |
|
truth_segs.append((tseg_start, tseg_stop)) |
| 325 |
|
tseg_stop = i |
| 326 |
|
# Prediction segments |
| 327 |
|
if cur_pred != prev_pred: |
| 328 |
|
if cur_pred: |
| 329 |
|
pseg_start = i |
| 330 |
|
elif pseg_stop != 0: |
| 331 |
|
pred_segs.append((pseg_start, pseg_stop)) |
| 332 |
|
pseg_stop = i |
| 333 |
|
prev_truth = cur_truth |
| 334 |
|
prev_pred = cur_pred |
| 335 |
|
# Add compensated segments to predictions egments |
| 336 |
|
for ts, (tseg_start, tseg_stop) in enumerate(truth_segs): |
| 337 |
|
ps = _find_overlap_seg(pred_segs, tseg_start) |
| 338 |
|
if ps == -1: |
| 339 |
|
# potential underfill or deletion |
| 340 |
|
ps = _find_seg_start_within(pred_segs, tseg_start, tseg_stop) |
| 341 |
|
if ps != -1: |
| 342 |
|
pseg_start = pred_segs[ps][0] |
| 343 |
|
offset = (time_list[tseg_start] - time_list[pseg_start]).total_seconds() |
| 344 |
|
if abs(offset) < 18000: |
| 345 |
|
start_mismatch[j].append(offset) |
| 346 |
|
else: |
| 347 |
|
pseg_start = pred_segs[ps][0] |
| 348 |
|
# Check the end of previous truth |
| 349 |
|
if ts > 1 and truth_segs[ts-1][1] >= pseg_start: |
| 350 |
|
continue |
| 351 |
|
else: |
| 352 |
|
offset = (time_list[tseg_start] - time_list[pseg_start]).total_seconds() |
| 353 |
|
if abs(offset) < 18000: |
| 354 |
|
# Calculate overfill |
| 355 |
|
start_mismatch[j].append((time_list[tseg_start] - time_list[pseg_start]).total_seconds()) |
| 356 |
|
for ts, (tseg_start, tseg_stop) in enumerate(truth_segs): |
| 357 |
|
ps = _find_overlap_seg(pred_segs, tseg_stop) |
| 358 |
|
if ps == -1: |
| 359 |
|
# potential underfill or deletion |
| 360 |
|
ps = _find_seg_end_within(pred_segs, tseg_start, tseg_stop) |
| 361 |
|
if ps != -1: |
| 362 |
|
pseg_stop = pred_segs[ps][1] |
| 363 |
|
offset = (time_list[tseg_stop] - time_list[pseg_stop]).total_seconds() |
| 364 |
|
if tseg_stop != pseg_stop and abs(offset) < 18000: |
| 365 |
|
stop_mismatch[j].append(offset) |
| 366 |
|
else: |
| 367 |
|
pseg_stop = pred_segs[ps][1] |
| 368 |
|
# Check the end of previous truth |
| 369 |
|
if ts < len(truth_segs) - 1 and truth_segs[ts-1][0] <= pseg_stop: |
| 370 |
|
continue |
| 371 |
|
else: |
| 372 |
|
offset = (time_list[tseg_stop] - time_list[pseg_stop]).total_seconds() |
| 373 |
|
if abs(offset) < 18000: |
| 374 |
|
# Calculate overfill |
| 375 |
|
stop_mismatch[j].append(offset) |
| 376 |
|
# print("class: %d" % j) |
| 377 |
|
# print("pred_segs: %d %s" % (len(pred_segs), str(pred_segs))) |
| 378 |
|
# print("truth_segs: %d %s" % (len(truth_segs), str(truth_segs))) |
| 379 |
|
# print("start_mismatch: %s" % start_mismatch) |
| 380 |
|
# print("stop_mismatch: %s" % stop_mismatch) |
| 381 |
|
return start_mismatch, stop_mismatch |
| 382 |
|
|
| 383 |
|
|
| 384 |
|
def _get_timeliness_measures(classes, truth, prediction, time_list): |