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); } } }
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)); }
public IEmergingPattern Clone() { EmergingPattern result = new EmergingPattern(Model, ClassFeature, ClassValue, Items) { Supports = (double[])Supports.Clone(), Counts = (double[])Counts.Clone(), }; return(result); }
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); }