コード例 #1
0
        /// <summary>
        /// Normalizes a sparse vector using the L2 norm.
        /// </summary>
        /// <param name="sparseVector">
        /// The sparse vector.
        /// </param>
        /// <returns>
        /// The normalized sparse vector
        /// </returns>
        private static SparseVector Normalize(SparseVector sparseVector)
        {
            var sumSquared = sparseVector.Inner(sparseVector);

            if (sumSquared > 1e-10)
            {
                return((SparseVector)(sparseVector / Math.Sqrt(sumSquared)));
            }
            else
            {
                return(sparseVector);
            }
        }