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


C# Vector.Distinct方法代码示例

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


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

示例1: Calculate

        internal override double Calculate(Vector x)
        {
            if (x == null)
                throw new InvalidOperationException("x does not exist!");

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

            return System.Math.Round(1 - px, 4);
        }
开发者ID:al-main,项目名称:CloudyBank,代码行数:13,代码来源:Error.cs

示例2: Calculate

        internal override double Calculate(Vector x)
        {
            if (x == null)
                throw new InvalidOperationException("x does not exist!");

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

            double imp = (from p in px
                          select -1 * p * System.Math.Log(p, 2)).Sum();

            // rouding off to 4 sig figs...
            return System.Math.Round(imp, 4);
        }
开发者ID:al-main,项目名称:CloudyBank,代码行数:17,代码来源:Entropy.cs

示例3: Calculate

        internal override double Calculate(Vector x)
        {
            if (x == null)
                throw new InvalidOperationException("x does not exist!");

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

            var g = 1 - (from j in px
                         select j * j).Sum();

            // thought this was the right one...
            //for (int i = 0; i < px.Length; i++)
            //    for (int j = i + 1; j < px.Length; j++)
            //        imp += px[i] * px[j];

            return System.Math.Round(g, 4); ;
        }
开发者ID:al-main,项目名称:CloudyBank,代码行数:21,代码来源:Gini.cs

示例4: CalculateConditional

        internal double CalculateConditional(Vector y, Vector x)
        {
            if (x == null && y == null)
                throw new InvalidOperationException("x and y do not exist!");

            var values = x.Distinct();
            var valueCount = values.Count();
            double result = 0;

            // binary split
            if (Width == 2)
            {
                // do binary split based on mean
                var mean = x.Mean();
                var ltSlice = y.Slice(x.Indices(d => d < mean));
                var gtSlice = y.Slice(x.Indices(d => d >= mean));

                var lh = Calculate(ltSlice);
                var rh = Calculate(gtSlice);

                result = (0.5 * lh) + (0.5 * rh);
                SplitValues = new double[] { x.Min(), mean, x.Max() + 1 };
            }
            // if valueCount has more values than
            // width allows, segment out data to
            // fit width
            else if (valueCount > Width)
            {
                double p = 0;
                double h = 0;
                // create segmentation
                // should really consider
                // some kind of distribution
                // for doing segmentation..
                SplitValues = x.Segment(Width);
                // for convenience ;)
                SplitValues[SplitValues.Length - 1] += 1;
                for (int i = 1; i < SplitValues.Length; i++)
                {
                    // get slice
                    var s = x.Indices(d => d >= SplitValues[i - 1] && d < SplitValues[i]);

                    // probability of slice
                    p = s.Count() / (double)x.Length;

                    // Impurity (y | x_i)
                    h = Calculate(y.Slice(s));

                    // sum up
                    result += p * h;
                }
            }
            // otherwise perform regular counting
            // exercises to find cond entropy
            else
            {
                double p = 0;
                double h = 0;
                // says there is no width
                // since deterministic
                // slice values
                _width = 0;
                SplitValues = new double[valueCount];
                int k = -1;
                // each disting x value
                foreach (var i in values)
                {
                    SplitValues[++k] = i;

                    // get slice
                    var s = x.Indices(d => d == i);

                    // probability of x_i
                    p = s.Count() / (double)x.Length;

                    // Impurity (y | x_i)
                    h = Calculate(y.Slice(s));

                    // sum up
                    result += p * h;
                }
            }

            return result;
        }
开发者ID:al-main,项目名称:CloudyBank,代码行数:85,代码来源:Impurity.cs


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