From 8c99960c357b3f58cf2c4507272fbb792599e156 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 27 Feb 2023 01:36:36 +0100 Subject: [PATCH] p2: make autocorrelation always positive --- p2/data/autocorrelation_u.csv | 34 +++++++++++++++++----------------- p2/data/autocorrelation_y.csv | 20 ++++++++++---------- p2/stats/stats.go | 4 ++-- p2/stats/stats_test.go | 4 ++-- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/p2/data/autocorrelation_u.csv b/p2/data/autocorrelation_u.csv index 7b6d3b0..1a58dca 100644 --- a/p2/data/autocorrelation_u.csv +++ b/p2/data/autocorrelation_u.csv @@ -1,26 +1,26 @@ 1.1590961414640938986764240326010622084140777587890625000000000000 --0.1490519384512796197128636777051724493503570556640625000000000000 +0.1490519384512796197128636777051724493503570556640625000000000000 0.0108848888890002853946370464655046816915273666381835937500000000 --0.0278269312937904772509156714477285277098417282104492187500000000 +0.0278269312937904772509156714477285277098417282104492187500000000 0.0762959156750215583553398346339236013591289520263671875000000000 --0.0307672964711055985098653309250948950648307800292968750000000000 --0.0616922706980928894915372495688643539324402809143066406250000000 --0.0042398197858100903148703686440512683475390076637268066406250000 +0.0307672964711055985098653309250948950648307800292968750000000000 +0.0616922706980928894915372495688643539324402809143066406250000000 +0.0042398197858100903148703686440512683475390076637268066406250000 0.0659566004815934775473706963566655758768320083618164062500000000 --0.0303218570133077236494756334650446660816669464111328125000000000 --0.0183346730583563329031182576045466703362762928009033203125000000 --0.0322607868390417662496361117518972605466842651367187500000000000 --0.0861106068508480093637302843490033410489559173583984375000000000 +0.0303218570133077236494756334650446660816669464111328125000000000 +0.0183346730583563329031182576045466703362762928009033203125000000 +0.0322607868390417662496361117518972605466842651367187500000000000 +0.0861106068508480093637302843490033410489559173583984375000000000 0.0889939616523050675001016429632727522403001785278320312500000000 --0.1216997668579310326597564539952145423740148544311523437500000000 +0.1216997668579310326597564539952145423740148544311523437500000000 0.0831315802089621080916970186081016436219215393066406250000000000 --0.0510906785058726845005772077001893194392323493957519531250000000 --0.0417323855971289472965857214603602187708020210266113281250000000 +0.0510906785058726845005772077001893194392323493957519531250000000 +0.0417323855971289472965857214603602187708020210266113281250000000 0.0338397983154378259595951305982453050091862678527832031250000000 --0.1131106178940711470826130380373797379434108734130859375000000000 +0.1131106178940711470826130380373797379434108734130859375000000000 0.0632283168008925949843401781436114106327295303344726562500000000 --0.0191174933650852495181649004507562494836747646331787109375000000 --0.0307279811112075168511026390660845208913087844848632812500000000 +0.0191174933650852495181649004507562494836747646331787109375000000 +0.0307279811112075168511026390660845208913087844848632812500000000 0.0593017282424278813213192051989608444273471832275390625000000000 --0.0685043020107265893114956156750849913805723190307617187500000000 --0.0467467808632735029594762465876556234434247016906738281250000000 +0.0685043020107265893114956156750849913805723190307617187500000000 +0.0467467808632735029594762465876556234434247016906738281250000000 diff --git a/p2/data/autocorrelation_y.csv b/p2/data/autocorrelation_y.csv index 589b791..7531107 100644 --- a/p2/data/autocorrelation_y.csv +++ b/p2/data/autocorrelation_y.csv @@ -1,12 +1,12 @@ 0.0247851861363328589138443902584185707382857799530029296875000000 0.0101597365212651533777910017875001358333975076675415039062500000 --0.0048916673698773316045218528813620650907978415489196777343750000 --0.0054237415652548014513567586902809125604107975959777832031250000 +0.0048916673698773316045218528813620650907978415489196777343750000 +0.0054237415652548014513567586902809125604107975959777832031250000 0.0008238030894209187084131773559647626825608313083648681640625000 0.0042388605435366259743812378246730077080428600311279296875000000 0.0016150316087213674280664843507793193566612899303436279296875000 --0.0004583168657113599738991971399570957146352156996726989746093750 --0.0004327734207589521058315296109242353850277140736579895019531250 +0.0004583168657113599738991971399570957146352156996726989746093750 +0.0004327734207589521058315296109242353850277140736579895019531250 0.0009200042244299674312410508569826106395339593291282653808593750 0.0019168656035581091087727223509773466503247618675231933593750000 0.0013538912127192088627469779282819217769429087638854980468750000 @@ -15,12 +15,12 @@ 0.0011426877227173335479365468003720707201864570379257202148437500 0.0011720300545479279269445171962615859229117631912231445312500000 0.0014998474895757723992367749232812457194086164236068725585937500 --0.0000440034019377805833152760006665715764029300771653652191162109 --0.0013574526282660156952658558893176632409449666738510131835937500 --0.0010881806286332530980115462782009672082494944334030151367187500 --0.0005801051347902472449594157843932862306246533989906311035156250 --0.0009795725105796386326939551025816399487666785717010498046875000 +0.0000440034019377805833152760006665715764029300771653652191162109 +0.0013574526282660156952658558893176632409449666738510131835937500 +0.0010881806286332530980115462782009672082494944334030151367187500 +0.0005801051347902472449594157843932862306246533989906311035156250 +0.0009795725105796386326939551025816399487666785717010498046875000 0.0000218475471446995081383889852899571337729867082089185714721680 0.0025448200120934670077910144669885994517244398593902587890625000 0.0024030272505739407908065263796970612020231783390045166015625000 --0.0007522352451961691107568119818438390211667865514755249023437500 +0.0007522352451961691107568119818438390211667865514755249023437500 diff --git a/p2/stats/stats.go b/p2/stats/stats.go index 5bd85e5..e14bbbb 100644 --- a/p2/stats/stats.go +++ b/p2/stats/stats.go @@ -33,7 +33,7 @@ func Autocorrelate(f []float64, maxShift float64) []float64 { r *= 1 / float64(fLen-currentShift) - v = append(v, r) + v = append(v, math.Abs(r)) currentShift++ } @@ -56,7 +56,7 @@ func AutocorrelateMP(f []float64, maxShift float64) []float64 { r *= math.Pow(float64(fLen-currentShift), -1) - v = append(v, r) + v = append(v, math.Abs(r)) currentShift++ } diff --git a/p2/stats/stats_test.go b/p2/stats/stats_test.go index 0ef0e03..e3ea929 100644 --- a/p2/stats/stats_test.go +++ b/p2/stats/stats_test.go @@ -13,13 +13,13 @@ func TestAutocorrelate(t *testing.T) { desc: "autocorrelate a 10-long slice", maxShift: .1, in: []float64{.4, .5, .23, 2.5, -3.6, .4, -0.12, 2.2, 0.02, 14.4}, - out: []float64{23.204770000000003, -1.0588888888888885}, + out: []float64{23.204770000000003, 1.0588888888888885}, }, { desc: "autocorrelate a 20-long slice", maxShift: .1, in: []float64{.4, .5, .23, 2.5, -3.6, .4, -0.12, 2.2, 0.02, 14.4, .4, .5, .23, 2.5, -3.6, .4, -0.12, 2.2, 0.02, 14.4}, - out: []float64{23.204770000000003, -0.6999999999999996, 4.234177777777778}, + out: []float64{23.204770000000003, 0.6999999999999996, 4.234177777777778}, }, }