示例#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; }));
            }
        }
示例#2
0
        private void button5_Click_1(object sender, EventArgs e)
        {
            progressBar1.Maximum = dataDouble.Count;

            dataGridView4.Rows[2].Cells[1].Value = dataGridView2.Rows.Count / 100 * Convert.ToDouble(dataGridView4.Rows[1].Cells[1].Value);

            InfaDlyaObnaryjeniyaAnomaliiPCAP infa = new InfaDlyaObnaryjeniyaAnomaliiPCAP();

            infa.data            = dataDouble;
            infa.dolyaNaOby4enie = Convert.ToDouble(dataGridView4.Rows[1].Cells[1].Value);
            infa.nomerDoli       = Convert.ToInt32(dataGridView4.Rows[3].Cells[1].Value);
            infa.porogOcenki     = Convert.ToDouble(dataGridView4.Rows[4].Cells[1].Value);

            Task.Factory.StartNew(() => { obnaryjenieAnomaliiPCAP(infa); }); //Создание и запуск нового потока
        }