Exemplo n.º 1
0
        public void obnaryjenieAnomaliiPCAP(object a)
        {
            InfaDlyaObnaryjeniyaAnomaliiPCAP infa     = (InfaDlyaObnaryjeniyaAnomaliiPCAP)a;
            List <List <Double> >            testData = infa.data; //обучающие данные
            int koli4estvoNaOby4enie        = Convert.ToInt32(testData.Count / 100 * infa.dolyaNaOby4enie);
            List <List <Double> > trainData = new List <List <double> >(koli4estvoNaOby4enie);

            for (int i = 0; i < koli4estvoNaOby4enie; i++)
            {
                trainData.Add(testData[infa.nomerDoli * koli4estvoNaOby4enie + i]);
            }

            /*
             *          Calling isolationForestAlgorithm with input data, number of trees which is roughly taken to be
             *          20% of number of data points and sub sampling size which is taken as 10% of number of data points.
             * (входные (обучающие) данные, количество деревьев, размер подвыборки для ДР)
             */
            isolationForestAlgorithm isolationForestAlgorithm = new isolationForestAlgorithm();

            label1.Invoke((Action)(() => { label1.Text = "Обучение леса..."; }));

            //Можно поиграть с параметрами
            List <Tree> forest = isolationForestAlgorithm.buildForest(trainData, 100, koli4estvoNaOby4enie);  //(data, data.size() / 5, data.size() / 10); //оригинал

            /*
             *          Calculating anomalyScore for each data point in input data. This is calculated for each data point
             *          by calculating the average of the path length for each point.
             */
            anomalyScore anomalyScore = new anomalyScore();

            for (int i = 0; i < testData.Count; i++)
            {
                double score = anomalyScore.Calculating(forest, testData[i], testData.Count); //Оценка аномалии
                int    flagAnomalii;

                if (score > infa.porogOcenki)
                {
                    flagAnomalii = 1;
                }
                else
                {
                    flagAnomalii = 0;
                }

                dataGridView2.Invoke((Action)(() =>
                {
                    dataGridView2.Rows[i].Cells[4].Value = score;
                    dataGridView2.Rows[i].Cells[5].Value = flagAnomalii;
                })); //Добавление строки в таблицу

                label1.Invoke((Action)(() => { label1.Text = "Обработано данных:" + i + "/" + testData.Count; }));
                progressBar1.Invoke((Action)(() => { progressBar1.Value = i; }));
            }
        }
Exemplo n.º 2
0
        public void obnaryjenieAnomaliiARFF(object a)
        {
            InfaDlyaObnaryjeniyaAnomaliiARFF infa      = (InfaDlyaObnaryjeniyaAnomaliiARFF)a;
            List <List <Double> >            dataTrain = infa.dataTrain; //обучающие данные
            List <List <Double> >            dataTest  = infa.dataTest;  //обучающие данные

            DateTime dateTime;                                           //время

            /*
             *          Calling isolationForestAlgorithm with input data, number of trees which is roughly taken to be
             *          20% of number of data points and sub sampling size which is taken as 10% of number of data points.
             * (входные (обучающие) данные, количество деревьев, размер подвыборки для ДР)
             */
            isolationForestAlgorithm isolationForestAlgorithm = new isolationForestAlgorithm();

            label1.Invoke((Action)(() => { label1.Text = "Обучение леса..."; }));

            dateTime = DateTime.Now;

            //Можно поиграть с параметрами
            List <Tree> forest = isolationForestAlgorithm.buildForest(dataTrain, 100, Convert.ToInt32(dataTrain.Count * 0.66));  //(data, data.size() / 5, data.size() / 10); //оригинал

            textBoxLog.Invoke((Action)(() =>
            {
                textBoxLog.Text += "Количество элементов на обучение" + dataTrain.Count;
                textBoxLog.Text += "Время обучения" + (DateTime.Now - dateTime);
            })); //Вывод времени обучения

            /*
             *          Calculating anomalyScore for each data point in input data. This is calculated for each data point
             *          by calculating the average of the path length for each point.
             */
            anomalyScore anomalyScore = new anomalyScore();

            dataGridView6.Invoke((Action)(() =>
            {
                dataGridView6.Columns.Add("columns6_Score", "Оценка аномалии");
                //dataGridView6.Columns.Add("columns6_flagAnomalii", "Флаг аномалии");
            })); //Добавление строки в таблицу

            int countDataTest = dataTest.Count;

            ocenkaAnomalii = new double[countDataTest];

            dateTime = DateTime.Now;

            for (int i = 0; i < countDataTest; i++)
            {
                ocenkaAnomalii[i] = anomalyScore.Calculating(forest, dataTest[i], countDataTest); //Оценка аномалии

                dataGridView6.Invoke((Action)(() =>
                {
                    dataGridView6.Rows[i].Cells[dataGridView6.Columns.Count - 1].Value = ocenkaAnomalii[i];
                })); //Добавление строки в таблицу

                label1.Invoke((Action)(() => { label1.Text = "Обработано данных:" + i + "/" + countDataTest; }));
                progressBar1.Invoke((Action)(() => { progressBar1.Value = i; }));
            }

            textBoxLog.Invoke((Action)(() =>
            {
                textBoxLog.Text += "Количесвто элементов на тестирование" + countDataTest;
                textBoxLog.Text += "Время тестирования" + (DateTime.Now - dateTime);
            })); //Вывод времени тестирования
        }