{"id":"spectral_cosine_similarity","title":"Fourier-magnitude cosine similarity","family":"feature-based","definition":"reference","intro_en":"Project the series onto sine and cosine bases, combine the real and imaginary parts into magnitudes, and compare the resulting frequency bins. The example retains all nine nonnegative-frequency bins of a length-16 real transform, including the DC bin. Cosine compares vector direction and is defined here for nonzero feature vectors.","intro_zh":"把序列投影到正弦、余弦基上，将实部和虚部合成为幅值，再比较频率坐标。本例保留长度 16 实数变换的全部九个非负频率坐标，包括直流分量。 余弦比较向量方向，本例特征向量均非零。","steps_en":["Compute the unnormalized real FFT and retain the magnitude of each bin.","Collect the computed coordinates in the same fixed order for both inputs.","Normalize by both vector lengths and sum coordinate products to obtain cosine similarity.","Interpret the score in this representation, accounting for the information it discards."],"steps_zh":["计算未归一化的实数 FFT，保留各频率坐标的模。","把计算得到的坐标按同一个固定顺序组成两个向量。","用两个向量的长度归一化坐标乘积之和，得到余弦相似度。","结合表示所舍弃的信息，在该表示空间中解释分数。"],"animation_steps_en":["Take all nine real-FFT magnitudes, including the DC component.","Collect matching coordinates in the same vector order.","Normalize vector products to obtain cosine similarity.","Read the score in this feature space, with its stated information loss."],"formula":"s(x,y) = dot(phi(x),phi(y)) / (norm(phi(x))*norm(phi(y)))","caveats_en":["Magnitude discards phase; a circular shift changes Fourier phase while preserving these magnitudes.","The DC coordinate reflects the mean, and raw magnitudes depend on record length and amplitude. Matching sampling rates and frequency grids is required.","This example compares unweighted nonnegative-frequency rFFT magnitudes. Comparing a full FFT, or weighting interior rFFT magnitudes by sqrt(2), gives a different distance/cosine convention.","Cosine ignores positive rescaling of the entire feature vector; 1-cosine is generally not a metric, and zero vectors require an explicit policy."],"caveats_zh":["幅值表示舍弃相位；循环平移改变傅里叶相位，却保留这些幅值。","直流坐标反映均值，原始幅值依赖记录长度与振幅；比较时需要一致的采样率和频率网格。","本例比较未加权的非负频率 rFFT 幅值。比较完整 FFT 或将内部 rFFT 幅值乘 sqrt(2)，对应不同的距离与余弦约定。","余弦忽略整个特征向量的正比例缩放；1-cosine 通常不满足度量公理，零向量还需明确处理规则。"],"sources":[{"label":"NumPy: real-input discrete Fourier transform","url":"https://numpy.org/doc/stable/reference/generated/numpy.fft.rfft.html"},{"label":"Imported registry: named feature and comparison conventions","url":"https://github.com/ZipengWu365/EchoTime/blob/main/src/echotime/data/ts_similarity_package_v2_registry.csv"},{"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],"input_label":"Deterministic synthetic teaching signals, 16 samples each","parameters":{"fft":"rfft","normalization":"backward","n_bins":9,"include_DC":true,"comparison":"cosine"},"result":{"label":"similarity","value":0.9781787644030476,"detail":"Computed from the explicitly defined illustrative encoder; no learned weights."},"frames":[{"phase":0,"caption":"Bin 0: sum cos-weighted samples to obtain a Fourier component.","panel":{"kind":"lines","title":"Frequency k=0: cos-weighted samples","a":[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],"a_label":"x weighted","b":[-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],"b_label":"y weighted"},"value":5.999999999999998,"value_label":"x cos component"},{"phase":0,"caption":"Bin 1: sum cos-weighted samples to obtain a Fourier component.","panel":{"kind":"lines","title":"Frequency k=1: cos-weighted samples","a":[0.0,0.8101700027620122,0.5723848453334728,0.3009407599205522,2.3912795617447522e-17,0.22077837326234637,0.42426406871192857,0.08857280587334067,-0.2094744111674235,-1.0036991238244484,-1.1246714295142415,-0.38110314657875877,-1.1021821192326182e-16,0.07811697225934981,-0.27614329209038396,0.10495631518909389],"a_label":"x weighted","b":[-0.2003300858899106,0.17091771351458804,0.4032842712474619,0.38459684952691525,6.12525518887938e-17,-0.12437211551865422,0.24772077938642142,0.32797723404150686,-0.07966991411008931,-0.42960398261774835,-0.6012741699796953,-0.49174821058914087,-2.3519282123057037e-16,0.23152347658087952,-0.04973088065418826,-0.06929096493834688],"b_label":"y weighted"},"value":-0.39490725986315967,"value_label":"x cos component"},{"phase":0,"caption":"Bin 1: sum sin-weighted samples to obtain a Fourier component.","panel":{"kind":"lines","title":"Frequency k=1: sin-weighted samples","a":[-0.0,-0.33558340297187333,-0.5723848453334728,-0.7265352640710625,-0.3905255888325767,0.5330061430086261,0.4242640687119286,0.036688057450177045,-2.5653216713946175e-17,0.41574578963007885,1.1246714295142413,0.9200643851334994,0.6000000000000002,0.18859105388004502,-0.27614329209038413,0.043474329208028045],"a_label":"x weighted","b":[0.0,-0.07079643498754161,-0.40328427124746186,-0.9284989301738431,-1.0003300858899107,-0.3002608480661684,0.24772077938642148,0.13585261848960695,-9.756750530326542e-18,0.17794779604976668,0.6012741699796951,1.1871851992770026,1.2803300858899114,0.5589471171693285,-0.04973088065418828,-0.028701257427381943],"b_label":"y weighted"},"value":1.985332863237255,"value_label":"x sin component"},{"phase":0,"caption":"Bin 2: sum cos-weighted samples to obtain a Fourier component.","panel":{"kind":"lines","title":"Frequency k=2: cos-weighted samples","a":[0.0,0.6200772749124023,4.956601233139369e-17,-0.5560660171779821,-0.3905255888325767,0.407945240556438,1.102182119232618e-16,-0.06779069073163356,0.2094744111674235,0.7681980515339464,4.869580178314435e-16,-0.7041867937995262,-0.6000000000000002,-0.14434134362433035,1.673895693221324e-16,0.08033008588990923],"a_label":"x weighted","b":[-0.2003300858899106,0.1308147545195113,3.49226457071257e-17,-0.7106423150924801,-1.0003300858899107,-0.22980970388562813,6.435459274951446e-17,-0.2510229073212244,0.07966991411008931,0.3288046532517446,2.603385044759432e-16,-0.9086322138247122,-1.2803300858899114,-0.42779960261786115,3.0145330099093203e-17,-0.05303300858899129],"b_label":"y weighted"},"value":-0.37688537010592893,"value_label":"x cos component"},{"phase":0,"caption":"Bin 2: sum sin-weighted samples to obtain a Fourier component.","panel":{"kind":"lines","title":"Frequency k=2: sin-weighted samples","a":[-0.0,-0.6200772749124022,-0.8094744111674236,-0.5560660171779822,-4.7825591234895043e-17,-0.4079452405564379,-0.6000000000000001,-0.0677906907316336,5.130643342789235e-17,-0.768198051533946,-1.5905255888325764,-0.7041867937995279,-2.2043642384652363e-16,0.14434134362433051,-0.39052558883257615,0.08033008588990943],"a_label":"x weighted","b":[0.0,-0.13081475451951127,-0.5703300858899106,-0.7106423150924802,-1.225051037775876e-16,0.22980970388562805,-0.35033008588991066,-0.2510229073212245,1.9513501060653085e-17,-0.3288046532517445,-0.8503300858899105,-0.9086322138247143,-4.703856424611407e-16,0.42779960261786165,-0.07033008588991083,-0.05303300858899144],"b_label":"y weighted"},"value":-6.290118228030266,"value_label":"x sin component"},{"phase":0,"caption":"Bin 3: sum cos-weighted samples to obtain a Fourier component.","panel":{"kind":"lines","title":"Frequency k=3: cos-weighted samples","a":[0.0,0.3355834029718734,-0.5723848453334728,-0.7265352640710626,-7.173838685234256e-17,-0.533006143008626,-0.4242640687119287,0.036688057450177045,-0.2094744111674235,-0.4157457896300798,1.1246714295142397,0.9200643851334996,3.3065463576978547e-16,-0.18859105388004496,0.27614329209038396,0.043474329208027955],"a_label":"x weighted","b":[-0.2003300858899106,0.07079643498754162,-0.40328427124746186,-0.9284989301738432,-1.8375765566638138e-16,0.30026084806616826,-0.2477207793864215,0.13585261848960695,-0.07966991411008931,-0.1779477960497671,0.6012741699796943,1.187185199277003,7.055784636917111e-16,-0.5589471171693284,0.04973088065418826,-0.02870125742738188],"b_label":"y weighted"},"value":-0.3333766794344364,"value_label":"x cos component"},{"phase":1,"caption":"Expose 1 of 9 coordinates; each has the same meaning in x and y.","panel":{"kind":"bars","title":"Feature vectors","a":[6.0],"a_label":"x features","b":[6.599999999999999],"b_label":"y features","labels":["k0"],"marker":0}},{"phase":1,"caption":"Expose 2 of 9 coordinates; each has the same meaning in x and y.","panel":{"kind":"bars","title":"Feature vectors","a":[6.0,2.0242278334571107],"a_label":"x features","b":[6.599999999999999,1.4352326507352435],"b_label":"y features","labels":["k0","k1"],"marker":1}},{"phase":1,"caption":"Expose 4 of 9 coordinates; each has the same meaning in x and y.","panel":{"kind":"bars","title":"Feature vectors","a":[6.0,2.0242278334571107,6.301399043450471,0.6000621696783222],"a_label":"x features","b":[6.599999999999999,1.4352326507352435,5.759804570172509,0.5039866849563922],"b_label":"y features","labels":["k0","k1","k2","k3"],"marker":3}},{"phase":1,"caption":"Expose 5 of 9 coordinates; each has the same meaning in x and y.","panel":{"kind":"bars","title":"Feature vectors","a":[6.0,2.0242278334571107,6.301399043450471,0.6000621696783222,0.2962415532430881],"a_label":"x features","b":[6.599999999999999,1.4352326507352435,5.759804570172509,0.5039866849563922,1.1933147112141043],"b_label":"y features","labels":["k0","k1","k2","k3","k4"],"marker":4}},{"phase":1,"caption":"Expose 7 of 9 coordinates; each has the same meaning in x and y.","panel":{"kind":"bars","title":"Feature vectors","a":[6.0,2.0242278334571107,6.301399043450471,0.6000621696783222,0.2962415532430881,0.8692554262043765,1.2828696204609291],"a_label":"x features","b":[6.599999999999999,1.4352326507352435,5.759804570172509,0.5039866849563922,1.1933147112141043,0.3367531366836253,0.3030698160818712],"b_label":"y features","labels":["k0","k1","k2","k3","k4","k5","k6"],"marker":6}},{"phase":1,"caption":"Expose 9 of 9 coordinates; each has the same meaning in x and y.","panel":{"kind":"bars","title":"Feature vectors","a":[6.0,2.0242278334571107,6.301399043450471,0.6000621696783222,0.2962415532430881,0.8692554262043765,1.2828696204609291,0.848680332200665,0.7810511776651512],"a_label":"x features","b":[6.599999999999999,1.4352326507352435,5.759804570172509,0.5039866849563922,1.1933147112141043,0.3367531366836253,0.3030698160818712,0.28548552429832874,0.2799999999999985],"b_label":"y features","labels":["k0","k1","k2","k3","k4","k5","k6","k7","k8"],"marker":8}},{"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.4806029686140968],"a_label":"contributions","labels":["k0"],"marker":0},"value":0.4806029686140968,"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.4806029686140968,0.03525924114211731],"a_label":"contributions","labels":["k0","k1"],"marker":1},"value":0.5158622097562141,"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.4806029686140968,0.03525924114211731,0.44048993954128496,0.0036703423419969716],"a_label":"contributions","labels":["k0","k1","k2","k3"],"marker":3},"value":0.960022491639496,"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.4806029686140968,0.03525924114211731,0.44048993954128496,0.0036703423419969716,0.004290345171285917],"a_label":"contributions","labels":["k0","k1","k2","k3","k4"],"marker":4},"value":0.964312836810782,"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.4806029686140968,0.03525924114211731,0.44048993954128496,0.0036703423419969716,0.004290345171285917,0.0035526328164289045,0.004718635919110677],"a_label":"contributions","labels":["k0","k1","k2","k3","k4","k5","k6"],"marker":6},"value":0.9725841055463216,"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.4806029686140968,0.03525924114211731,0.44048993954128496,0.0036703423419969716,0.004290345171285917,0.0035526328164289045,0.004718635919110677,0.002940488551293915,0.002654170305432164],"a_label":"contributions","labels":["k0","k1","k2","k3","k4","k5","k6","k7","k8"],"marker":8},"value":0.9781787644030476,"value_label":"partial dot sum"},{"phase":3,"caption":"Read the completed comparison using every retained coordinate.","panel":{"kind":"bars","title":"Dot-product terms / fixed full-vector norms","a":[0.4806029686140968,0.03525924114211731,0.44048993954128496,0.0036703423419969716,0.004290345171285917,0.0035526328164289045,0.004718635919110677,0.002940488551293915,0.002654170305432164],"a_label":"contributions","labels":["k0","k1","k2","k3","k4","k5","k6","k7","k8"],"marker":0},"value":0.9781787644030476,"value_label":"final similarity"},{"phase":3,"caption":"Read the completed comparison using every retained coordinate.","panel":{"kind":"bars","title":"Dot-product terms / fixed full-vector norms","a":[0.4806029686140968,0.03525924114211731,0.44048993954128496,0.0036703423419969716,0.004290345171285917,0.0035526328164289045,0.004718635919110677,0.002940488551293915,0.002654170305432164],"a_label":"contributions","labels":["k0","k1","k2","k3","k4","k5","k6","k7","k8"],"marker":3},"value":0.9781787644030476,"value_label":"final similarity"},{"phase":3,"caption":"Read the completed comparison using every retained coordinate.","panel":{"kind":"bars","title":"Dot-product terms / fixed full-vector norms","a":[0.4806029686140968,0.03525924114211731,0.44048993954128496,0.0036703423419969716,0.004290345171285917,0.0035526328164289045,0.004718635919110677,0.002940488551293915,0.002654170305432164],"a_label":"contributions","labels":["k0","k1","k2","k3","k4","k5","k6","k7","k8"],"marker":6},"value":0.9781787644030476,"value_label":"final similarity"},{"phase":3,"caption":"Read the completed comparison using every retained coordinate.","panel":{"kind":"bars","title":"Dot-product terms / fixed full-vector norms","a":[0.4806029686140968,0.03525924114211731,0.44048993954128496,0.0036703423419969716,0.004290345171285917,0.0035526328164289045,0.004718635919110677,0.002940488551293915,0.002654170305432164],"a_label":"contributions","labels":["k0","k1","k2","k3","k4","k5","k6","k7","k8"],"marker":8},"value":0.9781787644030476,"value_label":"final similarity"}],"echotime_status":"Conceptually covered","echotime_api":"spectral_similarity"}
