p2: calculate/save covariance

This commit is contained in:
leo 2023-02-26 17:39:39 +01:00
parent 102454e6e1
commit 129f33c9a6
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
4 changed files with 16 additions and 5 deletions

@ -82,7 +82,8 @@ func readFile(s *string) ([][]float64, error) {
func saveStuff(
meanU, meanY,
varianceU, varianceY float64,
varianceU, varianceY,
cov float64,
autocorrelationU, autocorrelationY,
mutCorrelationUY, mutCorrelationYU []float64,
) error {
@ -91,6 +92,7 @@ func saveStuff(
"mean_y": meanY,
"variance_u": varianceU,
"variance_y": varianceY,
"covariance_uy": cov,
}
sFnames := map[string][]float64{
"autocorrelation_u": autocorrelationU,

@ -0,0 +1 @@
0.0158513302983771878218455242404161253944039344787597656250000000

@ -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,
)

@ -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)
}