示例#1
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);
        }
示例#2
0
 /// <summary>
 /// Create a TweenPos Component and start a tween
 /// </summary>
 /// <param name="go">GameObject to apply tween too</param>
 /// <param name="duration">Duration of tween</param>
 /// <param name="pos">The ending value for the tween</param>
 /// <param name="finished">A optional Callback to fire when the tween is done</param>
 /// <param name="cSpace">A optional Arugmeant to define the coordnaite space to work in</param>
 /// <returns>Return reference to the new TweenPos component</returns>
 public static TweenPos Tween(GameObject go, float duration, Vector3 pos, UnityAction finished = null, CSpace cSpace = CSpace.Anchored)
 {
     TweenPos cls = TweenMain.Tween<TweenPos>(go, duration, finished);
     cls.CSpace = cSpace;
     cls.from = cls.value;
     cls.to = pos;
     cls.Start();
     return cls;
 }
        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);
        }
        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);
        }
示例#5
0
        public MechanismCSpace(Mechanisms mechanism, SceneBoxes scene)
        {
            this.mechanism = mechanism;
            this.scene = scene;

            double[] dimensionLowLimit = new double[mechanism.Joints.Count];
            double[] dimensionHighLimit = new double[mechanism.Joints.Count];
            double[] dimensionWeight = new double[mechanism.Joints.Count];
            for (int i = 0; i < mechanism.Joints.Count; i++)
            {
                dimensionLowLimit[i] = -180;
                dimensionHighLimit[i] = 180;
                dimensionWeight[i] = 1;

            }

            this.cSpace = new CSpace(mechanism.Joints.Count, dimensionLowLimit, dimensionHighLimit, dimensionWeight, CheckCollision);
        }
示例#6
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);
        }
示例#7
0
 /// <summary>
 /// Create a TweenPos Component and start a tween
 /// </summary>
 /// <param name="go">GameObject to apply tween too</param>
 /// <param name="duration">Duration of tween</param>
 /// <param name="fromVal">The starting value for the tween</param>
 /// <param name="toVal">The ending value for the tween</param>
 /// <param name="finished">A optional Callback to fire when the tween is done</param>
 /// <param name="cSpace">A optional Arugmeant to define the coordnaite space to work in</param>
 /// <returns>Return reference to the new TweenPos component</returns>
 public static TweenPos Tween(GameObject go, float duration, Vector3 fromVal, Vector3 toVal,
                              UnityAction finished = null, CSpace cSpace = CSpace.Anchored)
 {
     return(Tween(go, duration, fromVal, toVal, Style.Once, Method.Linear, finished, cSpace));
 }
示例#8
0
        /// <summary>
        /// Create a TweenPos Component and start a tween
        /// </summary>
        /// <param name="go">GameObject to apply tween too</param>
        /// <param name="duration">Duration of tween</param>
        /// <param name="pos">The ending value for the tween</param>
        /// <param name="finished">A optional Callback to fire when the tween is done</param>
        /// <param name="cSpace">A optional Arugmeant to define the coordnaite space to work in</param>
        /// <returns>Return reference to the new TweenPos component</returns>
        public static TweenPos Tween(GameObject go, float duration, Vector3 pos, UnityAction finished = null, CSpace cSpace = CSpace.Anchored)
        {
            TweenPos cls = TweenMain.Tween <TweenPos>(go, duration, finished);

            cls.CSpace = cSpace;
            cls.from   = cls.value;
            cls.to     = pos;
            cls.Start();
            return(cls);
        }
示例#9
0
        /// <summary>
        /// Create a TweenPos Component and start a tween
        /// </summary>
        /// <param name="go">GameObject to apply tween too</param>
        /// <param name="duration">Duration of tween</param>
        /// <param name="fromVal">The starting value for the tween</param>
        /// <param name="toVal">The ending value for the tween</param>
        /// <param name="style">The style of tween (Once, Looped, PingPong)</param>
        /// <param name="method">The Interpolation method of the tween</param>
        /// <param name="finished">A optional Callback to fire when the tween is done</param>
        /// <param name="cSpace">A optional Arugmeant to define the coordnaite space to work in</param>
        /// <returns>Return reference to the new TweenPos component</returns>
        public static TweenPos Tween(GameObject go, float duration, Vector3 fromVal, Vector3 toVal,
                                     Style style, Method method, UnityAction finished = null, CSpace cSpace = CSpace.Anchored)
        {
            TweenPos cls = TweenMain.Tween <TweenPos>(go, duration, style, method, finished);

            cls.CSpace = cSpace;
            cls.from   = fromVal;
            cls.to     = toVal;
            cls.Start();
            return(cls);
        }
示例#10
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);
            }
        }
示例#11
0
 /// <summary>
 /// Create a TweenPos Component and start a tween
 /// </summary>
 /// <param name="go">GameObject to apply tween too</param>
 /// <param name="duration">Duration of tween</param>
 /// <param name="fromVal">The starting value for the tween</param>
 /// <param name="toVal">The ending value for the tween</param>
 /// <param name="style">The style of tween (Once, Looped, PingPong)</param>
 /// <param name="method">The Interpolation method of the tween</param>
 /// <param name="finished">A optional Callback to fire when the tween is done</param>
 /// <param name="cSpace">A optional Arugmeant to define the coordnaite space to work in</param>
 /// <returns>Return reference to the new TweenPos component</returns>
 public static TweenPos Tween(GameObject go, float duration, Vector3 fromVal, Vector3 toVal,
     Style style, Method method, UnityAction finished = null, CSpace cSpace = CSpace.Anchored)
 {
     TweenPos cls = TweenMain.Tween<TweenPos>(go, duration, style, method, finished);
     cls.CSpace = cSpace;
     cls.from = fromVal;
     cls.to = toVal;
     cls.Start();
     return cls;
 }
示例#12
0
 /// <summary>
 /// Create a TweenPos Component and start a tween
 /// </summary>
 /// <param name="go">GameObject to apply tween too</param>
 /// <param name="duration">Duration of tween</param>
 /// <param name="fromVal">The starting value for the tween</param>
 /// <param name="toVal">The ending value for the tween</param>
 /// <param name="finished">A optional Callback to fire when the tween is done</param>
 /// <param name="cSpace">A optional Arugmeant to define the coordnaite space to work in</param>
 /// <returns>Return reference to the new TweenPos component</returns>
 public static TweenPos Tween(GameObject go, float duration, Vector3 fromVal, Vector3 toVal,
     UnityAction finished = null, CSpace cSpace = CSpace.Anchored)
 {
     return Tween(go, duration, fromVal, toVal, Style.Once, Method.Linear, finished, cSpace);
 }