2023-02-24 23:50:13 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"git.dotya.ml/wanderer/ak9im/p2/stats"
|
|
|
|
)
|
|
|
|
|
|
|
|
var datafile = flag.String("datafile", "", "read data from this file")
|
|
|
|
|
|
|
|
func run() error {
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *datafile != "" {
|
|
|
|
f, err := os.Open(*datafile)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
data, err := readData(f)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-02-25 14:08:38 +01:00
|
|
|
u := 0
|
|
|
|
y := 1
|
|
|
|
|
2023-02-24 23:50:13 +01:00
|
|
|
meanU := stats.Mean(data[u])
|
|
|
|
meanY := stats.Mean(data[y])
|
|
|
|
varianceU := stats.Variance(data[u])
|
|
|
|
varianceY := stats.Variance(data[y])
|
|
|
|
|
2023-02-25 13:23:47 +01:00
|
|
|
maxShift := 0.1
|
2023-02-25 13:50:28 +01:00
|
|
|
autocorrelationU := stats.Autocorrelate(data[u], maxShift)
|
|
|
|
autocorrelationY := stats.Autocorrelate(data[y], maxShift)
|
2023-02-25 13:23:47 +01:00
|
|
|
|
2023-02-25 14:08:38 +01:00
|
|
|
mutCorrelationUY, err := stats.MutCorrelate(data[u], data[y], maxShift)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-02-25 13:23:47 +01:00
|
|
|
log.Printf("len(data): %d", len(data[u]))
|
2023-02-24 23:50:13 +01:00
|
|
|
|
|
|
|
log.Printf("means - u: %v, y: %v", meanU, meanY)
|
|
|
|
|
|
|
|
log.Printf("variance - u: %v, y: %v", varianceU, varianceY)
|
2023-02-25 13:23:47 +01:00
|
|
|
|
|
|
|
log.Printf("len(autocorrelationU): %d", len(autocorrelationU))
|
|
|
|
log.Printf("autocorrelationU: %v", autocorrelationU)
|
|
|
|
log.Printf("autocorrelationY: %v", autocorrelationY)
|
2023-02-25 14:08:38 +01:00
|
|
|
log.Printf("mutual correlation U,Y: %v", mutCorrelationUY)
|
2023-02-24 23:50:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|