當前位置: 首頁>>代碼示例>>C#>>正文


C# Vector.Count方法代碼示例

本文整理匯總了C#中numl.Math.LinearAlgebra.Vector.Count方法的典型用法代碼示例。如果您正苦於以下問題:C# Vector.Count方法的具體用法?C# Vector.Count怎麽用?C# Vector.Count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numl.Math.LinearAlgebra.Vector的用法示例。


在下文中一共展示了Vector.Count方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SegmentedConditional

        /// <summary>
        /// Calculates segmented conditional impurity of y | x When stipulating ranges (r), X is broken
        /// up into
        /// |r| many segments therefore P(X=x_r) becomes a range probability
        /// rather than a fixed probability. In essence the average over H(Y|X = x) becomes SUM_s [ p_r *
        /// H(Y|X = x_r) ]. The values that were used to do the split are stored in the Splits member.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
        /// <param name="y">Target impurity.</param>
        /// <param name="x">Conditioned impurity.</param>
        /// <param name="ranges">Number of segments over x to condition upon.</param>
        /// <returns>Segmented conditional impurity measure.</returns>
        public double SegmentedConditional(Vector y, Vector x, IEnumerable<Range> ranges)
        {
            if (x == null && y == null)
                throw new InvalidOperationException("x and y do not exist!");

            double p = 0,               // probability of slice
                   h = 0,               // impurity of y | x_i : ith slice
                   result = 0,          // aggregated sum
                   count = x.Count();   // total items in list

            Segments = ranges.OrderBy(r => r.Min).ToArray();
            Discrete = false;

            // for each range calculate
            // conditional impurity and
            // aggregate results
            foreach (Range range in Segments)
            {
                // get slice
                var s = x.Indices(d => d >= range.Min && d < range.Max);
                // slice probability
                p = (double)s.Count() / (double)count;
                // impurity of (y | x_i)
                h = Calculate(y.Slice(s));
                // sum up
                result += p * h;
            }

            return result;
        }
開發者ID:m-abubakar,項目名稱:numl,代碼行數:42,代碼來源:Impurity.cs

示例2: Conditional

        /// <summary>
        /// Calculates conditional impurity of y | x
        /// R(Y|X) is the average of H(Y|X = x) over all possible values
        /// X may take. 
        /// </summary>
        /// <param name="y">Target impurity</param>
        /// <param name="x">Conditioned impurity</param>
        /// <param name="width">Split of values over x to condition upon</param>
        /// <returns>Conditional impurity measure</returns>
        public double Conditional(Vector y, Vector x)
        {
            if (x == null && y == null)
                throw new InvalidOperationException("x and y do not exist!");

            double p = 0,               // probability of slice
                   h = 0,               // impurity of y | x_i : ith slice
                   result = 0,          // aggregated sum
                   count = x.Count();   // total items in list

            var values = x.Distinct().OrderBy(z => z);  // distinct values to split on

            Segments = values.Select(z => Range.Make(z, z)).ToArray();
            Discrete = true;

            // for each distinct value
            // calculate conditional impurity
            // and aggregate results
            foreach (var i in values)
            {
                // get slice
                var s = x.Indices(d => d == i);
                // slice probability
                p = (double)s.Count() / (double)count;
                // impurity of (y | x_i)
                h = Calculate(y.Slice(s));
                // sum up
                result += p * h;
            }

            return result;
        }
開發者ID:budbjames,項目名稱:numl,代碼行數:41,代碼來源:Impurity.cs

示例3: Calculate

        /// <summary>Calculates Classification Error of x.</summary>
        /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
        /// <param name="x">The list in question.</param>
        /// <returns>Impurity measure.</returns>
        public override double Calculate(Vector x)
        {
            if (x == null)
            {
                throw new InvalidOperationException("x does not exist!");
            }

            double length = x.Count();

            var e = from i in x.Distinct() let q = (from j in x where j == i select j).Count() select q / length;

            return 1 - e.Max();
        }
開發者ID:ChewyMoon,項目名稱:Cupcake,代碼行數:17,代碼來源:Error.cs

示例4: Calculate

        /// <summary>Calculates the Shannon Entropy of x.</summary>
        /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
        /// <param name="x">The list in question.</param>
        /// <returns>Impurity measure.</returns>
        public override double Calculate(Vector x)
        {
            if (x == null)
            {
                throw new InvalidOperationException("x does not exist!");
            }

            double length = x.Count();

            var px = from i in x.Distinct() let q = (from j in x where j == i select j).Count() select q / length;

            var e = (from p in px select -1 * p * Math.Log(p, 2)).Sum();

            return e;
        }
開發者ID:ChewyMoon,項目名稱:Cupcake,代碼行數:19,代碼來源:Entropy.cs

示例5: Calculate

        /// <summary>Calculates Gini Index of x.</summary>
        /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
        /// <param name="x">The list in question.</param>
        /// <returns>Impurity measure.</returns>
        public override double Calculate(Vector x)
        {
            if (x == null)
            {
                throw new InvalidOperationException("x does not exist!");
            }

            double length = x.Count();

            var px = from i in x.Distinct() let q = (from j in x where j == i select j).Count() select q / length;

            var g = 1 - px.Select(d => d * d).Sum();

            return g;
        }
開發者ID:ChewyMoon,項目名稱:Cupcake,代碼行數:19,代碼來源:Gini.cs


注:本文中的numl.Math.LinearAlgebra.Vector.Count方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。