// Calculate covariance of rates. func (cmd *cmdCr) calcCr(pis []Pi, profile []profiling.Pos, posType byte, maxl int) (covs []Covariance) { corrs := make([]Covariance, maxl) for i := 0; i < maxl; i++ { corrs[i] = correlation.NewBivariateCovariance(false) } for i := 0; i < len(pis); i++ { p1 := pis[i] pos1 := profile[p1.Pos] if checkPosType(posType, pos1.Type) { for j := i; j < len(pis); j++ { p2 := pis[j] pos2 := profile[p2.Pos] distance := p2.Pos - p1.Pos if distance < 0 { distance = -distance } if distance >= maxl { break } if checkPosType(posType, pos2.Type) { x, y := p1.Pi(), p2.Pi() corrs[distance].Increment(x, y) } } } } covs = corrs return }
// NewCovariances create a new Covariances func NewCovariances(maxl int) *Covariances { cc := Covariances{} for i := 0; i < maxl; i++ { bc := correlation.NewBivariateCovariance(false) cc.corrs = append(cc.corrs, bc) } return &cc }
// Increment add x and y arrays, which separate at distance l. func (c *Calculator) Increment(xArr, yArr []float64, l int) { if l < c.MaxL { // calculate covariance of x and y. cov := correlation.NewBivariateCovariance(false) for i := range xArr { x, y := xArr[i], yArr[i] cov.Increment(x, y) } c.Cs.Increment(l, cov.GetResult()) c.Ct.AppendAt(l, cov) c.Cr.Increment(l, cov.MeanX(), cov.MeanY()) } }