예제 #1
0
        public void TestApriori()
        {
            _targetObject.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Cheap]);
            _targetObject.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.AllMountain]);

            _category.Engine.TeachCategory(_targetObject);

            ITargetObject targetObjectOther = new TargetObject(_category,
                                                               _category.CategoryTypes[
                                                                   TestCategoryFactory.MediumCategory]);

            _category.Engine.TeachCategory(new List<ITargetObject> {targetObjectOther, _targetObject, _targetObject});

            _category.Engine.PrepareToClassification();

            Assert.AreEqual(
                _category.Engine.GetApriori(TestCategoryFactory.CategoryTypes[TestCategoryFactory.BeginnerCategory]),
                3.0/4.0);
            Assert.AreEqual(
                _category.Engine.GetApriori(TestCategoryFactory.CategoryTypes[TestCategoryFactory.MediumCategory]),
                1.0/4.0);
            Assert.AreEqual(
                _category.Engine.GetApriori(TestCategoryFactory.CategoryTypes[TestCategoryFactory.AdvancedCategory]),
                0.0/4.0);
        }
예제 #2
0
        public void TestClassifyFreestyleExpensiveAsAdvancedCategory()
        {
            ITargetObject snowboardExpensiveFreestyleToClassify = new TargetObject(this._category, String.Empty);
            snowboardExpensiveFreestyleToClassify.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Freestyle]);
            snowboardExpensiveFreestyleToClassify.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Expensive]);

            double beginnerProbability, mediumProbability, advancedProbability;

            this.GetProbabilities(snowboardExpensiveFreestyleToClassify, out beginnerProbability, out mediumProbability, out advancedProbability);

            Assert.IsTrue(advancedProbability > mediumProbability);
            Assert.IsTrue(advancedProbability > beginnerProbability);
        }
예제 #3
0
        public void TestClassifyFreerideCheapAsMediumCategory()
        {
            ITargetObject snowboardFreerideCheapToClassify = new TargetObject(this._category, String.Empty);
            snowboardFreerideCheapToClassify.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Freeride]);
            snowboardFreerideCheapToClassify.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Cheap]);

            double beginnerProbability, mediumProbability, advancedProbability;

            this.GetProbabilities(snowboardFreerideCheapToClassify, out beginnerProbability, out mediumProbability, out advancedProbability);

            Assert.IsTrue(mediumProbability > advancedProbability);
            Assert.IsTrue(mediumProbability > beginnerProbability);
        }
예제 #4
0
        public void TestClassifyAllMountainCheapAsBeginnerCategory()
        {
            ITargetObject snowboardCheapAllMountainToClassify = new TargetObject(this._category, String.Empty);
            snowboardCheapAllMountainToClassify.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.AllMountain]);
            snowboardCheapAllMountainToClassify.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Cheap]);

            double beginnerProbability, mediumProbability, advancedProbability;

            this.GetProbabilities(snowboardCheapAllMountainToClassify, out beginnerProbability, out mediumProbability, out advancedProbability);

            Assert.IsTrue(beginnerProbability > mediumProbability);
            Assert.IsTrue(beginnerProbability > advancedProbability);
        }
        public void classify(string mushroomTeachingDataFile, string mushroomTestingDataFile, string outputDataFile)
        {
            this._dataLoader = new DataLoader();
            this._category = this.PrepareCategoryFromFile();

            Console.WriteLine("Loading data");
            List<ITargetObject> targetObjects = this._dataLoader.LoadTeachingData(_category, mushroomTeachingDataFile);

            Console.WriteLine("Teaching category engine");
            _category.Engine.TeachCategory(targetObjects);

            _category.Engine.PrepareToClassification();

            var fileInfo = new FileInfo(mushroomTestingDataFile);
            TextReader reader = fileInfo.OpenText();
            TextWriter writer = new StreamWriter(outputDataFile);

            string text;
            double edible, poisonous;
            List<string> attributes;

            Console.WriteLine("Classifing");
            do
            {
                text = reader.ReadLine();
                if (String.Equals(text, NewObjectCommand))
                {
                    ITargetObject mushroom = new TargetObject(_category, String.Empty);
                    string categoryType = String.Empty;

                    attributes = getAttributes(_category, reader,out categoryType);

                    foreach (string attribute in attributes)
                    {
                        mushroom.SetAttributeExist(attribute);
                    }

                    GetProbabilities(mushroom, _category, out edible, out poisonous);

                    writer.WriteLine(edible + " " + poisonous + " " + categoryType);
                    writer.Flush();
                }
            } while (text != null);
            writer.Close();
            reader.Close();
        }
        public void classify(string titanicTeachingDataFile, string titanicTestingDataFile,string titanicOutputDataFile)
        {
            this._dataLoader = new DataLoader();
            this._category = this.PrepareCategoryFromFile();

            Console.WriteLine("Loading data");
            List<ITargetObject> targetObjects = this._dataLoader.LoadTeachingData(_category, titanicTeachingDataFile);

            Console.WriteLine("Teaching category engine");
            _category.Engine.TeachCategory(targetObjects);

            _category.Engine.PrepareToClassification();

            var fileInfo = new FileInfo(titanicTestingDataFile);

            TextReader reader = fileInfo.OpenText();
            TextWriter writer = new StreamWriter(titanicOutputDataFile);

            string text;
            double survivedProbability, notSurvivedProbability;
            List<string> attributes;

            Console.WriteLine("Classifing");
            do
            {
                text = reader.ReadLine();
                if (String.Equals(text, NewObjectCommand))
                {
                    ITargetObject titanicPassenger = new TargetObject(_category, String.Empty);

                    attributes = getAttributes(_category, reader);

                    foreach (string attribute in attributes)
                    {
                        titanicPassenger.SetAttributeExist(attribute);
                    }

                    GetProbabilities(titanicPassenger, _category, out survivedProbability, out notSurvivedProbability);

                    writer.WriteLine(number + " " + survivedProbability + " " + notSurvivedProbability);
                    writer.Flush();
                }
            } while (text != null);
            writer.Close();
            reader.Close();
        }
예제 #7
0
 public void TestObjectIsClassified()
 {
     ITargetObject snowboardExpensiveFreestyle = new TargetObject(this._category, this._category.CategoryTypes[TestCategoryFactory.AdvancedCategory]);
     this._classifer.GetClassification(snowboardExpensiveFreestyle);
 }
예제 #8
0
        private void InitAndTeachCategory()
        {
            CategoryFactory.AddCategoryType(TestCategoryFactory.CategoryName, TestCategoryFactory.CategoryTypes, TestCategoryFactory.CategoryAttributes);

            this._category = CategoryFactory.GetCategory(TestCategoryFactory.CategoryName);

            ITargetObject snowboardExpensiveAllMountain = new TargetObject(this._category, this._category.CategoryTypes[TestCategoryFactory.MediumCategory]);
            snowboardExpensiveAllMountain.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Expensive]);
            snowboardExpensiveAllMountain.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.AllMountain]);

            ITargetObject snowboardCheapAllMountain = new TargetObject(this._category, this._category.CategoryTypes[TestCategoryFactory.BeginnerCategory]);
            snowboardCheapAllMountain.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Cheap]);
            snowboardCheapAllMountain.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.AllMountain]);

            ITargetObject snowboardCheapFreestyle = new TargetObject(this._category, this._category.CategoryTypes[TestCategoryFactory.BeginnerCategory]);
            snowboardCheapFreestyle.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Cheap]);
            snowboardCheapFreestyle.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Freestyle]);

            ITargetObject snowboardExpensiveFreestyle = new TargetObject(this._category, this._category.CategoryTypes[TestCategoryFactory.AdvancedCategory]);
            snowboardExpensiveFreestyle.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Expensive]);
            snowboardExpensiveFreestyle.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Freestyle]);

            ITargetObject snowboardCheapFreeride = new TargetObject(this._category, this._category.CategoryTypes[TestCategoryFactory.MediumCategory]);
            snowboardCheapFreeride.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Cheap]);
            snowboardCheapFreeride.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Freeride]);

            ITargetObject snowboardExpensiveFreeride = new TargetObject(this._category, this._category.CategoryTypes[TestCategoryFactory.AdvancedCategory]);
            snowboardExpensiveFreeride.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Expensive]);
            snowboardExpensiveFreeride.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Freeride]);

            this._category.Engine.TeachCategory(new List<ITargetObject>
                                                    {
                                                        snowboardCheapAllMountain,
                                                        snowboardCheapAllMountain,
                                                        snowboardCheapAllMountain,
                                                        snowboardCheapAllMountain,
                                                        snowboardCheapAllMountain,
                                                        snowboardCheapAllMountain,
                                                        snowboardCheapAllMountain,
                                                        snowboardExpensiveAllMountain,
                                                        snowboardExpensiveAllMountain,
                                                        snowboardExpensiveAllMountain,
                                                        snowboardCheapFreeride,
                                                        snowboardCheapFreeride,
                                                        snowboardCheapFreeride,
                                                        snowboardCheapFreeride,
                                                        snowboardExpensiveFreeride,
                                                        snowboardCheapFreestyle,
                                                        snowboardCheapFreestyle,
                                                        snowboardCheapFreestyle,
                                                        snowboardCheapFreestyle,
                                                        snowboardExpensiveFreestyle
                                                    });

            this._category.Engine.PrepareToClassification();
        }
예제 #9
0
        public void TestProbability()
        {
            _targetObject.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Cheap]);
            _targetObject.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.AllMountain]);

            _category.Engine.TeachCategory(_targetObject);

            ITargetObject targetObjectOther = new TargetObject(_category,
                                                               _category.CategoryTypes[
                                                                   TestCategoryFactory.BeginnerCategory]);
            targetObjectOther.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Cheap]);
            targetObjectOther.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Freestyle]);

            _category.Engine.TeachCategory(new List<ITargetObject> {targetObjectOther, _targetObject});

            _category.Engine.PrepareToClassification();

            const double numberOfTargetObject = 3.0;
            Assert.AreEqual(
                _category.Engine.GetCategoryType(_category.CategoryTypes[TestCategoryFactory.BeginnerCategory])
                         .GetProbability(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Cheap]),
                4.0/numberOfTargetObject);
            Assert.AreEqual(
                _category.Engine.GetCategoryType(_category.CategoryTypes[TestCategoryFactory.BeginnerCategory])
                         .GetProbability(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.AllMountain]),
                3.0/numberOfTargetObject);
            Assert.AreEqual(
                _category.Engine.GetCategoryType(_category.CategoryTypes[TestCategoryFactory.BeginnerCategory])
                         .GetProbability(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Freestyle]),
                2.0/numberOfTargetObject);

            Assert.AreEqual(
                _category.Engine.GetCategoryType(_category.CategoryTypes[TestCategoryFactory.MediumCategory])
                         .GetProbability(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Cheap]),
                0.0/numberOfTargetObject);
        }
예제 #10
0
 public void TestTeachingByObjectToClassify()
 {
     ITargetObject targetObjectOther = new TargetObject(_category, String.Empty);
     _category.Engine.TeachCategory(targetObjectOther);
 }
예제 #11
0
        public void TestTeachCategoryByTargetObject()
        {
            _targetObject.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Cheap]);
            _targetObject.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.AllMountain]);

            _category.Engine.TeachCategory(_targetObject);

            Assert.AreEqual(
                _category.Engine.GetCategoryType(_targetObject.CategoryType)[
                    TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Cheap]], 2);
            Assert.AreEqual(
                _category.Engine.GetCategoryType(_targetObject.CategoryType)[
                    TestCategoryFactory.CategoryAttributes[TestCategoryFactory.AllMountain]], 2);

            ITargetObject targetObjectOther = new TargetObject(_category, _category.CategoryTypes[0]);
            targetObjectOther.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Cheap]);
            targetObjectOther.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Freestyle]);
            targetObjectOther.SetAttributeExist(TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Freeride]);

            _category.Engine.TeachCategory(new List<ITargetObject> {targetObjectOther, _targetObject});

            Assert.AreEqual(
                _category.Engine.GetCategoryType(_targetObject.CategoryType)[
                    TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Freestyle]], 2);
            Assert.AreEqual(
                _category.Engine.GetCategoryType(_targetObject.CategoryType)[
                    TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Freeride]], 2);
            Assert.AreEqual(
                _category.Engine.GetCategoryType(_targetObject.CategoryType)[
                    TestCategoryFactory.CategoryAttributes[TestCategoryFactory.AllMountain]], 3);
            Assert.AreEqual(
                _category.Engine.GetCategoryType(_targetObject.CategoryType)[
                    TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Cheap]], 4);
            Assert.AreEqual(
                _category.Engine.GetCategoryType(_targetObject.CategoryType)[
                    TestCategoryFactory.CategoryAttributes[TestCategoryFactory.Expensive]], 1);
        }
예제 #12
0
        private static void AddNewObjectFromFile(ICategory category, ICollection<ITargetObject> targetObjects,
                                                 TextReader reader)
        {
            string text;
            var attributes = new List<string>();
            string categoryType = String.Empty;
            int count = -1;

            while (!String.Equals(text = reader.ReadLine(), EndObjectCommand))
            {
                switch (text)
                {
                    case CategoryTypeCommand:
                        LoadCategoryType(out categoryType, reader);
                        break;
                    case AttributesCommand:
                        attributes.AddRange(LoadAttributes(reader));
                        break;
                    case CountCommand:
                        count = LoadCount(reader);
                        break;
                }
            }

            if (count <= 0 || String.IsNullOrEmpty(categoryType) || attributes.Count == 0)
            {
                throw new InvalidDataException(
                    "Count of the new object must be higher than 0, categoryType cannot be null or empty and number of attributes must higher than 0.");
            }

            ITargetObject targetObject = new TargetObject(category, categoryType);

            foreach (string attribute in attributes)
            {
                targetObject.SetAttributeExist(attribute);
            }

            for (int i = 0; i < count; i++)
            {
                targetObjects.Add(targetObject);
            }
        }