当前位置: 首页>>代码示例>>C#>>正文


C# Double.Select方法代码示例

本文整理汇总了C#中System.Double.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Double.Select方法的具体用法?C# Double.Select怎么用?C# Double.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Double的用法示例。


在下文中一共展示了Double.Select方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetRatios

        /// <summary>
        /// Gets an array of coefficients that can be used to weight a numerical sequence of the specified length.
        /// The value of an element in the array represents the weighting coefficient for the item at the corresponding index in the sequence.
        /// </summary>
        /// <param name="rateOfChange">The rate at which the ratios change.</param>
        /// <param name="length">The length of the sequence for which weighting coefficients will be returned.</param>
        /// <returns>An array of <paramref name="length"/> length, that contains the weighting coefficients.</returns>
        /// <remarks>
        /// The sum of the array's elements should always equal 1.
        /// When a low value is provided for <paramref name="length"/>, the sum of the array elements is measurably smaller than 1.
        /// Consequently, after all elements in the sequence have been calculated, the remainder is divided equally between all elements such that their sum approaches 1.
        /// </remarks>
        public Double[] GetRatios(Int32 length, Double rateOfChange = 0.5)
        {
            Double[] ratios = new Double[length];
            Double currentAmount = 1;
            for (Int32 i = 0; i < ratios.Length; i++)
            {
                Double currentVal = currentAmount * rateOfChange;
                Double remaining = currentAmount - currentVal;
                currentAmount = remaining;
                ratios[i] = currentVal;
            }

            // As the number of buckets increases, the sum of the buckets approaches 1.
            // When the number of buckets is very small, a significant portion is not represented in the output.
            // To account for this, we split the remaining portion and apply it evenly among every bucket.
            currentAmount /= length;

            // Sometimes Resharper is a little dumb.
            // ReSharper disable once RedundantAssignment
            ratios = ratios.Select(bucket => bucket += currentAmount).ToArray();
            return ratios;
        }
开发者ID:Rychard,项目名称:GnomeServer,代码行数:34,代码来源:GnomeController.cs

示例2: CalculateNormalizeVector

        private static Double[] CalculateNormalizeVector(Double[,] matrix)
        {
            Int32 n = matrix.GetLength(0);

            Double[] notNormalizeVector = new Double[n];

            for (Int32 i = 0; i < n; i++)
            {
                Double tmp = 1;
                for (Int32 j = 0; j < n; j++)
                {
                    tmp *= matrix[i, j];
                }

                notNormalizeVector[i] = Math.Pow(tmp, (Double)1/n);
            }

            Double sumOfVector = notNormalizeVector.Sum();

            Double[] normalizeVector = notNormalizeVector.Select(v => v / sumOfVector).ToArray();

            return normalizeVector;
        }
开发者ID:SenkaOlefir,项目名称:Project_MVC,代码行数:23,代码来源:JudgmentHelper.cs


注:本文中的System.Double.Select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。