diff --git a/p2/data.go b/p2/data.go index 476ae09..d211f1d 100644 --- a/p2/data.go +++ b/p2/data.go @@ -82,15 +82,17 @@ func readFile(s *string) ([][]float64, error) { func saveStuff( meanU, meanY, - varianceU, varianceY float64, + varianceU, varianceY, + cov float64, autocorrelationU, autocorrelationY, mutCorrelationUY, mutCorrelationYU []float64, ) error { fFnames := map[string]float64{ - "mean_u": meanU, - "mean_y": meanY, - "variance_u": varianceU, - "variance_y": varianceY, + "mean_u": meanU, + "mean_y": meanY, + "variance_u": varianceU, + "variance_y": varianceY, + "covariance_uy": cov, } sFnames := map[string][]float64{ "autocorrelation_u": autocorrelationU, diff --git a/p2/data/covariance_uy.txt b/p2/data/covariance_uy.txt new file mode 100644 index 0000000..93c1d21 --- /dev/null +++ b/p2/data/covariance_uy.txt @@ -0,0 +1 @@ +0.0158513302983771878218455242404161253944039344787597656250000000 \ No newline at end of file diff --git a/p2/run.go b/p2/run.go index 5c5e965..321675f 100644 --- a/p2/run.go +++ b/p2/run.go @@ -40,6 +40,8 @@ func run() error { return err } + cov := stats.Covariance(data[u], data[y]) + log.Printf("len(data): %d", len(data[u])) log.Printf("means - u: %v, y: %v", meanU, meanY) @@ -51,10 +53,12 @@ func run() error { log.Printf("autocorrelationY: %v", autocorrelationY) log.Printf("mutual correlation U,Y: %v", mutCorrelationUY) log.Printf("mutual correlation Y,U: %v", mutCorrelationYU) + log.Printf("covariance U,Y: %v", cov) err = saveStuff( meanU, meanY, varianceU, varianceY, + cov, autocorrelationU, autocorrelationY, mutCorrelationUY, mutCorrelationYU, ) diff --git a/p2/stats/stats.go b/p2/stats/stats.go index 1911764..149576b 100644 --- a/p2/stats/stats.go +++ b/p2/stats/stats.go @@ -89,3 +89,7 @@ func MutCorrelate(f1, f2 []float64, maxShift float64) ([]float64, error) { return v, nil } + +func Covariance(f1, f2 []float64) float64 { + return stat.Covariance(f1, f2, nil) +}