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


C# ICollection.ToLookup方法代码示例

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


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

示例1: Entropy

        /// <summary>
        /// Entropy of a set of examples
        /// </summary>
        private static double Entropy(ICollection<Example> examples)
        {
            var exampleValues = examples.ToLookup(x => x.ClassLabel);

            var probabilities = exampleValues.Select(x => (double)x.Count() / examples.Count);

            return -probabilities.Sum(x => x * Math.Log(x, 2));
        }
开发者ID:aldenquimby,项目名称:cs4701,代码行数:11,代码来源:Learner.cs

示例2: LearnInternal

        /// <summary>
        /// Recursively construct decision tree from examples and attributes
        /// </summary>
        private static TreeNode LearnInternal(ICollection<Example> examples, ICollection<DataAttribute> attributes, IEnumerable<Example> parentExamples)
        {
            // if no examples, use parent plurality
            if (examples.Count == 0)
            {
                return PluralityValue(parentExamples);
            }

            // if all examples have same classification, use it
            if (examples.Select(x => x.ClassLabel).Distinct().Count() == 1)
            {
                return new TreeNode
                    {
                        ClassLabel = examples.First().ClassLabel,
                    };
            }

            // if no attributes, use plurality
            if (attributes.Count == 0)
            {
                return PluralityValue(examples);
            }

            // pick most important attribute
            var attr = attributes.OrderByDescending(x => Importance(examples, x)).First();

            // get other attributes
            var remainingAttrs = attributes.Where(x => x != attr).ToList();

            // group the examples by their value for selected attribute
            var examplesByAttrValue = examples.ToLookup(x => x.Attributes[attr.ColNum]);

            // construct a decision tree for this attribute
            var tree = new TreeNode
                {
                    ColNum = attr.ColNum,
                };

            // for each value, recursively construct a sub-tree
            foreach (var attrValue in attr.Values)
            {
                var childExamples = examplesByAttrValue[attrValue].ToList();

                var subTree = LearnInternal(childExamples, remainingAttrs, examples);

                tree.Children.Add(attrValue, subTree);
            }

            return tree;
        }
开发者ID:aldenquimby,项目名称:cs4701,代码行数:53,代码来源:Learner.cs

示例3: InspectionHelper

        /// <summary>
        /// Instantiate dependencies, resolve method metadata tokens and from that build
        /// caller-callee method pairs
        /// </summary>
        /// <param name="assembly">the assembly that is being probed</param>
        internal InspectionHelper(Assembly assembly)
        {
            _logger = LogManager.GetLogger(GetType().Name);

            _assembly = assembly;
            _methodILBytes = assembly.GetTypes()
                .SelectMany(t => t.GetMethods(BindingFlags.Instance
                                              | BindingFlags.NonPublic
                                              | BindingFlags.Public
                                              | BindingFlags.Static
                                              | BindingFlags.DeclaredOnly))
                .Where(mi => mi.GetMethodBody() != null)
                .ToDictionary(mi => mi,
                              mi => mi.GetMethodBody().GetILAsByteArray());

            _calls = new List<Tuple<MethodInfo, MethodInfo>>(_methodILBytes.Count);
            FindCalls();

            _callsLookup = _calls.ToLookup(x => x.Item1, x => x.Item2);
        }
开发者ID:hruan,项目名称:Pennyworth,代码行数:25,代码来源:InspectionHelper.cs

示例4: Remainder

        /// <summary>
        /// Remaining entropy after attribute divides example set
        /// </summary>
        private static double Remainder(ICollection<Example> examples, DataAttribute attr)
        {
            var subsets = examples.ToLookup(x => x.Attributes[attr.ColNum]);

            return subsets.Select(x => x.ToList())
                          .Select(subset => new
                              {
                                  prob = (double)subset.Count / examples.Count,
                                  entropy = Entropy(subset),
                              })
                          .Sum(x => x.prob * x.entropy);
        }
开发者ID:aldenquimby,项目名称:cs4701,代码行数:15,代码来源:Learner.cs


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