示例#1
0
        public IEnumerable <IEmergingPattern> Mine(InstanceModel model, IEnumerable <Instance> instances, Feature classFeature)
        {
            EmergingPatternCreator                EpCreator  = new EmergingPatternCreator();
            EmergingPatternComparer               epComparer = new EmergingPatternComparer(new ItemComparer());
            IEmergingPatternSimplifier            simplifier = new EmergingPatternSimplifier(new ItemComparer());
            FilteredCollection <IEmergingPattern> minimal    =
                new FilteredCollection <IEmergingPattern>(epComparer.Compare, FilterRelation);

            if (MinePatternsWhileBuildingTree)
            {
                DecisionTreeBuilder.OnSplitEvaluation =
                    delegate(IDecisionTreeNode node, ISplitIterator iterator, List <SelectorContext> currentContext)
                {
                    IChildSelector currentSelector = null;
                    for (int i = 0; i < iterator.CurrentDistribution.Length; i++)
                    {
                        double[] distribution = iterator.CurrentDistribution[i];
                        if (EPTester.Test(distribution, model, classFeature))
                        {
                            if (currentSelector == null)
                            {
                                currentSelector = iterator.CreateCurrentChildSelector();
                            }
                            EmergingPattern ep = EpCreator.ExtractPattern(currentContext, model, classFeature,
                                                                          currentSelector, i);
                            ep.Counts = (double[])distribution.Clone();
                            minimal.Add(simplifier.Simplify(ep));
                        }
                    }
                };
                DoMine(model, instances, classFeature, EpCreator, null);
            }
            else
            {
                DoMine(model, instances, classFeature, EpCreator, p =>
                {
                    if (EPTester.Test(p.Counts, model, classFeature))
                    {
                        minimal.Add(simplifier.Simplify(p));
                    }
                }
                       );
            }
            return(minimal.GetItems());
        }