예제 #1
0
        public Matrix Covariance(Vector mean)
        {
            Matrix cache = new Matrix (rows, columns);
            float factor = 1.0f/(float)(columns - 1);
            for (int j = 0; j < rows; j++) {
                for (int i = 0; i < columns; i++) {
                    cache.d[j, i] = (d[j, i] - mean.d[j, 0]);
                }
            }

            Matrix cov = new Matrix (mean.rows, mean.rows);
            for (int i = 0; i < cov.rows; i++) {
                for (int j = 0; j <= i; j++) {
                    float sum = 0.0f;
                    for (int k = 0; k < columns; k++) {
                        sum += cache.d[i, k] * cache.d[j, k];
                    }
                    sum *= factor;
                    cov.d[i, j] = sum;
                    if (i == j) {
                        continue;
                    }
                    cov.d[j, i] = sum;
                }
            }

            return cov;
        }
예제 #2
0
		public Vector Mean ()
		{
			Vector mean = new Vector (rows);
			for (int i = 0; i < rows; i++) {
				for (int j = 0; j < columns; j++) {
					mean.d[i, 0] += d[i, j] / columns;
				}
			}

			return mean;
		}