kodokan.recognize#
Learned-vs-DTW technique recognition experiments (data-appropriate, no GPU).
The feature bake-off showed DTW on hand-crafted angles can’t tell techniques apart. This module tests whether the bottleneck is the classifier, the features, or tori/uke role inconsistency, with leave-one-out CV on the small dataset:
feature modes:
primary_angles(baseline),tori_angles(role-consistent — tori picked as the person left standing),tori_angles_pos.methods:
dtw_1nn(DTW nearest-neighbour),pool_centroid/pool_knn(temporal-pyramid pooled descriptor + nearest-centroid / kNN), andpool_lda_knn(LDA-reduced + kNN, if scikit-learn is available).
Everything is numpy (sklearn optional), appropriate for ~80 samples where deep nets would overfit; the same harness scales to more techniques once more data is collected.
Functions
|
Top-1, balanced (macro-recall), majority-class baseline, n_classes, n. |
|
Most-frequent misclassifications as |
|
Per-frame features for one demo under a role/feature mode. |
|
|
|
Leave-one-out 1-NN by DTW distance; returns predicted label per item. |
|
Leak-free (leave-one-demo-out medoid) technique-separability report. |
|
Leave-one-out (or leave-one-GROUP-out) predictions; preprocessing fit on train only. |
|
Per-frame features of the horizontally mirrored demo, from |
|
95% percentile-bootstrap CIs for A, B and the PAIRED difference A−B. |
|
|
|
|
|
|
|
Temporal-pyramid pooled fixed-length descriptor (mean+std per segment). |
|
Standard ROC-AUC for a distance score: |
|
|
|
Tori (thrower) heuristic with a confidence margin and an abstain flag. |
|
Aggregate fall-back / abstain rates and median margin over decisions. |
|
Heuristic tori slot (thin wrapper over |
Classes
|
Outcome of the tori/uke role heuristic, with a confidence margin. |
- class kodokan.recognize.ToriDecision(index, margin, fell_back, abstained)[source]#
Bases:
objectOutcome of the tori/uke role heuristic, with a confidence margin.
The “role-consistency is the dominant recognition lever” claim rests on this heuristic, so — per the adversarial review — every call is now instrumented.
- margin#
Finish-frame hip-y separation between the two judoka in torso-length units (how much lower uke’s hips sit than tori’s). Larger = more confident;
nanwhen the cue was unusable.- Type:
- kodokan.recognize.classification_metrics(y_true, y_pred, *, n_boot=0, seed=0)[source]#
Top-1, balanced (macro-recall), majority-class baseline, n_classes, n.
Pass
n_boot > 0to add 95% percentile-bootstrap confidence intervals (top1_ci/balanced_ci) — the rigor the review asked for, so small-n accuracy differences aren’t over-read. Defaultn_boot=0is unchanged.- Return type:
- kodokan.recognize.confusion_pairs(y_true, y_pred, *, top=None)[source]#
Most-frequent misclassifications as
{true, pred, count}(off-diagonal).Per-class confusion that stays readable at many classes: instead of a dense N×N matrix it returns only the non-zero true→pred error cells, sorted by count. A
predof-1means an abstain/no-prediction.
- kodokan.recognize.demo_feature(pose_seq, start_s, end_s, *, mode)[source]#
Per-frame features for one demo under a role/feature mode.
- Return type:
ndarray
- kodokan.recognize.dtw_1nn_predict(feature_seqs, labels)[source]#
Leave-one-out 1-NN by DTW distance; returns predicted label per item.
- Return type:
- kodokan.recognize.loo_medoid_separability(feats_by_tech, *, distance, per_demo=False)[source]#
Leak-free (leave-one-demo-out medoid) technique-separability report.
The earlier feature bake-off built each technique’s medoid reference from all its demos, including the one being tested — so genuine distances were optimistically low and needed an ad-hoc self-zero filter. Here a held-out demo’s GENUINE distance is measured to the medoid of its technique’s other demos (true leave-one-out, no self-zero), and its IMPOSTOR distances to every other technique’s medoid. Reports leave-one-out nearest-medoid accuracy and the standard ROC-AUC (
roc_auc_distances()).- Parameters:
feats_by_tech (
list) – per technique, a list of per-demo feature arrays.distance –
(feat_a, feat_b) -> float(e.g. normalized DTW).per_demo (
bool) – also returnper_demo— one{tech, genuine, impostor, correct}per held-out demo, in input order — so callers can bootstrap without recomputing distances (seepaired_bootstrap_separability()).
- Return type:
- kodokan.recognize.loo_pooled_predict(X, y, *, method='lda_knn', k=3, groups=None, X_aug=None)[source]#
Leave-one-out (or leave-one-GROUP-out) predictions; preprocessing fit on train only.
If
groupsis given (e.g. sourcevideo_idper sample), each fold excludes ALL samples sharing the held-out sample’s group — i.e. leave-one-clip-out, which removes within-clip leakage. Otherwise it is plain leave-one-sample-out.X_aug(same shape asX, rowjan augmented copy of samplej, e.g. the pooledmirror_feature()) adds the copies of the TRAIN-fold samples to each fold’s training set; a held-out sample’s own copy (and its group’s) never trains.- Return type:
ndarray
- kodokan.recognize.mirror_feature(feat, *, mode)[source]#
Per-frame features of the horizontally mirrored demo, from
demo_feature()’s.mirror_feature(demo_feature(seq, ...), mode=m)equalsdemo_featureof the mirroredseq(tested), so mirrored training copies cost no pose estimation.- Return type:
ndarray
- kodokan.recognize.paired_bootstrap_separability(rows_a, rows_b, *, n_boot=2000, seed=0)[source]#
95% percentile-bootstrap CIs for A, B and the PAIRED difference A−B.
rows_a/rows_bareper_demooutputs ofloo_medoid_separability()over the SAME demos in the same order (e.g. two modalities on identical frames), so each resample draws the same demos for both — the difference CI then reflects only the modality, not which demos happened to be drawn. Distances are reused, not recomputed. A difference CI that straddles 0 means “not distinguishable at this n”.- Return type:
- kodokan.recognize.pooled_descriptor(feat, *, levels=(1, 2, 4))[source]#
Temporal-pyramid pooled fixed-length descriptor (mean+std per segment).
- Return type:
ndarray
- kodokan.recognize.roc_auc_distances(genuine, impostor)[source]#
Standard ROC-AUC for a distance score:
P(impostor > genuine)(ties=0.5).Equals the Mann–Whitney U statistic divided by
|genuine|·|impostor|— the “standard ROC-AUC” the review asked for (replacing the ad-hoc self-zero-dropping estimate). Larger = better separation (impostor demos sit farther than genuine ones). NaNs are dropped; returnsnanif either side is empty.- Return type:
- kodokan.recognize.similarity_from_confusion(y_true, y_pred, *, symmetric=True)[source]#
target -> {other: weight}(0..1) from a recognizer’s confusions.weightis the share oftarget’s samples predicted asother(off-diagonal only; abstains and self-predictions are ignored). Withsymmetric(default) the weight is the mean of both directions, so “a looks like b” implies “b looks like a”, which suits distractor choice. Same shape asflashcards.build_confusability, so it plugs intoQuiz(similarity=...).- Return type:
- kodokan.recognize.tori_decision(pose_seq, start_s, end_s, *, abstain_margin=0.15)[source]#
Tori (thrower) heuristic with a confidence margin and an abstain flag.
Tori is the judoka whose hips stay highest (smallest image-y) over the last third of the demo — uke has been thrown to the ground. The margin is the two judoka’s finish hip-y separation in torso-length units; below
abstain_margin(or when the cue is unusable and we fall back to presence) the role assignment is unreliable andabstainedis set. Seetori_decision_stats()for aggregate fall-back/abstain rates.- Return type:
- kodokan.recognize.tori_decision_stats(decisions)[source]#
Aggregate fall-back / abstain rates and median margin over decisions.
The instrumentation the review asked for: run this over every demo’s
tori_decision()to see how often the “dominant lever” heuristic is actually confident vs. abstaining.- Return type:
- kodokan.recognize.tori_index(pose_seq, start_s, end_s)[source]#
Heuristic tori slot (thin wrapper over
tori_decision()).Backward-compatible: returns just the chosen slot. Use
tori_decision()when you need the confidence margin / abstain flag.- Return type: