p2: calculate/save covariance
This commit is contained in:
parent
102454e6e1
commit
129f33c9a6
12
p2/data.go
12
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,
|
||||
|
1
p2/data/covariance_uy.txt
Normal file
1
p2/data/covariance_uy.txt
Normal file
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user