mirror of
				https://github.com/gonum/gonum.git
				synced 2025-10-31 02:26:59 +08:00 
			
		
		
		
	improve comments
This commit is contained in:
		| @@ -16,26 +16,28 @@ func CovarianceMatrix(x mat64.Matrix) *mat64.Dense { | ||||
| 	// the correction found in the Covariance and Variance functions. | ||||
|  | ||||
| 	r, _ := x.Dims() | ||||
|  | ||||
| 	// determine the mean of each of the columns | ||||
| 	b := ones(1, r) | ||||
| 	b.Mul(b, x) | ||||
| 	b.Scale(1/float64(r), b) | ||||
| 	 | ||||
| 	// todo: avoid unneeded memory expansion here. | ||||
| 	mu := b.RowView(0) | ||||
|  | ||||
| 	// this could also be done with a clone & row viewer | ||||
| 	// subtract the mean from the data | ||||
| 	xc := mat64.DenseCopyOf(x) | ||||
| 	for i := 0; i < r; i++ { | ||||
| 		rv := xc.RowView(i) | ||||
| 		for j, mean := range(mu) { | ||||
| 		for j, mean := range mu { | ||||
| 			rv[j] -= mean | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	// todo: avoid matrix copy | ||||
| 	// todo: avoid matrix copy? | ||||
| 	xt := new(mat64.Dense) | ||||
| 	xt.TCopy(xc) | ||||
|  | ||||
| 	// It would be nice if we could indicate that this was a symmetric | ||||
| 	// matrix. | ||||
| 	ss := new(mat64.Dense) | ||||
| 	ss.Mul(xt, xc) | ||||
| 	ss.Scale(1/float64(r-1), ss) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jonathan J Lawlor
					Jonathan J Lawlor