68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
|
|
"git.dotya.ml/wanderer/ak9im/p2/stats"
|
|
)
|
|
|
|
var datafile = flag.String("datafile", "", "read data from this file")
|
|
|
|
func run() error {
|
|
flag.Parse()
|
|
|
|
if *datafile != "" {
|
|
data, err := readFile(datafile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
u := 0
|
|
y := 1
|
|
|
|
meanU := stats.Mean(data[u])
|
|
meanY := stats.Mean(data[y])
|
|
varianceU := stats.Variance(data[u])
|
|
varianceY := stats.Variance(data[y])
|
|
|
|
maxShift := 0.1
|
|
autocorrelationU := stats.Autocorrelate(data[u], maxShift)
|
|
autocorrelationY := stats.Autocorrelate(data[y], maxShift)
|
|
|
|
mutCorrelationUY, err := stats.MutCorrelate(data[u], data[y], maxShift)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
mutCorrelationYU, err := stats.MutCorrelate(data[y], data[u], maxShift)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Printf("len(data): %d", len(data[u]))
|
|
|
|
log.Printf("means - u: %v, y: %v", meanU, meanY)
|
|
|
|
log.Printf("variance - u: %v, y: %v", varianceU, varianceY)
|
|
|
|
log.Printf("len(autocorrelationU): %d", len(autocorrelationU))
|
|
log.Printf("autocorrelationU: %v", autocorrelationU)
|
|
log.Printf("autocorrelationY: %v", autocorrelationY)
|
|
log.Printf("mutual correlation U,Y: %v", mutCorrelationUY)
|
|
log.Printf("mutual correlation Y,U: %v", mutCorrelationYU)
|
|
|
|
err = saveStuff(
|
|
meanU, meanY,
|
|
varianceU, varianceY,
|
|
autocorrelationU, autocorrelationY,
|
|
mutCorrelationUY, mutCorrelationYU,
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|