public static void computeNormal ( List < Point2D_F64 > points , Point2D_F64 mean , DMatrix covariance ) { if ( covariance . getNumCols ( ) != 2 || covariance . getNumRows ( ) != 2 ) { if ( covariance instanceof ReshapeMatrix ) { ( ( ReshapeMatrix ) covariance ) . reshape ( 2 , 2 ) ; } else { throw new IllegalArgumentException ( "Must be a 2x2 matrix" ) ; } } mean ( points , mean ) ; double xx = 0 , xy = 0 , yy = 0 ; for ( int i = 0 ; i < points . size ( ) ; i ++ ) { Point2D_F64 p = points . get ( i ) ; double dx = p . x - mean . x ; double dy = p . y - mean . y ; xx += dx * dx ; xy += dx * dy ; yy += dy * dy ; } xx /= points . size ( ) ; xy /= points . size ( ) ; yy /= points . size ( ) ; covariance . unsafe_set ( 0 , 0 , xx ) ; covariance . unsafe_set ( 0 , 1 , xy ) ; covariance . unsafe_set ( 1 , 0 , xy ) ; covariance . unsafe_set ( 1 , 1 , yy ) ; }
Computes the mean and covariance matrix from the set of points . This describes a normal distribution