Exemplo n.º 1
0
        public static void Serialize(int numberTest, StoredResult obj)
        {
            XmlSerializer formatter = new XmlSerializer(typeof(StoredResult));
            string        fileName  = string.Format("{0}{1}{2}", filePath, numberTest, format);

            using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate))
            {
                formatter.Serialize(fs, obj);
            }
        }
Exemplo n.º 2
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            StoredResult sr = prognostication.NewModel(Convert.ToInt32(comboBoxNumberTest.Text));

            txtBoxResult.Clear();
            btnPredict.Enabled      = true;
            labelAlg.Text           = sr.algorithm;
            labelCountClusters.Text = sr.countClusters.ToString();
            labelStay.Text          = sr.stayedPlayers[2].ToString();
            labelLeave.Text         = sr.leavePlayers[2].ToString();
        }
Exemplo n.º 3
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            countTest = new DirectoryInfo(@"Save\Test").GetFiles().Length;
            if (File.Exists(@"Save\Data.txt"))
            {
                labelData.Text = "У вас уже есть обработанные данные.";
                DataLoadingEnabled(false);
                btnWork.Enabled = false;
                for (int i = 1; i <= countTest; i++)
                {
                    StoredResult sr     = DataStore.Deserialize(i);
                    int          indRow = gridResult.Rows.Add();
                    gridResult.Rows[indRow].Cells[0].Value = i;
                    gridResult.Rows[indRow].Cells[1].Value = sr.silhouette;
                    gridResult.Rows[indRow].Cells[2].Value = sr.Qmetrics;
                    gridResult.Rows[indRow].Cells[3].Value = sr.Bmetrics;
                    gridResult.Rows[indRow].Cells[4].Value = sr.stayedPlayers[2];
                    gridResult.Rows[indRow].Cells[5].Value = sr.leavePlayers[2];

                    comboBoxNumberTest.Items.Add(i);
                    cmbBoxJsonTest.Items.Add(i);
                }

                if (countTest >= 1)
                {
                    comboBoxNumberTest.SelectedIndex = 0;
                    cmbBoxJsonTest.SelectedIndex     = 0;
                }
                else
                {
                    btnOk.Enabled = false;
                }
            }
            else
            {
                labelData.Text          = "У вас еще нет обработанных данных.";
                checkBoxNewData.Enabled = false;
            }

            btnPredict.Enabled = false;
        }
Exemplo n.º 4
0
        public StoredResult NewModel(int numberTest)
        {
            this.numberTest = numberTest;
            string       fileName = clustersPath + numberTest + ".txt";
            StreamReader sr       = new StreamReader(fileName);

            countClusters = Convert.ToInt32(sr.ReadLine());
            for (int i = 0; i < countClusters; i++)
            {
                double[] f   = new double[countFeatures];
                var      arr = sr.ReadLine().Split(' ');
                for (int j = 0; j < countFeatures; j++)
                {
                    f[j] = Convert.ToDouble(arr[j].Replace('.', ','));
                }
                model.Add(f);
            }

            storedResult = DataStore.Deserialize(numberTest);
            return(storedResult);
        }
Exemplo n.º 5
0
        public static void SerializeJSON(string fileName, int numberTest)
        {
            int            countClusters = 0;
            List <Cluster> listClusters  = new List <Cluster>();

            StoredResult testResult = Deserialize(numberTest);

            countClusters = testResult.countClusters;
            listClusters  = ModelClusters(fileName, countClusters);
            int[] clusters = new int[countClusters];
            for (int i = 0; i < testResult.clusters.Count; i++)
            {
                clusters[i] = testResult.clusters[i].leaveCount + testResult.clusters[i].stayCount;
            }

            for (int i = 0; i < countClusters; i++)
            {
                Graph1 g = new Graph1();
                g.nodes = new Node1[clusters[i]];
                int id = 1;
                for (int j = 0; j < clusters[i]; j++)
                {
                    g.nodes[j]       = new Node1();
                    g.nodes[j].id    = id;
                    g.nodes[j].label = "Игрок " + id;
                    id++;
                }

                double[,] matrix = MatrixDist(clusters[i], listClusters[i]);
                if (i + 1 == 13)
                {
                }
                string[,] tooltip = MatrixTooltip(clusters[i], listClusters[i]);
                g.edges           = new Edge1[clusters[i] * (clusters[i] - 1)];
                int ind = 0;
                for (int j = 0; j < clusters[i]; j++)
                {
                    for (int k = 0; k < clusters[i]; k++)
                    {
                        if (j != k)
                        {
                            g.edges[ind]         = new Edge1();
                            g.edges[ind].source  = j + 1;
                            g.edges[ind].target  = k + 1;
                            g.edges[ind].weight  = matrix[j, k];
                            g.edges[ind].tooltip = tooltip[j, k];
                            ind++;
                        }
                    }
                }

                string ser = JsonConvert.SerializeObject(g);
                using (StreamWriter sw = new StreamWriter("Json\\Graph" + (i + 1).ToString() + ".js"))
                {
                    sw.Write(ser);
                }
            }

            /*Создание файла для второй диаграммы*/
            SerializeJSON2(numberTest, countClusters);
        }
Exemplo n.º 6
0
        public static void SerializeJSON2(int nmbTest, int countClusters)
        {
            StoredResult stored = Deserialize(nmbTest);
            string       path   = "Json2\\Graph";
            int          id     = 1;

            double[,] matrix   = MatrixAverageCluster(countClusters, nmbTest);
            double[,] matrix_n = MatrixAverageCluster_n(countClusters, nmbTest);
            string[] names = new string[countClusters];
            for (int i = 0; i < countClusters; i++)
            {
                names[i] = "Кластер " + (i + 1).ToString();
            }
            Graph2 g = new Graph2();

            g.nodes = new Node2[countClusters + 14];
            g.edges = new Edge1[countClusters * 14 * 2];
            for (int i = 0; i < countClusters; i++)
            {
                g.nodes[i]       = new Node2();
                g.nodes[i].id    = id;
                g.nodes[i].label = names[i];
                if (stored.clusters[i].metka == 1)
                {
                    g.nodes[i].class_ = 3;
                }
                else
                {
                    g.nodes[i].class_ = 4;
                }
                id++;
            }
            for (int i = 0; i < 14; i++)
            {
                g.nodes[i + countClusters]        = new Node2();
                g.nodes[i + countClusters].id     = id;
                g.nodes[i + countClusters].label  = features[i];
                g.nodes[i + countClusters].class_ = 1;
                id++;
            }
            int ind = 0;

            for (int i = 0; i < countClusters; i++)
            {
                for (int j = 0; j < 14; j++)
                {
                    g.edges[ind]         = new Edge1();
                    g.edges[ind].source  = i + 1;
                    g.edges[ind].target  = countClusters + j + 1;
                    g.edges[ind].weight  = matrix_n[i, j];
                    g.edges[ind].tooltip = matrix[i, j].ToString();
                    ind++;
                }
            }
            for (int i = 0; i < 14; i++)
            {
                for (int j = 0; j < countClusters; j++)
                {
                    g.edges[ind]         = new Edge1();
                    g.edges[ind].source  = countClusters + i + 1;
                    g.edges[ind].target  = j + 1;
                    g.edges[ind].weight  = matrix_n[j, i];
                    g.edges[ind].tooltip = matrix[j, i].ToString();
                    ind++;
                }
            }

            string ser = JsonConvert.SerializeObject(g);

            using (StreamWriter sw = new StreamWriter("Json2\\Graph.js"))
            {
                sw.Write(ser);
            }
        }
Exemplo n.º 7
0
        private void FillTables()
        {
            StoredResult sr  = DataStore.Deserialize(numbTest);
            int          ind = gridMatrixErr.Rows.Add();

            gridMatrixErr.Rows[ind].Cells[0].Value = "Остался";
            gridMatrixErr.Rows[ind].Cells[1].Value = sr.stayedPlayers[0];
            gridMatrixErr.Rows[ind].Cells[2].Value = sr.stayedPlayers[1];
            gridMatrixErr.Rows[ind].Cells[3].Value = sr.stayedPlayers[2];
            ind = gridMatrixErr.Rows.Add();
            gridMatrixErr.Rows[ind].Cells[0].Value = "Ушел";
            gridMatrixErr.Rows[ind].Cells[1].Value = sr.leavePlayers[0];
            gridMatrixErr.Rows[ind].Cells[2].Value = sr.leavePlayers[1];
            gridMatrixErr.Rows[ind].Cells[3].Value = sr.leavePlayers[2];

            ind = gridMetrics.Rows.Add();
            gridMetrics.Rows[ind].Cells[0].Value = sr.silhouette;
            gridMetrics.Rows[ind].Cells[1].Value = sr.Qmetrics;
            gridMetrics.Rows[ind].Cells[2].Value = sr.Bmetrics;

            for (int i = 0; i < sr.countClusters; i++)
            {
                ind = gridPercent.Rows.Add();
                gridPercent.Rows[ind].Cells[0].Value = sr.clusters[i].number;
                gridPercent.Rows[ind].Cells[1].Value = sr.clusters[i].leaveCount;
                gridPercent.Rows[ind].Cells[2].Value = sr.clusters[i].stayCount;
                gridPercent.Rows[ind].Cells[3].Value = sr.clusters[i].metka;
                gridPercent.Rows[ind].Cells[4].Value = sr.clusters[i].errors;
            }

            ind = gridParams.Rows.Add();
            gridParams[0, ind].Value = "Алгоритм";
            gridParams[1, ind].Value = sr.algorithm;
            ind = gridParams.Rows.Add();
            gridParams[0, ind].Value = "Количество кластеров";
            gridParams[1, ind].Value = sr.countClusters;
            ind = gridParams.Rows.Add();
            gridParams[0, ind].Value = "Нормализация";
            if (sr.normalization)
            {
                gridParams[1, ind].Value = "Да";
            }
            else
            {
                gridParams[1, ind].Value = "Нет";
            }

            switch (sr.algorithm)
            {
            case "Hierarchical agglomerative":
                ind = gridParams.Rows.Add();
                gridParams[0, ind].Value = "Метрика";
                gridParams[1, ind].Value = sr.metrcis;
                ind = gridParams.Rows.Add();
                gridParams[0, ind].Value = "Связь";
                gridParams[1, ind].Value = sr.link;
                break;

            case "KMeans":
                ind = gridParams.Rows.Add();
                gridParams[0, ind].Value = "Метод инициализации";
                gridParams[1, ind].Value = sr.init;

                ind = gridParams.Rows.Add();
                gridParams[0, ind].Value = "Алгоритм";
                gridParams[1, ind].Value = sr.alg;
                break;

            case "DBSCAN":
                ind = gridParams.Rows.Add();
                gridParams[0, ind].Value = "Eps-окрестность";
                gridParams[1, ind].Value = sr.eps;
                ind = gridParams.Rows.Add();
                gridParams[0, ind].Value = "Min samples";
                gridParams[1, ind].Value = sr.minSample;
                break;

            case "Affinity Propagation":
                ind = gridParams.Rows.Add();
                gridParams[0, ind].Value = "Damping коэффициент";
                gridParams[1, ind].Value = sr.damping;
                ind = gridParams.Rows.Add();
                gridParams[0, ind].Value = "Max_iter";
                gridParams[1, ind].Value = sr.maxIter;
                ind = gridParams.Rows.Add();
                gridParams[0, ind].Value = "Convergence_iter";
                gridParams[1, ind].Value = sr.convergIter;
                break;
            }
        }
Exemplo n.º 8
0
        private void SaveTest_()
        {
            countTest++;
            StoredResult sr = new StoredResult(gridErrors.Rows.Count);

            sr.silhouette       = Convert.ToDouble(gridMetrics.Rows[0].Cells[0].Value);
            sr.Qmetrics         = Convert.ToDouble(gridMetrics.Rows[0].Cells[1].Value);
            sr.Bmetrics         = Convert.ToDouble(gridMetrics.Rows[0].Cells[2].Value);
            sr.algorithm        = cmbBoxAlg.Text;
            sr.stayedPlayers[0] = Convert.ToDouble(gridMatrixErrors.Rows[0].Cells[1].Value);
            sr.stayedPlayers[1] = Convert.ToDouble(gridMatrixErrors.Rows[0].Cells[2].Value);
            sr.stayedPlayers[2] = Convert.ToDouble(gridMatrixErrors.Rows[0].Cells[3].Value);
            sr.leavePlayers[0]  = Convert.ToDouble(gridMatrixErrors.Rows[1].Cells[1].Value);
            sr.leavePlayers[1]  = Convert.ToDouble(gridMatrixErrors.Rows[1].Cells[2].Value);
            sr.leavePlayers[2]  = Convert.ToDouble(gridMatrixErrors.Rows[1].Cells[3].Value);
            for (int i = 0; i < gridErrors.Rows.Count; i++)
            {
                sr.AddCluster(Convert.ToInt32(gridErrors.Rows[i].Cells[0].Value),
                              Convert.ToInt32(gridErrors.Rows[i].Cells[1].Value),
                              Convert.ToInt32(gridErrors.Rows[i].Cells[2].Value),
                              Convert.ToInt32(gridErrors.Rows[i].Cells[3].Value),
                              Convert.ToDouble(gridErrors.Rows[i].Cells[4].Value));
            }
            sr.normalization = checkBoxNormal.Checked;
            switch (cmbBoxAlg.Text)
            {
            case "Hierarchical agglomerative":
                sr.metrcis = cmbBoxMetric.Text;
                sr.link    = cmbBoxLink.Text;
                break;

            case "KMeans":
                sr.init = cmbBoxInit.Text;
                sr.alg  = cmbBoxAlgMeans.Text;
                break;

            case "Affinity Propagation":
                sr.damping     = Convert.ToDouble(txtBoxDamping.Text);
                sr.maxIter     = Convert.ToInt32(txtBoxMaxIter.Text);
                sr.convergIter = Convert.ToInt32(txtBoxConvergIter.Text);
                break;

            case "DBSCAN":
                sr.eps       = Convert.ToDouble(txtBoxEps.Text);
                sr.minSample = Convert.ToInt32(txtBoxMinSamples.Text);
                break;
            }
            DataStore.Serialize(countTest, sr);
            int indRow = gridResult.Rows.Add();

            gridResult.Rows[indRow].Cells[0].Value = countTest;
            gridResult.Rows[indRow].Cells[1].Value = sr.silhouette;
            gridResult.Rows[indRow].Cells[2].Value = sr.Qmetrics;
            gridResult.Rows[indRow].Cells[3].Value = sr.Bmetrics;
            gridResult.Rows[indRow].Cells[4].Value = sr.stayedPlayers[2];
            gridResult.Rows[indRow].Cells[5].Value = sr.leavePlayers[2];

            comboBoxNumberTest.Items.Add(countTest);
            comboBoxNumberTest.SelectedIndex = comboBoxNumberTest.Items.Count - 1;
            cmbBoxJsonTest.Items.Add(countTest);
            cmbBoxJsonTest.SelectedIndex = cmbBoxJsonTest.Items.Count - 1;
        }