Skip to content

Instantly share code, notes, and snippets.

@pukpr
Created December 8, 2023 17:14
Show Gist options
  • Save pukpr/fcc9ba38c5f92bde0b53dc95c44ff7dc to your computer and use it in GitHub Desktop.
Save pukpr/fcc9ba38c5f92bde0b53dc95c44ff7dc to your computer and use it in GitHub Desktop.
Dynamic Time Warping Distance
function DTW_Distance(X, Y: in Data_Pairs; Window_Size: Positive) return Long_Float is
N : Positive := X'Length;
type Real_Array is array(X'First - Window_Size .. X'Last + Window_Size) of Long_Float;
DTW_Current, DTW_Previous : Real_Array := (others => Long_Float'Last);
begin
DTW_Previous(X'First) := 0.0;
for I in X'First .. X'Last loop
DTW_Current(X'First) := Long_Float'Last; -- Reset current row
for J in Integer'Max(X'First, I - Window_Size) .. Integer'Min(X'Last, I + Window_Size) loop
declare
Cost : Long_Float := Abs(X(I).Value - Y(J).Value);
Min_Cost : Long_Float;
J_Previous : Integer := Integer'Max(J - 1, Y'First);
begin
-- Compute minimum cost considering the DTW constraint
Min_Cost := Long_Float'Min( Long_Float'Min(
DTW_Previous(J_Previous),
DTW_Current(J_Previous)),
(if J > Y'First then DTW_Previous(J) else Long_Float'Last)
);
DTW_Current(J) := Cost + Min_Cost;
end;
end loop;
-- Swap the rows
DTW_Previous := DTW_Current;
end loop;
return 1.0/DTW_Current(N);
end DTW_Distance;
@pukpr
Copy link
Author

pukpr commented Mar 31, 2024

QBO 30

Tried to align more with the 18.6 modulation, removing the strong 4.4y and replacing it with interference of Draconic+ and Anomalistic, leading to the beat of 4.53 = 1/(1/8.85+12/18.6)

   0.00191058407 :offset:
  -0.00005634248 :bg:
   5.06137960862 :impA:
  -1.23265062772 :impB:
  -0.23741935956 :impC:
  -7.64535383712:delA:
   0.40050301578:delB:
   4.75357076113:asym:
  35.64331450367:ann1:
  -0.72755501152:ann2:
   8.80217676737:sem1:
  -1.73442119281:sem2:
   0.00000454052:year:
  -0.28159791283:IR:
  -0.00030182759 :mA:
  -0.05912221089 :mP:
  -0.00202946592 :shiftT:
   6.72040384889 :init:
---- Tidal ----
   9.10846048884,    0.00000000000,   -0.00812992487,  1, -100,  2.78389545156867E-03
  27.32166155400,   -1.22088284184,    1.27865879184,  2, -580560,  2.10330076241761E-04
  27.09267692660,    0.00000000000,  454.59474108018,  3, -100,  2.55834714402693E-03
   7.08840416574,    0.00000000000,   -0.00019825799,  4, -100,  5.92982459268319E-03
   6.85248390316,    0.00000000000,   -0.86639053803,  5, -100,  4.02026635670852E-03
  13.60611040750,   -0.37048132162,   -1.37402123888,  6, -3664,  1.03948495827232E-02
  13.66083077700,    0.04575397270,    0.00000000000,  7, -84,  2.82848035633829E-01
3396.73824406533,   -0.42382328369,    5.89709658289,  8, -48114,  8.82716385230237E-04
   9.12068919638,    0.00000000000,    0.12071268500,  9, -100,  3.49821517280576E-02
  13.77727494300,    0.35475665288,   -5.85713651516,  10,  2482,  1.37399354501661E-02
6793.47648813065,    0.57351348836,   -0.09657611037,  11,  70733,  8.09672470116974E-04
  27.55454988600,   -0.61433141299,  -20.08653125657,  12, -817,  8.56399014837518E-02
  27.66676714572,    0.25646421046,   -1.72998780806,  13,  3440,  7.24466137063528E-03
  27.44323926226,    0.02752646161,    0.71393166993,  14,  510,  4.51534497995516E-03
1616.30271425126,   -0.29380825214,    3.64477936767,  15, -20504,  1.43996737104650E-03
   6.85940288609,    0.00000000000,   -0.00604745373,  16, -100,  1.48743844613416E-02
   7.09580802667,    0.00000000000,    3.45305338330,  17, -100,  1.71069181044158E-02
   9.55688270553,    0.00000000000,   -7.23956539839,  18, -100,  1.53930725197578E-02
   9.13295078376,    0.00000000000,   -0.35205379817,  19, -100,  8.56344204085288E-02
2190.35004466729,   -0.23078845442,   -2.85767109080,  20, -33013,  7.01214760698434E-04
  27.21222081500,   -4.33922309733,    2.19899135520,  21, -276223,  1.57148430824415E-03
   9.18484996200,    0.00000000000,   -0.23867948870,  22, -100,  2.29977081732398E-03
  14.76531557694,    0.55207325997,   -5.68365616039,  23,  2097,  2.51325572677795E-02
  27.10365333842,    1.36521656804,   -1.65429330187,  24,  49076,  2.77619425635132E-03
   9.54345722280,    0.00000000000,    0.95503233255,  25, -100,  6.39816026346445E-03
  13.63341568476,   -0.18546683584,   -5.24724492355,  26, -243,  1.29658153799553E-01
  26.98505934729,    0.00000000000,    8.48630325169,  27, -100,  3.26005930241243E-03
  13.69115772864,    0.15676924413,    6.35343172340,  28,  5365,  2.86860486147658E-03
  13.66362090133,    0.16289096080,   -0.00000000000,  29,  313,  3.94320500288279E-02
1656.31999626209,    0.36743682898,    1.41812060331,  30,  23970,  1.52652022906254E-03
  13.71880577217,    0.50088853111,   -2.33218281456,  31,  50059,  9.98605329211078E-04
3232.60542850251,    0.48901741859,    1.62842769180,  32,  56024,  8.71322830450230E-04
---- LTE ----
   0.00000000000 :trend:
   0.00000000000 :accel:
   4.96417997234 :K0:
 -73.71751403305 :level:
  -0.04815839380,  135.41546583742,    1.98482945671 1
  -0.09631678759,   79.39811594133,    1.47202722540 2
  -1.15580145109,   53.83149196894,    1.18565425257 24
  -0.19263357518,   79.11333489927,   -2.48740293672 4
  -0.24079196898,   49.13399847234,   -2.37388636123 5
  -0.62605911934,   72.67241417576,    2.44902183071 13

CC 0.7694682017 0.8869879290 6 1
-0.04231616902:dLOD:
PS C:\Users\pp\github\pukpr\GeoEnergyMath\qbo> notepad enso_opt.exe.resp
PS C:\Users\pp\github\pukpr\GeoEnergyMath\qbo> ..\io\backup qbo30dtw9nonlin1bCCslope1965-1980c-modulate2_tropphase1-wow3b-harmmHighccDRACPPwow.5gwow3-4pt53align18pt6i

image

Note that the 18.6 year modulation overlays better.
image

list

4.000000
-0.142618 w_A
2.30E+00
1.14E+00 w_D
9.04E-01
3.05E-01 w_T
9.22E-03
4.10E-02 w_A2
1.29E+00
3.17E-01 w_DD
-6.86E-02
3.66E-01 w_N
-5.42E-02
2.08E-01 w_N2
-9.36E-02
7.38E-01 w_P
-5.14E-02
2.61E-01 w_P2
-1.18E-01
6.25E-01 w_6
5.71E-02
1.99E-01 w_453
-4.95E-02
3.19E-01 w_d2
1.14E+00
6.67E-01 w_t2
-5.22E-01
-5.98E-02 w_a6 18.6 mod of w_a
-8.29E-01

=+$F$2*(1+$F$3SIN(w_at+$F$4)+$F$29SIN(w_a6t+$F$30)+$F$9SIN(w_a2t+$F$10))(1+$F$5COS(w_dt+$F$6)+$F$7COS(w_tt+$F$8)+$F$11COS(w_ddt+$F$12))-$F$2 +$F$13COS(w_Nt+$F$14)+$F$15COS(w_N2t+$F$16)+$F$17COS(w_pt+$F$18)+$F$19COS(w_p2t+$F$20)+$F$21COS(w_6t+$F$22)+$F$23COS(w_453t+$F$24)+$F$25COS(w_d2t+$F$26) +$F$27COS(w_t2*t+$F$28)

@pukpr
Copy link
Author

pukpr commented Mar 31, 2024

reconstructed QBO driving from above

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment