Пример #1
0
        static void Main(string[] args)
        {
            DictinaryAttribute dictinary = new DictinaryAttribute();


            dictinary.BildNewDictinary(
                new[]
            {
                @"C:\001\002\bad3.txt",
                @"C:\001\002\good3.txt"
            },
                new[]
            {
                ClassTypeValue.Negative,
                ClassTypeValue.Positive,
            }
                );


            // dictinary.LoadDictinaryFrom(@"C:\001\002\");

            // dictinary.SaveAllTo(@"C:\001\002", true);

            SVM svm = new SVM();

            svm.LoadVectorsFromAttribures(dictinary);
            svm.DoWork();

            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }
Пример #2
0
        /// <summary>
        /// Создает обучающие вектора из библиотеки
        /// </summary>
        /// <param name="dictinary">Библиотека</param>
        public void LoadVectorsFromAttribures(DictinaryAttribute dictinary)
        {
            List <Attribute>[]    arrowOFAttrList = dictinary.AttributesListArrow;
            List <ClassTypeValue> textType        = dictinary.TextTypeList;

            int cntText            = dictinary.TextTypeList.Count; // сумарное количество текстов
            int sumLeightOfVectors = 0;                            // сумарное количество всех признаков


            foreach (List <Attribute> attributesList in arrowOFAttrList)
            {
                sumLeightOfVectors += attributesList.Count;

                foreach (Attribute att in attributesList)
                {
                    att.setLeightIsInText(cntText);
                }
            }


            for (int i = 0; VectorList.Count != cntText; i++)
            {
                VectorList.Add(new Node[sumLeightOfVectors]);
                TypeElementVectorList.Add((double)textType[i]);
            }


            int tmpCnt = 0;

            foreach (List <Attribute> attributeList in arrowOFAttrList)
            {
                for (int attrIndex = 0; attrIndex < attributeList.Count; attrIndex++)
                {
                    for (int textIndex = 0; textIndex < cntText; textIndex++)
                    {
                        int  typeOfText = (int)textType[textIndex];
                        Node node       = new Node();
                        node.Index = attrIndex + tmpCnt + 1;

                        if (attributeList[attrIndex].isInText[textIndex])
                        {
                            node.Value = attributeList[attrIndex].weight[typeOfText];
                        }
                        else
                        {
                            node.Value = 0;
                        }

                        VectorList[textIndex][attrIndex + tmpCnt] = node;
                    }
                }

                tmpCnt += attributeList.Count;
            }

            return;
        }