{"id":"edr","title":"Edit distance on real sequences","family":"elastic","definition":"echotime","intro_en":"EDR replaces the size of a sample discrepancy with a thresholded substitution cost. A nearby pair costs zero, a mismatching substitution costs one, and insertions or deletions cost one. Dynamic programming finds the least expensive edit sequence; this example reports EchoTime's length-normalized default.","intro_zh":"EDR 把观测差异转成阈值替换代价：相近配对为零，不匹配替换为一，插入和删除也为一。动态规划寻找费用最低的编辑序列；本例采用 EchoTime 默认的长度归一化输出。","steps_en":["Set the stated local scoring rule, tolerance and boundary conditions.","Choose the cheapest substitution, insertion or deletion for each prefix.","Trace the selected predecessor operations from the complete-prefix state.","Read the final score with the normalization explicitly stated below."],"steps_zh":["设置明确的局部计分规则、容差与边界条件。","逐个前缀选择费用最低的替换、插入或删除。","从完整前缀状态沿选定的前驱操作回溯。","按下方明确的归一化约定读取最终分数。"],"formula":"D_ij=min(D_(i-1,j)+1,D_(i,j-1)+1,D_(i-1,j-1)+1[|x_i-y_j|>epsilon]); d=D_nm/max(n,m)","caveats_en":["The amplitude of a mismatch beyond epsilon is discarded. Normalization and epsilon must be specified when comparing implementations.","The small arrays are an algorithm illustration, not evidence of retrieval or classification quality."],"caveats_zh":["超过 epsilon 后的误差幅度被丢弃；比较不同实现时须明确容差与归一化。","这些小数组用于解释计算过程，不构成检索或分类性能证据。"],"sources":[{"label":"EchoTime low-level similarity implementations","url":"https://github.com/ZipengWu365/EchoTime/blob/main/src/echotime/similarity_methods.py"},{"label":"EchoTime imported atlas: named formula conventions","url":"https://github.com/ZipengWu365/EchoTime/blob/main/src/echotime/data/ts_similarity_package_v2_registry.csv"}],"x":[0.2,0.4,1.1,2.4,3.2,2.5,1.2,0.3,-0.4,-0.1],"y":[0.1,0.3,0.5,1.2,2.6,3.1,2.3,1.1,0.2,-0.3],"input_label":"Deterministic illustrative arrays; no benchmark data","parameters":{"normalization":"edit count / max(n,m)","local_norm":"absolute difference","epsilon":0.35},"result":{"label":"distance","value":0.2,"detail":"The explicit definition and parameters shown on this card."},"frames":[{"phase":0,"caption":"Compare samples to construct the local table","panel":{"kind":"matrix","title":"Substitution costs","z":[[0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0],[0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0],[1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null]],"row_label":"x index","col_label":"y index","cursor":[2,0]}},{"phase":0,"caption":"Compare samples to construct the local table","panel":{"kind":"matrix","title":"Substitution costs","z":[[0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0],[0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0],[1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0],[1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0],[1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null]],"row_label":"x index","col_label":"y index","cursor":[4,0]}},{"phase":0,"caption":"Compare samples to construct the local table","panel":{"kind":"matrix","title":"Substitution costs","z":[[0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0],[0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0],[1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0],[1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0],[1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0],[1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0],[1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0],[0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null]],"row_label":"x index","col_label":"y index","cursor":[7,0]}},{"phase":0,"caption":"Compare samples to construct the local table","panel":{"kind":"matrix","title":"Substitution costs","z":[[0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0],[0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0],[1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0],[1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0],[1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0],[1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0],[1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0],[0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0],[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0],[0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0]],"row_label":"x index","col_label":"y index","cursor":[9,0]}},{"phase":1,"caption":"Extend solved prefixes using the stated recurrence","panel":{"kind":"matrix","title":"Accumulated edit costs","z":[[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null]],"row_label":"x index","col_label":"y index","cursor":[0,9]},"value":9.0,"value_label":"prefix cost"},{"phase":1,"caption":"Extend solved prefixes using the stated recurrence","panel":{"kind":"matrix","title":"Accumulated edit costs","z":[[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0],[1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null]],"row_label":"x index","col_label":"y index","cursor":[1,9]},"value":8.0,"value_label":"prefix cost"},{"phase":1,"caption":"Extend solved prefixes using the stated recurrence","panel":{"kind":"matrix","title":"Accumulated edit costs","z":[[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0],[1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],[2.0,1.0,1.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null]],"row_label":"x index","col_label":"y index","cursor":[2,9]},"value":7.0,"value_label":"prefix cost"},{"phase":1,"caption":"Extend solved prefixes using the stated recurrence","panel":{"kind":"matrix","title":"Accumulated edit costs","z":[[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0],[1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],[2.0,1.0,1.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0],[3.0,2.0,2.0,2.0,1.0,2.0,3.0,4.0,5.0,6.0],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null]],"row_label":"x index","col_label":"y index","cursor":[3,9]},"value":6.0,"value_label":"prefix cost"},{"phase":1,"caption":"Extend solved prefixes using the stated recurrence","panel":{"kind":"matrix","title":"Accumulated edit costs","z":[[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0],[1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],[2.0,1.0,1.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0],[3.0,2.0,2.0,2.0,1.0,2.0,3.0,4.0,5.0,6.0],[4.0,3.0,3.0,3.0,2.0,1.0,2.0,3.0,4.0,5.0],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null]],"row_label":"x index","col_label":"y index","cursor":[4,9]},"value":5.0,"value_label":"prefix cost"},{"phase":1,"caption":"Extend solved prefixes using the stated recurrence","panel":{"kind":"matrix","title":"Accumulated edit costs","z":[[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0],[1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],[2.0,1.0,1.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0],[3.0,2.0,2.0,2.0,1.0,2.0,3.0,4.0,5.0,6.0],[4.0,3.0,3.0,3.0,2.0,1.0,2.0,3.0,4.0,5.0],[5.0,4.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null]],"row_label":"x index","col_label":"y index","cursor":[5,9]},"value":4.0,"value_label":"prefix cost"},{"phase":1,"caption":"Extend solved prefixes using the stated recurrence","panel":{"kind":"matrix","title":"Accumulated edit costs","z":[[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0],[1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],[2.0,1.0,1.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0],[3.0,2.0,2.0,2.0,1.0,2.0,3.0,4.0,5.0,6.0],[4.0,3.0,3.0,3.0,2.0,1.0,2.0,3.0,4.0,5.0],[5.0,4.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0],[6.0,5.0,5.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null]],"row_label":"x index","col_label":"y index","cursor":[6,9]},"value":3.0,"value_label":"prefix cost"},{"phase":1,"caption":"Extend solved prefixes using the stated recurrence","panel":{"kind":"matrix","title":"Accumulated edit costs","z":[[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0],[1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],[2.0,1.0,1.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0],[3.0,2.0,2.0,2.0,1.0,2.0,3.0,4.0,5.0,6.0],[4.0,3.0,3.0,3.0,2.0,1.0,2.0,3.0,4.0,5.0],[5.0,4.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0],[6.0,5.0,5.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0],[7.0,6.0,5.0,5.0,5.0,4.0,3.0,2.0,1.0,2.0],[null,null,null,null,null,null,null,null,null,null],[null,null,null,null,null,null,null,null,null,null]],"row_label":"x index","col_label":"y index","cursor":[7,9]},"value":2.0,"value_label":"prefix cost"},{"phase":1,"caption":"Extend solved prefixes using the stated recurrence","panel":{"kind":"matrix","title":"Accumulated edit costs","z":[[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0],[1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],[2.0,1.0,1.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0],[3.0,2.0,2.0,2.0,1.0,2.0,3.0,4.0,5.0,6.0],[4.0,3.0,3.0,3.0,2.0,1.0,2.0,3.0,4.0,5.0],[5.0,4.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0],[6.0,5.0,5.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0],[7.0,6.0,5.0,5.0,5.0,4.0,3.0,2.0,1.0,2.0],[8.0,7.0,6.0,6.0,6.0,5.0,4.0,3.0,2.0,1.0],[null,null,null,null,null,null,null,null,null,null]],"row_label":"x index","col_label":"y index","cursor":[8,9]},"value":1.0,"value_label":"prefix cost"},{"phase":1,"caption":"Extend solved prefixes using the stated recurrence","panel":{"kind":"matrix","title":"Accumulated edit costs","z":[[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0],[1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],[2.0,1.0,1.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0],[3.0,2.0,2.0,2.0,1.0,2.0,3.0,4.0,5.0,6.0],[4.0,3.0,3.0,3.0,2.0,1.0,2.0,3.0,4.0,5.0],[5.0,4.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0],[6.0,5.0,5.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0],[7.0,6.0,5.0,5.0,5.0,4.0,3.0,2.0,1.0,2.0],[8.0,7.0,6.0,6.0,6.0,5.0,4.0,3.0,2.0,1.0],[9.0,8.0,7.0,7.0,7.0,6.0,5.0,4.0,3.0,2.0]],"row_label":"x index","col_label":"y index","cursor":[9,9]},"value":2.0,"value_label":"prefix cost"},{"phase":2,"caption":"Follow the chosen predecessor decisions","panel":{"kind":"matrix","title":"Accumulated edit costs","z":[[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0],[1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],[2.0,1.0,1.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0],[3.0,2.0,2.0,2.0,1.0,2.0,3.0,4.0,5.0,6.0],[4.0,3.0,3.0,3.0,2.0,1.0,2.0,3.0,4.0,5.0],[5.0,4.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0],[6.0,5.0,5.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0],[7.0,6.0,5.0,5.0,5.0,4.0,3.0,2.0,1.0,2.0],[8.0,7.0,6.0,6.0,6.0,5.0,4.0,3.0,2.0,1.0],[9.0,8.0,7.0,7.0,7.0,6.0,5.0,4.0,3.0,2.0]],"row_label":"x index","col_label":"y index","path":[[8,8],[9,9]]},"value":0.2,"value_label":"distance"},{"phase":2,"caption":"Follow the chosen predecessor decisions","panel":{"kind":"matrix","title":"Accumulated edit costs","z":[[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0],[1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],[2.0,1.0,1.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0],[3.0,2.0,2.0,2.0,1.0,2.0,3.0,4.0,5.0,6.0],[4.0,3.0,3.0,3.0,2.0,1.0,2.0,3.0,4.0,5.0],[5.0,4.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0],[6.0,5.0,5.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0],[7.0,6.0,5.0,5.0,5.0,4.0,3.0,2.0,1.0,2.0],[8.0,7.0,6.0,6.0,6.0,5.0,4.0,3.0,2.0,1.0],[9.0,8.0,7.0,7.0,7.0,6.0,5.0,4.0,3.0,2.0]],"row_label":"x index","col_label":"y index","path":[[6,7],[7,8],[8,8],[9,9]]},"value":0.2,"value_label":"distance"},{"phase":2,"caption":"Follow the chosen predecessor decisions","panel":{"kind":"matrix","title":"Accumulated edit costs","z":[[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0],[1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],[2.0,1.0,1.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0],[3.0,2.0,2.0,2.0,1.0,2.0,3.0,4.0,5.0,6.0],[4.0,3.0,3.0,3.0,2.0,1.0,2.0,3.0,4.0,5.0],[5.0,4.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0],[6.0,5.0,5.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0],[7.0,6.0,5.0,5.0,5.0,4.0,3.0,2.0,1.0,2.0],[8.0,7.0,6.0,6.0,6.0,5.0,4.0,3.0,2.0,1.0],[9.0,8.0,7.0,7.0,7.0,6.0,5.0,4.0,3.0,2.0]],"row_label":"x index","col_label":"y index","path":[[4,5],[5,6],[6,7],[7,8],[8,8],[9,9]]},"value":0.2,"value_label":"distance"},{"phase":2,"caption":"Follow the chosen predecessor decisions","panel":{"kind":"matrix","title":"Accumulated edit costs","z":[[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0],[1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],[2.0,1.0,1.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0],[3.0,2.0,2.0,2.0,1.0,2.0,3.0,4.0,5.0,6.0],[4.0,3.0,3.0,3.0,2.0,1.0,2.0,3.0,4.0,5.0],[5.0,4.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0],[6.0,5.0,5.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0],[7.0,6.0,5.0,5.0,5.0,4.0,3.0,2.0,1.0,2.0],[8.0,7.0,6.0,6.0,6.0,5.0,4.0,3.0,2.0,1.0],[9.0,8.0,7.0,7.0,7.0,6.0,5.0,4.0,3.0,2.0]],"row_label":"x index","col_label":"y index","path":[[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,8],[9,9]]},"value":0.2,"value_label":"distance"},{"phase":2,"caption":"Follow the chosen predecessor decisions","panel":{"kind":"matrix","title":"Accumulated edit costs","z":[[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0],[1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],[2.0,1.0,1.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0],[3.0,2.0,2.0,2.0,1.0,2.0,3.0,4.0,5.0,6.0],[4.0,3.0,3.0,3.0,2.0,1.0,2.0,3.0,4.0,5.0],[5.0,4.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0],[6.0,5.0,5.0,4.0,4.0,3.0,2.0,1.0,2.0,3.0],[7.0,6.0,5.0,5.0,5.0,4.0,3.0,2.0,1.0,2.0],[8.0,7.0,6.0,6.0,6.0,5.0,4.0,3.0,2.0,1.0],[9.0,8.0,7.0,7.0,7.0,6.0,5.0,4.0,3.0,2.0]],"row_label":"x index","col_label":"y index","path":[[0,1],[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,8],[9,9]]},"value":0.2,"value_label":"distance"},{"phase":3,"caption":"Inspect the selected correspondences and final score","panel":{"kind":"alignment","title":"Chosen pairs (gaps remain unlinked)","a":[0.2,0.4,1.1,2.4,3.2,2.5,1.2,0.3,-0.4,-0.1],"b":[0.1,0.3,0.5,1.2,2.6,3.1,2.3,1.1,0.2,-0.3],"pairs":[[0,1],[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[9,9]]},"value":0.2,"value_label":"distance"}],"checks":{"api":"echotime.similarity_methods.edr_distance","expected":0.2,"observed":0.2,"tolerance":1e-12},"animation_steps_en":["Assign substitution cost zero inside tolerance, one outside.","Compare substitution with unit-cost insertion and deletion.","Trace the cheapest edit sequence through the prefix table.","Divide the edit cost by the longer sequence length."],"echotime_status":"Implemented in EchoTime","echotime_api":"edr_distance"}
