Exemplo n.º 1
0
        public void Count_TwoItemsAdded_ReturnsTwo()
        {
            // arrange
            string f1 = "F1";
            string f2 = "F2";
            FeatureNumericalManager featureManager = new FeatureNumericalManager();

            featureManager.Add(new FeatureNumerical("F1"));
            featureManager.Add(new FeatureNumerical("F2"));
            ItemNumericalSet set = new ItemNumericalSet(featureManager);

            ItemNumerical i1 = set.CreateItem();

            i1.SetValue(f1, 3);
            i1.SetValue(f2, 4.7f);
            set.AddItem(i1);

            ItemNumerical i2 = set.CreateItem();

            i2.SetValue(f1, 1);
            i2.SetValue(f2, 2.1f);
            set.AddItem(i2);

            // act
            int qty = set.Count();

            // assert
            Assert.AreEqual(2, qty);
        }
Exemplo n.º 2
0
        public void GetRandomSubset_9from15_Returns9()
        {
            // arrange
            FillItemSet_Features4_Items15();
            float subcountRatio = 0.6f;

            // act
            ItemNumericalSet subset = _set.GetRandomSubset(subcountRatio, false);

            // assert
            Assert.IsNotNull(subset);
            Assert.AreEqual(9, subset.Count());
        }
Exemplo n.º 3
0
        public void FillItemNumericalSet_ExcelDocument_()
        {
            // arrange
            GenerateExcelDocumentF3();
            FileInfo fi = new FileInfo(@"temp\test.xlsx");

            //FileInfo fi = new FileInfo(@"data\test-4x1000.xlsx");
            if (!fi.Exists)
            {
                Assert.Fail();
            }

            // act
            ItemNumericalSet set = ExcelParser.ParseItemNumericalSet(fi.FullName, 1);

            // assert
            Assert.IsNotNull(set);
            Assert.AreEqual(_itemsQty, set.Count());
            Assert.AreEqual(true, set.CheckConsistency());
        }
Exemplo n.º 4
0
        public FeatureNumericalSplitValue Split(ItemNumericalSet set, string resolutionFeatureName)
        {
            double totalIndex = set.GetRSS(resolutionFeatureName);

            if (totalIndex == 0)
            {
                return(null);
            }

            double minIndex = totalIndex;

            var featureNameList = set.GetFeatureNames();
            var featureNames    = featureNameList.Where(x => x != resolutionFeatureName);

            if (!featureNames.Any())
            {
                throw new Exception();
            }

            FeatureNumericalSplitValue res = new FeatureNumericalSplitValue();

            foreach (string fn in featureNames)
            {
                set.SortItems(fn);

                int qty = set.Count();
                for (int k = 1; k < qty; k++)
                {
                    //ItemNumericalSet left = new ItemNumericalSet(featureNameList);
                    //ItemNumericalSet right = new ItemNumericalSet(featureNameList);
                    ItemNumericalSet left  = set.Clone();
                    ItemNumericalSet right = set.Clone();
                    for (int i = 0; i < k; i++)
                    {
                        left.AddItem(set.GetItem(i));
                    }
                    for (int i = k; i < qty; i++)
                    {
                        right.AddItem(set.GetItem(i));
                    }

                    double leftIndex  = left.GetRSS(resolutionFeatureName);
                    double rightIndex = right.GetRSS(resolutionFeatureName);

                    bool sumIndexIsLessThanMinIndex = leftIndex + rightIndex < minIndex;
                    bool sumIndexIsEqualToMinIndex  = leftIndex + rightIndex == minIndex;

                    if (sumIndexIsLessThanMinIndex || (k == qty - 1 && sumIndexIsEqualToMinIndex))
                    {
                        if (sumIndexIsLessThanMinIndex)
                        {
                            minIndex = leftIndex + rightIndex;
                        }

                        res.FeatureName = fn;
                        double lv = left.GetItem(left.Count() - 1).GetValue(fn);
                        double rv = right.GetItem(0).GetValue(fn);
                        res.FeatureValue = Math.Round(lv + (rv - lv) / 2, 5);
                        res.Left         = left;
                        res.Right        = right;
                    }
                }
            }

            return(res);
        }
Exemplo n.º 5
0
        public FeatureNumericalSplitValue Split(ItemNumericalSet set, string resolutionFeatureName)
        {
            double totalIndex = set.GetGini2(resolutionFeatureName);

            if (totalIndex == 0)
            {
                return(null);
            }

            double minIndex = totalIndex;
            double maxDelta = 0;
            int    n        = set.Count();

            var featureNameList = set.GetFeatureNames();
            var featureNames    = featureNameList.Where(x => x != resolutionFeatureName);

            if (!featureNames.Any())
            {
                throw new Exception();
            }

            FeatureNumericalSplitValue res = new FeatureNumericalSplitValue();

            foreach (string fn in featureNames)
            {
                set.SortItems(fn);

                int qty = set.Count();
                for (int k = 1; k < qty; k++)
                {
                    //ItemNumericalSet left = new ItemNumericalSet(featureNameList);
                    //ItemNumericalSet right = new ItemNumericalSet(featureNameList);
                    ItemNumericalSet left  = set.Clone();
                    ItemNumericalSet right = set.Clone();
                    for (int i = 0; i < k; i++)
                    {
                        left.AddItem(set.GetItem(i));
                    }
                    for (int i = k; i < qty; i++)
                    {
                        right.AddItem(set.GetItem(i));
                    }

                    double leftIndex  = left.GetGini2(resolutionFeatureName);
                    double rightIndex = right.GetGini2(resolutionFeatureName);
                    int    lc         = left.Count();
                    int    rc         = right.Count();
                    double delta      = totalIndex - ((lc * 1.0) / n) * leftIndex - ((rc * 1.0) / n) * rightIndex;

                    if (delta > maxDelta)
                    {
                        maxDelta        = delta;
                        res.FeatureName = fn;
                        double lv = left.GetItem(left.Count() - 1).GetValue(fn);
                        double rv = right.GetItem(0).GetValue(fn);
                        res.FeatureValue = Math.Round(lv + (rv - lv) / 2, 5);
                        res.Left         = left;
                        res.Right        = right;
                    }
                }
            }

            return(res);
        }
Exemplo n.º 6
0
 public int ItemCount()
 {
     return(_set.Count());
 }