Esempio n. 1
0
        /// <summary>
        /// Builds a covariance matrix based on corrected Matrix
        /// </summary>
        /// <param name="classCorrectedMatrix"></param>
        /// <returns></returns>
        protected List <double[][]> GetCoVarianceMatrix(
            List <double[][]> classCorrectedMatrix)
        {
            List <double[][]> covarianceMatrix = new List <double[][]>();

            //Add dummy items
            Parallel.For(0, classCorrectedMatrix.Count, idx =>
            {
                covarianceMatrix.Add(null);
            });



            //TODO:
            //Parallelize this op
            //foreach (double[][] ccMatrix in classCorrectedMatrix)
            var oLock = new Object();

            Parallel.For(0, classCorrectedMatrix.Count, idx =>
            {
                double[][] ccMatrix     = classCorrectedMatrix[idx];
                double[][] ccmTranspose = _mo.Transpose(ccMatrix);
                double[][] ccvMatrix    = _mo.Multiply(ccmTranspose, ccMatrix);
                //Divide by number of rows
                ccvMatrix = _mo.DivideByScalar(ccvMatrix, ccMatrix[0].Length);

                lock (oLock)     //List ops are not thread safe
                {
                    covarianceMatrix.RemoveAt(idx);
                    covarianceMatrix.Insert(idx, ccvMatrix);
                }
            });

            return(covarianceMatrix);
        }