{"id":"bag_of_patterns_distance","title":"Bag-of-patterns cosine distance","family":"feature-based","definition":"reference","intro_en":"Slide an eight-sample window, normalize each window, encode it as a four-letter SAX word and count the words. Consecutive duplicate words are suppressed in this example. The resulting bag is compared by cosine, so local motifs contribute through their frequencies while their global order is discarded.","intro_zh":"滑动八点窗口，对每个窗口单独标准化，编码为四字母 SAX 单词并计数。本例抑制连续重复单词，再用余弦比较词袋。局部模式通过出现频率参与比较，其全局顺序被舍弃。","steps_en":["Slide a length-eight window, normalize it, then encode four PAA means with the shared SAX alphabet.","Suppress consecutive duplicate words and count both series in one shared vocabulary.","Accumulate matching word-count products divided by both vector norms.","Subtract the completed cosine similarity from one."],"steps_zh":["滑动八点窗口并标准化，再用共享 SAX 字母表编码四个 PAA 均值。","抑制连续重复词，在一个共享词表中对两条序列计数。","累加对应词频的乘积，并除以两个向量的范数乘积。","用一减去完整的余弦相似度。"],"formula":"d = 1 - cosine(counts(SAX_windows(x)), counts(SAX_windows(y)))","caveats_en":["Window length, word length, alphabet and numerosity reduction define the comparison; the original BoP representation does not mandate this exact cosine adapter.","Global motif order and absolute window level/scale are discarded; a similar bag need not imply aligned events.","A zero count vector needs an explicit policy. This example has nonempty bags."],"caveats_zh":["窗口长度、词长、字母表与重复抑制规则共同定义比较；原 BoP 表示并未要求必须使用本例余弦适配器。","全局模式顺序和窗口的绝对水平、尺度被舍弃；词袋相似并不意味着事件对齐。","零计数向量需要明确处理规则，本例两个词袋均非空。"],"sources":[{"label":"Lin, Khade and Li (2012), bag-of-patterns representation","url":"https://link.springer.com/article/10.1007/s10844-012-0196-5"},{"label":"Lin et al. (2007), Experiencing SAX, author copy","url":"https://www.cs.ucr.edu/~stelo/papers/DMKD07b.pdf"},{"label":"Exact illustrative inputs and encoder definitions","url":"https://github.com/ZipengWu365/EchoTime/blob/main/tools/method_animation_data/feature_model_embedding.py"}],"x":[0.0,0.8769216919004693,0.8094744111674236,0.7863961030678929,0.3905255888325767,-0.5769216919004693,-0.6000000000000001,-0.09587051423531628,0.2094744111674235,1.0863961030678926,1.5905255888325764,0.9958705142353173,0.6000000000000002,0.20412948576468337,-0.39052558883257615,0.11360389693210537],"y":[-0.2003300858899106,0.185,0.5703300858899106,1.005,1.0003300858899107,0.3250000000000002,-0.35033008588991066,-0.3550000000000001,0.07966991411008931,0.46499999999999997,0.8503300858899105,1.2849999999999995,1.2803300858899114,0.6050000000000002,-0.07033008588991083,-0.07500000000000043],"parameters":{"window":8,"stride":1,"word_length":4,"alphabet_size":4,"local_z_normalization":true,"numerosity_reduction":"consecutive exact duplicate words","vocabulary":["aacd","abdc","abdd","acdb","adca","bacd","bdda","cabd","cdba","daac","dbac","dcab"],"comparison":"one_minus_cosine"},"result":{"label":"distance","value":0.5454545454545454,"detail":"Explicit BoP + cosine composition; shared vocabulary."},"frames":[{"phase":0,"caption":"Window 1: SAX words cdba / bdda; skip consecutive duplicates.","panel":{"kind":"lines","title":"Locally normalized length-eight windows","a":[-0.35002859581639745,1.1938518452755613,1.075106307914163,1.0344753726579694,0.3375183355839122,-1.3657385781256388,-1.4063695133818324,-0.5188151741077376],"a_label":"x window","b":[-0.907726877284732,-0.16798021981390343,0.5717664376569251,1.4062344115849634,1.3972692321709652,0.1007881318883425,-1.195692968394281,-1.2046581478082794],"b_label":"y window"},"input_highlight":[0,1,2,3,4,5,6,7]},{"phase":0,"caption":"Window 2: SAX words dcab / cdba; skip consecutive duplicates.","panel":{"kind":"lines","title":"Locally normalized length-eight windows","a":[1.1578679905797857,1.0380759229392977,0.997086898402798,0.2939874271899088,-1.4242806606056269,-1.465269685142127,-0.5698931361999687,-0.02757475716406733],"a_label":"x window","b":[-0.24657914686607108,0.5290483130569008,1.4039914688904862,1.394591440831681,0.035225592409439094,-1.3241402560128035,-1.333540284071609,-0.4585971282380235],"b_label":"y window"},"input_highlight":[1,2,3,4,5,6,7,8]},{"phase":0,"caption":"Window 4: SAX words cabd / daac; skip consecutive duplicates.","panel":{"kind":"lines","title":"Locally normalized length-eight windows","a":[0.600109198412441,0.05720203312479084,-1.2695804421060117,-1.301230636751485,-0.6098542896570074,-0.19109628186350466,1.01153703587315,1.7029133829676275],"a_label":"x window","b":[1.2046581478082792,1.1956929683942812,-0.10078813188834165,-1.397269232170965,-1.4062344115849637,-0.5717664376569251,0.16798021981390354,0.907726877284732],"b_label":"y window"},"input_highlight":[3,4,5,6,7,8,9,10]},{"phase":0,"caption":"Window 6: SAX words abdc / aacd; skip consecutive duplicates.","panel":{"kind":"lines","title":"Locally normalized length-eight windows","a":[-1.3012377727258455,-1.3319403411954511,-0.6612642245804736,-0.25504408753260877,0.9115816534853811,1.5822577701003588,0.7911495976606294,0.26449740478801004],"a_label":"x window","b":[-0.20042836612779935,-1.3053696372450354,-1.3130103168780345,-0.6018251683882695,0.028632623732542738,0.6590904158533548,1.370275564343119,1.3626348847101222],"b_label":"y window"},"input_highlight":[5,6,7,8,9,10,11,12]},{"phase":0,"caption":"Window 8: SAX words adca / acdb; skip consecutive duplicates.","panel":{"kind":"lines","title":"Locally normalized length-eight windows","a":[-0.9967417615572095,-0.5065428684702531,0.9012619022380602,1.7105883240490556,0.7559326704414502,0.1204045455578804,-0.515123579325689,-1.4697792329332948],"a_label":"x window","b":[-1.5332255842191969,-0.7693894432404578,-0.09225712684413503,0.5848751895521875,1.348711330530926,1.340504990370819,0.15376187807355884,-1.032981234223701],"b_label":"y window"},"input_highlight":[7,8,9,10,11,12,13,14]},{"phase":0,"caption":"Window 9: SAX words cdba / bdda; skip consecutive duplicates.","panel":{"kind":"lines","title":"Locally normalized length-eight windows","a":[-0.5692874699871925,0.8916609708819709,1.7315389132646322,0.7408456596800163,0.08132678142674242,-0.578192096826531,-1.5688853504111475,-0.7290074080284902],"a_label":"x window","b":[-0.907726877284732,-0.1679802198139035,0.5717664376569248,1.4062344115849623,1.3972692321709663,0.10078813188834249,-1.195692968394281,-1.2046581478082798],"b_label":"y window"},"input_highlight":[8,9,10,11,12,13,14,15]},{"phase":1,"caption":"Expose 1 of 12 coordinates; each has the same meaning in x and y.","panel":{"kind":"bars","title":"SAX-word count vectors","a":[0.0],"a_label":"x features","b":[1.0],"b_label":"y features","labels":["aacd"],"marker":0}},{"phase":1,"caption":"Expose 3 of 12 coordinates; each has the same meaning in x and y.","panel":{"kind":"bars","title":"SAX-word count vectors","a":[0.0,1.0,0.0],"a_label":"x features","b":[1.0,0.0,1.0],"b_label":"y features","labels":["aacd","abdc","abdd"],"marker":2}},{"phase":1,"caption":"Expose 5 of 12 coordinates; each has the same meaning in x and y.","panel":{"kind":"bars","title":"SAX-word count vectors","a":[0.0,1.0,0.0,1.0,1.0],"a_label":"x features","b":[1.0,0.0,1.0,1.0,0.0],"b_label":"y features","labels":["aacd","abdc","abdd","acdb","adca"],"marker":4}},{"phase":1,"caption":"Expose 7 of 12 coordinates; each has the same meaning in x and y.","panel":{"kind":"bars","title":"SAX-word count vectors","a":[0.0,1.0,0.0,1.0,1.0,1.0,0.0],"a_label":"x features","b":[1.0,0.0,1.0,1.0,0.0,0.0,2.0],"b_label":"y features","labels":["aacd","abdc","abdd","acdb","adca","bacd","bdda"],"marker":6}},{"phase":1,"caption":"Expose 9 of 12 coordinates; each has the same meaning in x and y.","panel":{"kind":"bars","title":"SAX-word count vectors","a":[0.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,2.0],"a_label":"x features","b":[1.0,0.0,1.0,1.0,0.0,0.0,2.0,1.0,1.0],"b_label":"y features","labels":["aacd","abdc","abdd","acdb","adca","bacd","bdda","cabd","cdba"],"marker":8}},{"phase":1,"caption":"Expose 12 of 12 coordinates; each has the same meaning in x and y.","panel":{"kind":"bars","title":"SAX-word count vectors","a":[0.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,2.0,0.0,1.0,1.0],"a_label":"x features","b":[1.0,0.0,1.0,1.0,0.0,0.0,2.0,1.0,1.0,1.0,0.0,1.0],"b_label":"y features","labels":["aacd","abdc","abdd","acdb","adca","bacd","bdda","cabd","cdba","daac","dbac","dcab"],"marker":11}},{"phase":2,"caption":"Sum normalized dot-product contributions from the displayed coordinates.","panel":{"kind":"bars","title":"Dot-product terms / fixed full-vector norms","a":[0.0],"a_label":"contributions","labels":["aacd"],"marker":0},"value":0.0,"value_label":"partial dot sum"},{"phase":2,"caption":"Sum normalized dot-product contributions from the displayed coordinates.","panel":{"kind":"bars","title":"Dot-product terms / fixed full-vector norms","a":[0.0,0.0,0.0],"a_label":"contributions","labels":["aacd","abdc","abdd"],"marker":2},"value":0.0,"value_label":"partial dot sum"},{"phase":2,"caption":"Sum normalized dot-product contributions from the displayed coordinates.","panel":{"kind":"bars","title":"Dot-product terms / fixed full-vector norms","a":[0.0,0.0,0.0,0.09090909090909091,0.0],"a_label":"contributions","labels":["aacd","abdc","abdd","acdb","adca"],"marker":4},"value":0.09090909090909091,"value_label":"partial dot sum"},{"phase":2,"caption":"Sum normalized dot-product contributions from the displayed coordinates.","panel":{"kind":"bars","title":"Dot-product terms / fixed full-vector norms","a":[0.0,0.0,0.0,0.09090909090909091,0.0,0.0,0.0],"a_label":"contributions","labels":["aacd","abdc","abdd","acdb","adca","bacd","bdda"],"marker":6},"value":0.09090909090909091,"value_label":"partial dot sum"},{"phase":2,"caption":"Sum normalized dot-product contributions from the displayed coordinates.","panel":{"kind":"bars","title":"Dot-product terms / fixed full-vector norms","a":[0.0,0.0,0.0,0.09090909090909091,0.0,0.0,0.0,0.09090909090909091,0.18181818181818182],"a_label":"contributions","labels":["aacd","abdc","abdd","acdb","adca","bacd","bdda","cabd","cdba"],"marker":8},"value":0.36363636363636365,"value_label":"partial dot sum"},{"phase":2,"caption":"Sum normalized dot-product contributions from the displayed coordinates.","panel":{"kind":"bars","title":"Dot-product terms / fixed full-vector norms","a":[0.0,0.0,0.0,0.09090909090909091,0.0,0.0,0.0,0.09090909090909091,0.18181818181818182,0.0,0.0,0.09090909090909091],"a_label":"contributions","labels":["aacd","abdc","abdd","acdb","adca","bacd","bdda","cabd","cdba","daac","dbac","dcab"],"marker":11},"value":0.4545454545454546,"value_label":"partial dot sum"},{"phase":3,"caption":"Use one minus the completed cosine score.","panel":{"kind":"bars","title":"Dot-product terms / fixed full-vector norms","a":[0.0,0.0,0.0,0.09090909090909091,0.0,0.0,0.0,0.09090909090909091,0.18181818181818182,0.0,0.0,0.09090909090909091],"a_label":"contributions","labels":["aacd","abdc","abdd","acdb","adca","bacd","bdda","cabd","cdba","daac","dbac","dcab"],"marker":0},"value":0.5454545454545454,"value_label":"final distance"},{"phase":3,"caption":"Use one minus the completed cosine score.","panel":{"kind":"bars","title":"Dot-product terms / fixed full-vector norms","a":[0.0,0.0,0.0,0.09090909090909091,0.0,0.0,0.0,0.09090909090909091,0.18181818181818182,0.0,0.0,0.09090909090909091],"a_label":"contributions","labels":["aacd","abdc","abdd","acdb","adca","bacd","bdda","cabd","cdba","daac","dbac","dcab"],"marker":4},"value":0.5454545454545454,"value_label":"final distance"},{"phase":3,"caption":"Use one minus the completed cosine score.","panel":{"kind":"bars","title":"Dot-product terms / fixed full-vector norms","a":[0.0,0.0,0.0,0.09090909090909091,0.0,0.0,0.0,0.09090909090909091,0.18181818181818182,0.0,0.0,0.09090909090909091],"a_label":"contributions","labels":["aacd","abdc","abdd","acdb","adca","bacd","bdda","cabd","cdba","daac","dbac","dcab"],"marker":8},"value":0.5454545454545454,"value_label":"final distance"},{"phase":3,"caption":"Use one minus the completed cosine score.","panel":{"kind":"bars","title":"Dot-product terms / fixed full-vector norms","a":[0.0,0.0,0.0,0.09090909090909091,0.0,0.0,0.0,0.09090909090909091,0.18181818181818182,0.0,0.0,0.09090909090909091],"a_label":"contributions","labels":["aacd","abdc","abdd","acdb","adca","bacd","bdda","cabd","cdba","daac","dbac","dcab"],"marker":11},"value":0.5454545454545454,"value_label":"final distance"}],"animation_steps_en":["Slide, normalize and SAX-encode each length-eight window.","Suppress consecutive repeats and count a shared word vocabulary.","Accumulate matching word-count products, divided by vector norms.","Subtract the completed cosine similarity from one."],"echotime_status":"Possible addition","echotime_api":""}
