Пример #1
0
        private void button1_Click_2(object sender, EventArgs e)// MRMR Reduce button
        {
            NRReduce.Enabled   = false;
            MRMRReduce.Enabled = false;

            List <double> Xi = new List <double>();
            List <double> Xj = new List <double>();
            List <string> RED = new List <string>(), tempRED = new List <string>();
            Dictionary <string, double> allNR = new Dictionary <string, double>();// Store the neighbor relevance to decision value of all conditions

            string bestRED = "";
            string colName = "";
            double radius = 0.05;// threshold
            long   neighborDAmount = 0, neighborAmount = 0;
            double NU = 0.0;
            double Pos = 0.0;
            double tempMrmrValue = 0.0, mrmrValue = 0.0, bestMrmrValue = 0.0;
            bool   flag = false;
            int    conditionAmount = 1;// Counting the times do while loop

            do
            {
                for (int curr_col = 0; curr_col <= DV.Table.Columns.Count - 2; ++curr_col)//Except the dicision column
                {
                    Pos     = 0.0;
                    colName = DV.Table.Columns[curr_col].ColumnName;
                    if (RED.Contains(colName))
                    {
                        continue;
                    }

                    if (conditionAmount == 1)// Same as Neighbor Reduce
                    {
                        // Only computing a single condition
                        for (int selected_row = 0; selected_row <= DV.Table.Rows.Count - 1; ++selected_row)
                        {
                            neighborAmount = neighborDAmount = 0;
                            retrieveOneRow(Xi, RED, selected_row, curr_col);
                            for (int contrast_row = 0; contrast_row <= DV.Table.Rows.Count - 1; ++contrast_row)
                            {
                                retrieveOneRow(Xj, RED, contrast_row, curr_col);
                                if (euclidean_distance(Xi, Xj) <= radius * radius)
                                {// current instance is a neighbor
                                    ++neighborAmount;
                                    string decisionValue = DV[contrast_row][DV.Table.Columns.Count - 1].ToString();
                                    if (decisionValue == DV[selected_row][DV.Table.Columns.Count - 1].ToString())// Two rows have same decision value
                                    {
                                        ++neighborDAmount;
                                    }
                                }
                            }
                            NU   = (neighborDAmount * 1.0) / neighborAmount;
                            Pos += NU;
                        }

                        double tempNR = Pos / DV.Count;
                        allNR.Add(colName, tempNR);     // Collect the NR of all condition
                        if (tempNR > allNR[tempRED[0]]) // tempRED only have one single element
                        {
                            if (tempRED.Count > conditionAmount - 1)
                            {
                                tempRED.RemoveAt(tempRED.Count - 1);
                            }                     // Drop the rear element of old optimal RED in the previous for(curr_col) loop
                            tempRED.Add(colName); // 第一个被收录的应该是c7
                        }
                    }

                    //if (conditionAmount > 1)
                    //{
                    //    tempMrmrValue = MRMR(allNR, tempRED, colName, radius);///////////////////////////////
                    //    if (tempMrmrValue > mrmrValue)
                    //    {
                    //        mrmrValue = tempMrmrValue;
                    //        if (tempRED.Count > conditionAmount - 1)
                    //        { tempRED.RemoveAt(tempRED.Count - 1); }// Drop the last element of previous optimal RED
                    //        tempRED.Add(colName);// Update this RED now
                    //    }
                    //}
                }
                RED = tempRED;
                if (mrmrValue - bestMrmrValue > 0.001 || conditionAmount == 1)
                {
                    bestMrmrValue = mrmrValue;
                    copyTo(RED, ref bestRED);
                    Out.AppendText(bestRED + "\n");
                    ++conditionAmount;
                    flag = (RED.Count < DV.Table.Columns.Count - 1 ? false : true);// Set true while all conditions are contained in RED
                }
                else
                {
                    flag = true;
                }
            } while (flag == false);
            Out.AppendText("bestRED: " + bestRED + "\n");
        }
Пример #2
0
        private void button1_Click_1(object sender, EventArgs e)// Neighbor Reduce button
        {
            NRReduce.Enabled   = false;
            MRMRReduce.Enabled = false;

            List <double> Xi = new List <double>();
            List <double> Xj = new List <double>();
            List <string> RED = new List <string>(), tempRED = new List <string>();

            string bestRED         = "";
            string colName         = "";
            double radius          = 0.01;// threshold
            long   neighborDAmount = 0;
            long   neighborAmount  = 0;
            double NU = 0.0;
            double Pos = 0.0;
            double NR = 0.0, tempNR = 0.0, bestNR = 0.0;
            bool   flag            = false;
            int    conditionAmount = 1;// Counting the times do while loop

            do
            {
                for (int curr_col = 0; curr_col <= DV.Table.Columns.Count - 2; ++curr_col)//Except the dicision column
                {
                    Pos     = 0.0;
                    colName = DV.Table.Columns[curr_col].ColumnName;
                    if (RED.Contains(colName))
                    {
                        continue;
                    }
                    for (int selected_row = 0; selected_row <= DV.Table.Rows.Count - 1; ++selected_row)
                    {
                        neighborAmount = neighborDAmount = 0;
                        retrieveOneRow(Xi, RED, selected_row, curr_col);
                        for (int contrast_row = 0; contrast_row <= DV.Table.Rows.Count - 1; ++contrast_row)
                        {
                            retrieveOneRow(Xj, RED, contrast_row, curr_col);
                            if (euclidean_distance(Xi, Xj) <= radius * radius)
                            {// current instance is a neighbor
                                ++neighborAmount;
                                string decisionValue = DV[contrast_row][DV.Table.Columns.Count - 1].ToString();
                                if (decisionValue == DV[selected_row][DV.Table.Columns.Count - 1].ToString())// Two rows have same decision value
                                {
                                    ++neighborDAmount;
                                }
                            }
                        }
                        NU   = (neighborDAmount * 1.0) / neighborAmount;
                        Pos += NU;
                    }
                    tempNR = Pos / DV.Count;
                    if (tempNR > NR)
                    {
                        NR = tempNR;
                        if (tempRED.Count > conditionAmount - 1)// Make sure save the old optimal RED in the last do while loop
                        {
                            tempRED.RemoveAt(tempRED.Count - 1);
                        }                     // Drop the rear element of old optimal RED in the previous for(curr_col) loop
                        tempRED.Add(colName); // Update this RED now
                    }
                }
                RED = tempRED;
                if (NR - bestNR > 0.001)
                {
                    bestNR = NR;
                    copyTo(RED, ref bestRED);
                    Out.AppendText(bestRED + "\n");
                    ++conditionAmount;
                    flag = (RED.Count < DV.Table.Columns.Count - 1 ? false : true);// Set true while all conditions are contained in RED
                }
                else
                {
                    flag = true;
                }
            } while (flag == false);
            Out.AppendText("bestRED: " + bestRED + "\n");
        }