/// <summary> /// Calculate the mean and covariance of \lambda over all the particles, /// i.e. /// /// \text{mean} &= \mu = \sum_i \lambda_i p(i) \nonumber \\ /// \text{mean} &= \sum_i \lambda_i\lambda_i^T p(i) - \mu\mu^T \nonumber /// /// The result is not returned, but is instead stored in the class to be read using /// get_mean() and get_covariance(). /// </summary> public void calculate_mean_and_covariance() { // Vector which will store expected value of lambda * lambda^T // (allows us to do this calculation with one pass through particles) MatrixFixed ExpectedSquared = new MatrixFixed(PARTICLE_DIMENSION, PARTICLE_DIMENSION); ExpectedSquared.Fill(0.0f); // Zero mean vector before filling it up mean.Fill(0.0f); foreach (Particle it in particle_vector) { mean += it.lambda * it.probability; ExpectedSquared += it.probability * Vector.OuterProduct(it.lambda, it.lambda); } covariance = ExpectedSquared - Vector.OuterProduct(mean, mean); }