예제 #1
0
 private void DoExtractPatterns(IDecisionTreeNode node,
                                List <SelectorContext> contexts, InstanceModel model,
                                Action <EmergingPattern> patternFound,
                                Feature classFeature)
 {
     if (node.IsLeaf)
     {
         EmergingPattern newPattern = Create(contexts, model, classFeature);
         newPattern.Counts     = node.Data;
         newPattern.Supports   = CalculateSupports(node.Data, classFeature);
         newPattern.ClassValue = newPattern.Supports.ArgMax();
         if (patternFound != null)
         {
             patternFound(newPattern);
         }
     }
     else
     {
         for (int i = 0; i < node.Children.Length; i++)
         {
             SelectorContext context = new SelectorContext
             {
                 Index    = i,
                 Selector = node.ChildSelector,
             };
             contexts.Add(context);
             DoExtractPatterns(node.Children[i], contexts, model, patternFound,
                               classFeature);
             contexts.Remove(context);
         }
     }
 }
예제 #2
0
        public static bool Test(this IPatternTest test, double[] distribution, InstanceModel model, Feature classFeature)
        {
            var pattern = new EmergingPattern(model, classFeature, 0);

            pattern.Counts     = distribution;
            pattern.Supports   = EmergingPatternCreator.CalculateSupports(distribution, classFeature);
            pattern.ClassValue = pattern.Supports.ArgMax();
            return(test.Test(pattern));
        }
예제 #3
0
        public IEmergingPattern Clone()
        {
            EmergingPattern result = new EmergingPattern(Model, ClassFeature, ClassValue, Items)
            {
                Supports = (double[])Supports.Clone(),
                Counts   = (double[])Counts.Clone(),
            };

            return(result);
        }
예제 #4
0
        public EmergingPattern Create(IEnumerable <SelectorContext> contexes, InstanceModel model, Feature classFeature)
        {
            EmergingPattern result = new EmergingPattern(model, classFeature, 0);

            foreach (SelectorContext context in contexes)
            {
                IChildSelector childSelector = context.Selector;
                ItemBuilder    builder;
                if (!builderForType.TryGetValue(childSelector.GetType(), out builder))
                {
                    throw new InvalidOperationException(string.Format("Unknown selector: '{0}'", childSelector.GetType().Name));
                }
                Item item = builder.GetItem(childSelector, context.Index);
                item.Model = model;
                result.Items.Add(item);
            }
            return(result);
        }