Пример #1
0
        public void Classification_Resolver_2_3()
        {
            var space = new CSpace();
            var cl1   = new CClass()
            {
                Name = "Plus"
            };
            var cl2 = new CClass()
            {
                Name = "Minus"
            };
            var cl3 = new CClass()
            {
                Name = "AbsMinus"
            };

            space.Classes.Add(cl1);
            space.Classes.Add(cl2);
            space.Classes.Add(cl3);

            // 1 четверть
            space.Objects.Add(CObjectFactory.GetFromProperties(cl1, new { x = 1, y = 1 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl1, new { x = 1, y = 2 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl1, new { x = 2, y = 1 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl1, new { x = 2, y = 2 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl1, new { x = 3, y = 3 }, "x", "y"));

            // 2 четверть
            space.Objects.Add(CObjectFactory.GetFromProperties(cl2, new { x = -1, y = 1 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl2, new { x = -1, y = 2 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl2, new { x = -2, y = 1 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl2, new { x = -2, y = 2 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl2, new { x = -3, y = 3 }, "x", "y"));

            // 3 четверть
            space.Objects.Add(CObjectFactory.GetFromProperties(cl3, new { x = -1, y = -1 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl3, new { x = -1, y = -2 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl3, new { x = -2, y = -1 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl3, new { x = -2, y = -2 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl3, new { x = -3, y = -3 }, "x", "y"));

            var resolver = new CResolver(space);
            var objCl1   = resolver.Resolve(CObjectFactory.GetFromProperties(new { x = 4, y = 4 }, "x", "y"));
            var objCl2   = resolver.Resolve(CObjectFactory.GetFromProperties(new { x = -4, y = -4 }, "x", "y"));
            var objCl3   = resolver.Resolve(CObjectFactory.GetFromProperties(new { x = -4, y = 4 }, "x", "y"));

            Assert.IsNotNull(objCl1);
            Assert.IsNotNull(objCl2);
            Assert.IsNotNull(objCl3);
            Assert.AreEqual("Plus", objCl1.Name);
            Assert.AreEqual("AbsMinus", objCl2.Name);
            Assert.AreEqual("Minus", objCl3.Name);
        }
Пример #2
0
        public void ClassificationIris_Test2()
        {
            var cult     = new CultureInfo("en-US");
            var lines    = System.IO.File.ReadAllLines("iris.data");
            var irisList = lines.Select(i =>
            {
                var irisItem = i.Split(',');
                return(new IrisItem()
                {
                    SepalLength = Convert.ToDecimal(irisItem[0], cult),
                    SepalWidth = Convert.ToDecimal(irisItem[1], cult),
                    PetalLength = Convert.ToDecimal(irisItem[2], cult),
                    PetalWidth = Convert.ToDecimal(irisItem[3], cult),
                    ClassName = irisItem[4]
                });
            }).ToList();

            var classes = irisList.Select(i => i.ClassName).Distinct().Select(i => new CClass()
            {
                Name = i
            }).ToList();

            var space = new CSpace();

            space.Classes.AddRange(classes);
            foreach (var irisItem in irisList)
            {
                var objCl = classes.First(i => i.Name == irisItem.ClassName);
                var obj   = CObjectFactory.GetFromProperties(objCl, irisItem, "SepalLength", "SepalWidth", "PetalLength", "PetalWidth");
                space.Objects.Add(obj);
            }

            List <CObject> unknownObjects = new List <CObject>();

            foreach (var cl in space.Classes)
            {
                var objToRemove = space.Objects.Where(i => i.Class == cl).Take(10).ToList();
                unknownObjects.AddRange(objToRemove);
                foreach (var obj in objToRemove)
                {
                    space.Objects.Remove(obj);
                }
            }

            var resolver = new CResolver(space);

            int allCnt      = unknownObjects.Count;
            int resolvedCnt = 0;

            foreach (var obj in unknownObjects)
            {
                var result = resolver.Resolve(obj);
                if (result == obj.Class)
                {
                    resolvedCnt++;
                }
            }
            Assert.IsTrue(resolvedCnt * 1.0 / allCnt > 0.1);
        }
Пример #3
0
        public void Classification_Resolver_2_4()
        {
            var space = new CSpace();

            var senior = new CClass()
            {
                Name = "Старший разработчик"
            };
            var middle = new CClass()
            {
                Name = "Средний разработчик"
            };
            var junior = new CClass()
            {
                Name = "Младший разработчик"
            };

            space.Classes.Add(senior);
            space.Classes.Add(middle);
            space.Classes.Add(junior);

            space.Objects.Add(CObjectFactory.GetFromProperties(senior, new { codePoints = 6, databasePoints = 5, experience = 21, education = 4 }, "codePoints", "databasePoints", "experience", "education"));

            space.Objects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 5, databasePoints = 3, experience = 20, education = 4 }, "codePoints", "databasePoints", "experience", "education"));

            space.Objects.Add(CObjectFactory.GetFromProperties(junior, new { codePoints = 2, databasePoints = 1, experience = 9, education = 3 }, "codePoints", "databasePoints", "experience", "education"));

            List <CObject> unknownObjects = new List <CObject>();

            unknownObjects.Add(CObjectFactory.GetFromProperties(senior, new { codePoints = 7, databasePoints = 5, experience = 120, education = 5 }, "codePoints", "databasePoints", "experience", "education"));
            unknownObjects.Add(CObjectFactory.GetFromProperties(senior, new { codePoints = 6, databasePoints = 4, experience = 25, education = 4 }, "codePoints", "databasePoints", "experience", "education"));


            unknownObjects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 4, databasePoints = 4, experience = 25, education = 4 }, "codePoints", "databasePoints", "experience", "education"));
            unknownObjects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 3, databasePoints = 3, experience = 19, education = 3 }, "codePoints", "databasePoints", "experience", "education"));
            unknownObjects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 5, databasePoints = 3, experience = 19, education = 3 }, "codePoints", "databasePoints", "experience", "education"));

            unknownObjects.Add(CObjectFactory.GetFromProperties(junior, new { codePoints = 4, databasePoints = 2, experience = 7, education = 4 }, "codePoints", "databasePoints", "experience", "education"));
            unknownObjects.Add(CObjectFactory.GetFromProperties(junior, new { codePoints = 2, databasePoints = 3, experience = 9, education = 3 }, "codePoints", "databasePoints", "experience", "education"));

            CResolver resolver = new CResolver(space);

            int verifiedCount = 0;

            foreach (var obj in unknownObjects)
            {
                var calcClass = resolver.Resolve(obj);
                if (calcClass != null && calcClass.Equals(obj.Class))
                {
                    verifiedCount++;
                }
            }

            Assert.IsTrue(verifiedCount * 1.0 / unknownObjects.Count > 0.5);
        }
Пример #4
0
        public void ClassificationIris_Test()
        {
            var cult     = new CultureInfo("en-US");
            var lines    = System.IO.File.ReadAllLines("iris.data");
            var irisList = lines.Select(i =>
            {
                var irisItem = i.Split(',');
                return(new IrisItem()
                {
                    SepalLength = Convert.ToDecimal(irisItem[0], cult),
                    SepalWidth = Convert.ToDecimal(irisItem[1], cult),
                    PetalLength = Convert.ToDecimal(irisItem[2], cult),
                    PetalWidth = Convert.ToDecimal(irisItem[3], cult),
                    ClassName = irisItem[4]
                });
            }).ToList();

            var classes = irisList.Select(i => i.ClassName).Distinct().Select(i => new CClass()
            {
                Name = i
            }).ToList();

            var space = new CSpace();

            space.Classes.AddRange(classes);
            foreach (var irisItem in irisList)
            {
                var objCl = classes.First(i => i.Name == irisItem.ClassName);
                var obj   = CObjectFactory.GetFromProperties(objCl, irisItem, "SepalLength", "SepalWidth", "PetalLength", "PetalWidth");
                space.Objects.Add(obj);
            }

            int validCnt = 0;
            var resolver = new CResolver(space);

            var newIris1 = new IrisItem()
            {
                SepalLength = 5, SepalWidth = 3.5m, PetalLength = 1.5m, PetalWidth = 0.2m
            };
            var result1 = resolver.Resolve(CObjectFactory.GetFromProperties(newIris1, "SepalLength", "SepalWidth", "PetalLength", "PetalWidth"));

            //Assert.AreEqual(result1.Name, "Iris-setosa");
            if (result1 != null && result1.Name == "Iris-setosa")
            {
                validCnt++;
            }

            var newIris2 = new IrisItem()
            {
                SepalLength = 6, SepalWidth = 2.7m, PetalLength = 4m, PetalWidth = 1.3m
            };
            var result2 = resolver.Resolve(CObjectFactory.GetFromProperties(newIris2, "SepalLength", "SepalWidth", "PetalLength", "PetalWidth"));

            //Assert.AreEqual(result2.Name, "Iris-versicolor");
            if (result2 != null && result2.Name == "Iris-versicolor")
            {
                validCnt++;
            }

            var newIris3 = new IrisItem()
            {
                SepalLength = 6.5m, SepalWidth = 3, PetalLength = 5.5m, PetalWidth = 2
            };
            var result3 = resolver.Resolve(CObjectFactory.GetFromProperties(newIris3, "SepalLength", "SepalWidth", "PetalLength", "PetalWidth"));

            //Assert.AreEqual(result3.Name, "Iris-virginica");
            if (result3 != null && result3.Name == "Iris-virginica")
            {
                validCnt++;
            }

            Assert.IsTrue(validCnt > 0);
        }
Пример #5
0
        private void getClassBtn_Click(object sender, EventArgs e)
        {
            try
            {
                var nameValue = string.IsNullOrEmpty(name.Text) ? "Неведомый разработчик" : name.Text;

                int codePointsValue = 0;
                if (!int.TryParse(codePoints.Text, out codePointsValue))
                {
                    throw new Exception($"{codePointsLabel.Text} указано некорректно.");
                }

                int databasePointsValue = 0;
                if (!int.TryParse(databasePoints.Text, out databasePointsValue))
                {
                    throw new Exception($"{databasePointsLabel.Text}  указано некорректно.");
                }

                int experienceValue = 0;
                if (!int.TryParse(experience.Text, out experienceValue))
                {
                    throw new Exception($"{experienceLabel.Text}  указан некорректно.");
                }

                int educationValue = 0;
                if (!int.TryParse(education.Text, out educationValue))
                {
                    throw new Exception($"{educationLabel.Text}  указано некорректно.");
                }

                var space  = new CSpace();
                var senior = new CClass()
                {
                    Name = "Старший разработчик"
                };
                var middle = new CClass()
                {
                    Name = "Средний разработчик"
                };
                var junior = new CClass()
                {
                    Name = "Младший разработчик"
                };

                space.Classes.Add(senior);
                space.Classes.Add(middle);
                space.Classes.Add(junior);

                space.Objects.Add(CObjectFactory.GetFromProperties(senior, new { codePoints = 7, databasePoints = 5, experience = 120, education = 5 }, "codePoints", "databasePoints", "experience", "education"));
                space.Objects.Add(CObjectFactory.GetFromProperties(senior, new { codePoints = 6, databasePoints = 5, experience = 21, education = 4 }, "codePoints", "databasePoints", "experience", "education"));
                space.Objects.Add(CObjectFactory.GetFromProperties(senior, new { codePoints = 6, databasePoints = 4, experience = 25, education = 4 }, "codePoints", "databasePoints", "experience", "education"));

                space.Objects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 5, databasePoints = 3, experience = 20, education = 4 }, "codePoints", "databasePoints", "experience", "education"));
                space.Objects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 4, databasePoints = 4, experience = 25, education = 4 }, "codePoints", "databasePoints", "experience", "education"));
                space.Objects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 3, databasePoints = 3, experience = 19, education = 3 }, "codePoints", "databasePoints", "experience", "education"));
                space.Objects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 5, databasePoints = 3, experience = 19, education = 3 }, "codePoints", "databasePoints", "experience", "education"));

                space.Objects.Add(CObjectFactory.GetFromProperties(junior, new { codePoints = 4, databasePoints = 2, experience = 7, education = 4 }, "codePoints", "databasePoints", "experience", "education"));
                space.Objects.Add(CObjectFactory.GetFromProperties(junior, new { codePoints = 2, databasePoints = 1, experience = 9, education = 3 }, "codePoints", "databasePoints", "experience", "education"));
                space.Objects.Add(CObjectFactory.GetFromProperties(junior, new { codePoints = 2, databasePoints = 3, experience = 9, education = 3 }, "codePoints", "databasePoints", "experience", "education"));

                CResolver resolver = new CResolver(space);
                var       result   = resolver.Resolve(CObjectFactory.GetFromProperties(new { codePoints = codePointsValue, databasePoints = databasePointsValue, experience = experienceValue, education = educationValue }, "codePoints", "databasePoints", "experience", "education"));

                if (result == null)
                {
                    throw new Exception($"{nameValue} относится к неизвестному типу разработчиков.");
                }

                throw new Exception($"{nameValue} - {result.Name}");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }