Example #1
0
        public void treeBuilding(EducationTable education_table, TreeNode tree_node)
        {
            VeryfiedClassInfo[] thisClassInfo = ClassInfoInit();
            for (int i = 0; i < education_table.Rows.Count; i++)
            {
                foreach (VeryfiedClassInfo clinf in thisClassInfo)
                {
                    if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value)
                    {
                        clinf.number_of_checked++;
                    }
                }
            }
            int k = 0;

            foreach (VeryfiedClassInfo clinf in thisClassInfo)
            {
                if (clinf.number_of_checked >= 1)
                {
                    k++;
                }
            }

            if (k >= 2)
            {
                tree_node.is_leaf = false;
                int      index_of_parametr    = 0;
                string   best_value_for_split = "";
                Parametr param = new Parametr();
                FindBetterParametr(education_table, ref index_of_parametr, ref best_value_for_split, ref param);
                tree_node.rule = new Rule();
                tree_node.rule.index_of_param = index_of_parametr;
                tree_node.rule.value          = best_value_for_split;
                tree_node.left_child          = new TreeNode();
                tree_node.right_child         = new TreeNode();
                EducationTable left_table  = new EducationTable();
                EducationTable right_table = new EducationTable();
                SplitEducationTable(education_table, tree_node.rule, param, ref left_table, ref right_table);
                treeBuilding(left_table, tree_node.left_child);
                treeBuilding(right_table, tree_node.right_child);
            }
            else
            {
                tree_node.is_leaf = true;
                tree_node.rule    = new Rule();
                foreach (VeryfiedClassInfo clinf in thisClassInfo)
                {
                    if (clinf.number_of_checked > 0)
                    {
                        tree_node.rule.value = clinf.class_name;
                    }
                }
            }
        }
Example #2
0
        private void btnBuildTree_Click(object sender, EventArgs e)
        {
            Selection selection = sqlManager.GetOneSelectionWithRequest("SELECT * FROM SELECTION WHERE NAME ='" + tvTaskSelections.SelectedNode.Text + "'");

            arrParams = sqlManager.GetParamsWithRequest("SELECT * FROM PARAM WHERE TASK_ID = (SELECT TASK_ID FROM SELECTION WHERE NAME =  '" + tvTaskSelections.SelectedNode.Text + "')");
            List <ValueParametr> arrValues   = sqlManager.GetValuesWithRequest("select * from VALUE_PARAM where SELECTION_ID=(select ID from SELECTION where NAME ='" + tvTaskSelections.SelectedNode.Text + "')");
            EducationTable       educatTable = new EducationTable(arrValues, arrParams);
            TreeNode             root        = new TreeNode();
            int root_id = 1 + sqlManager.GetMaxFeature("SELECT COUNT(1) FROM NODE", "COUNT(1)");

            treeBuilding(educatTable, root);

            SaveTreeToDB(root, root_id, selection.TaskID, selection.ID);
        }
Example #3
0
 public void SplitEducationTable(EducationTable education_table, Rule split_rule, Parametr param, ref EducationTable left_table, ref EducationTable right_table)
 {
     if ((param.Type == TypeParametr.Real) || (param.Type == TypeParametr.Int))
     {
         for (int i = 0; i < education_table.Rows.Count; i++)
         {
             double curVal   = Convert.ToDouble(education_table.Rows.ElementAt(i)[split_rule.index_of_param].Value, UsCulture);
             double splitVal = Convert.ToDouble(split_rule.value, UsCulture);
             if (curVal <= splitVal)
             {
                 right_table.Rows.Add(education_table.Rows.ElementAt(i));
             }
             else
             {
                 left_table.Rows.Add(education_table.Rows.ElementAt(i));
             }
         }
         right_table.ParameterCount = education_table.ParameterCount;
         left_table.ParameterCount  = education_table.ParameterCount;
     }
     else
     {
         for (int i = 0; i < education_table.Rows.Count; i++)
         {
             String curVal   = education_table.Rows.ElementAt(i)[split_rule.index_of_param].Value;
             String splitVal = split_rule.value;
             if (curVal == splitVal)
             {
                 right_table.Rows.Add(education_table.Rows.ElementAt(i));
             }
             else
             {
                 left_table.Rows.Add(education_table.Rows.ElementAt(i));
             }
         }
         right_table.ParameterCount = education_table.ParameterCount;
         left_table.ParameterCount  = education_table.ParameterCount;
     }
 }
Example #4
0
        public void FindBetterParametr(EducationTable education_table,ref int index_of_parametr,ref string best_value_for_split, ref Parametr _param)
        {
            index_of_parametr = 0;
            best_value_for_split = "";
            VeryfiedClassInfo[] leftClassInf = ClassInfoInit();
            VeryfiedClassInfo[] rightClassInf = ClassInfoInit();
            Parametr param;
            double giniValue = -100000;
            for(int index = 1; index < education_table.ParameterCount; index++)
            {
                param = sqlManager.GetOneParametrWithRequest("SELECT * FROM PARAM WHERE ID ='" + education_table.Rows.ElementAt(1)[index].ParametrID + "'");
                education_table.BubbleSortByParam(index, param);

                if ((param.Type == TypeParametr.Real) || (param.Type == TypeParametr.Int))
                {
                    double average = 0;
                    for (int prevRowInd = 1, nextRowInd = 2; nextRowInd < education_table.Rows.Count; prevRowInd++, nextRowInd++)
                    {
                        average = (Convert.ToDouble(education_table.Rows.ElementAt(prevRowInd)[index].Value, UsCulture) + Convert.ToDouble(education_table.Rows.ElementAt(nextRowInd)[index].Value, UsCulture)) / 2.0;
                        for (int i = 0; i < education_table.Rows.Count; i++)
                        {
                            if (Convert.ToDouble(education_table.Rows.ElementAt(i)[index].Value, UsCulture) <= average)
                            {
                                foreach (VeryfiedClassInfo clinf in rightClassInf)
                                {
                                    if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value)
                                    {
                                        clinf.number_of_checked++;
                                    }
                                }
                            }
                            else
                            {
                                foreach (VeryfiedClassInfo clinf in leftClassInf)
                                {
                                    if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value)
                                    {
                                        clinf.number_of_checked++;
                                    }
                                }
                            }
                        }
                        double newGiniValue = GiniSplitCalc(leftClassInf, rightClassInf);
                        if (newGiniValue > giniValue)
                        {
                            giniValue = newGiniValue;
                            index_of_parametr = index;
                            best_value_for_split = average.ToString(UsCulture);
                            _param = param;
                        }
                        for (int i = 0; i < leftClassInf.Length; i++)
                        {
                            leftClassInf[i].number_of_checked = 0;
                            rightClassInf[i].number_of_checked = 0;
                        }
                    }

                }
                else
                {
                    //param.Range
                    int number_of_var = 0;
                    for (int i = 0; i < param.Range.Length; i++)
                    {
                        if (param.Range[i] == '|')
                            number_of_var++;
                    }

                    String[] variables = new String[number_of_var + 1];
                    for (int i = 0, j = 0; i < param.Range.Length; i++)
                    {
                        if (param.Range[i] == '|')
                        {
                            j++;
                            continue;
                        }
                        if (param.Range[i] != ' ')
                            variables[j]+= param.Range[i];
                    }

                    for (int j = 0; j < number_of_var; j++)
                    {
                        for (int i = 0; i < education_table.Rows.Count; i++)
                        {
                            if (education_table.Rows.ElementAt(i)[index].Value == variables[j])
                            {
                                foreach (VeryfiedClassInfo clinf in rightClassInf)
                                {
                                    if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value)
                                    {
                                        clinf.number_of_checked++;
                                    }
                                }
                            }
                            else
                            {
                                foreach (VeryfiedClassInfo clinf in leftClassInf)
                                {
                                    if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value)
                                    {
                                        clinf.number_of_checked++;
                                    }
                                }
                            }
                        }
                        double newGiniValue = GiniSplitCalc(leftClassInf, rightClassInf);
                        if (newGiniValue > giniValue)
                        {
                            giniValue = newGiniValue;
                            index_of_parametr = index;
                            best_value_for_split = variables[j];
                            _param = param;
                        }
                        for (int i = 0; i < leftClassInf.Length; i++)
                        {
                            leftClassInf[i].number_of_checked = 0;
                            rightClassInf[i].number_of_checked = 0;
                        }
                    }
                }
            }
        }
Example #5
0
        private void btnBuildTree_Click(object sender, EventArgs e)
        {
            Selection selection = sqlManager.GetOneSelectionWithRequest("SELECT * FROM SELECTION WHERE NAME ='"+tvTaskSelections.SelectedNode.Text+"'");
            arrParams = sqlManager.GetParamsWithRequest("SELECT * FROM PARAM WHERE TASK_ID = (SELECT TASK_ID FROM SELECTION WHERE NAME =  '" + tvTaskSelections.SelectedNode.Text + "')");
            List<ValueParametr> arrValues = sqlManager.GetValuesWithRequest("select * from VALUE_PARAM where SELECTION_ID=(select ID from SELECTION where NAME ='" + tvTaskSelections.SelectedNode.Text + "')");
            EducationTable educatTable = new EducationTable(arrValues, arrParams);
            TreeNode root = new TreeNode();
            int root_id = 1 + sqlManager.GetMaxFeature("SELECT COUNT(1) FROM NODE","COUNT(1)");
            treeBuilding(educatTable, root);

            SaveTreeToDB(root, root_id, selection.TaskID, selection.ID);
        }
Example #6
0
        public void treeBuilding(EducationTable education_table, TreeNode tree_node)
        {
            VeryfiedClassInfo[] thisClassInfo = ClassInfoInit();
            for (int i = 0; i < education_table.Rows.Count; i++)
            {
                foreach (VeryfiedClassInfo clinf in thisClassInfo)
                {
                    if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value)
                    {
                        clinf.number_of_checked++;
                    }
                }
            }
            int k = 0;
            foreach (VeryfiedClassInfo clinf in thisClassInfo)
            {
                if (clinf.number_of_checked >= 1)
                {
                    k++;
                }
            }

            if (k >= 2)
            {
                tree_node.is_leaf = false;
                int index_of_parametr = 0;
                string best_value_for_split = "";
                Parametr param = new Parametr();
                FindBetterParametr(education_table, ref index_of_parametr, ref best_value_for_split, ref param);
                tree_node.rule = new Rule();
                tree_node.rule.index_of_param = index_of_parametr;
                tree_node.rule.value = best_value_for_split;
                tree_node.left_child = new TreeNode();
                tree_node.right_child = new TreeNode();
                EducationTable left_table = new EducationTable();
                EducationTable right_table = new EducationTable();
                SplitEducationTable(education_table, tree_node.rule, param, ref left_table, ref right_table);
                treeBuilding(left_table, tree_node.left_child);
                treeBuilding(right_table, tree_node.right_child);

            }
            else
            {
                tree_node.is_leaf = true;
                tree_node.rule = new Rule();
                foreach (VeryfiedClassInfo clinf in thisClassInfo)
                {
                    if (clinf.number_of_checked > 0)
                    {
                        tree_node.rule.value = clinf.class_name;
                    }
                }

            }
        }
Example #7
0
 public void SplitEducationTable(EducationTable education_table,Rule split_rule,Parametr param, ref EducationTable left_table, ref EducationTable right_table)
 {
     if ((param.Type == TypeParametr.Real) || (param.Type == TypeParametr.Int))
     {
         for (int i = 0; i < education_table.Rows.Count; i++)
         {
             double curVal = Convert.ToDouble(education_table.Rows.ElementAt(i)[split_rule.index_of_param].Value, UsCulture);
             double splitVal = Convert.ToDouble(split_rule.value, UsCulture);
             if (curVal <= splitVal)
             {
                 right_table.Rows.Add(education_table.Rows.ElementAt(i));
             }
             else
             {
                 left_table.Rows.Add(education_table.Rows.ElementAt(i));
             }
         }
         right_table.ParameterCount = education_table.ParameterCount;
         left_table.ParameterCount = education_table.ParameterCount;
     }
     else
     {
         for (int i = 0; i < education_table.Rows.Count; i++)
         {
             String curVal = education_table.Rows.ElementAt(i)[split_rule.index_of_param].Value;
             String splitVal = split_rule.value;
             if (curVal == splitVal)
             {
                 right_table.Rows.Add(education_table.Rows.ElementAt(i));
             }
             else
             {
                 left_table.Rows.Add(education_table.Rows.ElementAt(i));
             }
         }
         right_table.ParameterCount = education_table.ParameterCount;
         left_table.ParameterCount = education_table.ParameterCount;
     }
 }
Example #8
0
        public void FindBetterParametr(EducationTable education_table, ref int index_of_parametr, ref string best_value_for_split, ref Parametr _param)
        {
            index_of_parametr    = 0;
            best_value_for_split = "";
            VeryfiedClassInfo[] leftClassInf  = ClassInfoInit();
            VeryfiedClassInfo[] rightClassInf = ClassInfoInit();
            Parametr            param;
            double giniValue = -100000;

            for (int index = 1; index < education_table.ParameterCount; index++)
            {
                param = sqlManager.GetOneParametrWithRequest("SELECT * FROM PARAM WHERE ID ='" + education_table.Rows.ElementAt(1)[index].ParametrID + "'");
                education_table.BubbleSortByParam(index, param);

                if ((param.Type == TypeParametr.Real) || (param.Type == TypeParametr.Int))
                {
                    double average = 0;
                    for (int prevRowInd = 1, nextRowInd = 2; nextRowInd < education_table.Rows.Count; prevRowInd++, nextRowInd++)
                    {
                        average = (Convert.ToDouble(education_table.Rows.ElementAt(prevRowInd)[index].Value, UsCulture) + Convert.ToDouble(education_table.Rows.ElementAt(nextRowInd)[index].Value, UsCulture)) / 2.0;
                        for (int i = 0; i < education_table.Rows.Count; i++)
                        {
                            if (Convert.ToDouble(education_table.Rows.ElementAt(i)[index].Value, UsCulture) <= average)
                            {
                                foreach (VeryfiedClassInfo clinf in rightClassInf)
                                {
                                    if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value)
                                    {
                                        clinf.number_of_checked++;
                                    }
                                }
                            }
                            else
                            {
                                foreach (VeryfiedClassInfo clinf in leftClassInf)
                                {
                                    if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value)
                                    {
                                        clinf.number_of_checked++;
                                    }
                                }
                            }
                        }
                        double newGiniValue = GiniSplitCalc(leftClassInf, rightClassInf);
                        if (newGiniValue > giniValue)
                        {
                            giniValue            = newGiniValue;
                            index_of_parametr    = index;
                            best_value_for_split = average.ToString(UsCulture);
                            _param = param;
                        }
                        for (int i = 0; i < leftClassInf.Length; i++)
                        {
                            leftClassInf[i].number_of_checked  = 0;
                            rightClassInf[i].number_of_checked = 0;
                        }
                    }
                }
                else
                {
                    //param.Range
                    int number_of_var = 0;
                    for (int i = 0; i < param.Range.Length; i++)
                    {
                        if (param.Range[i] == '|')
                        {
                            number_of_var++;
                        }
                    }

                    String[] variables = new String[number_of_var + 1];
                    for (int i = 0, j = 0; i < param.Range.Length; i++)
                    {
                        if (param.Range[i] == '|')
                        {
                            j++;
                            continue;
                        }
                        if (param.Range[i] != ' ')
                        {
                            variables[j] += param.Range[i];
                        }
                    }

                    for (int j = 0; j < number_of_var; j++)
                    {
                        for (int i = 0; i < education_table.Rows.Count; i++)
                        {
                            if (education_table.Rows.ElementAt(i)[index].Value == variables[j])
                            {
                                foreach (VeryfiedClassInfo clinf in rightClassInf)
                                {
                                    if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value)
                                    {
                                        clinf.number_of_checked++;
                                    }
                                }
                            }
                            else
                            {
                                foreach (VeryfiedClassInfo clinf in leftClassInf)
                                {
                                    if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value)
                                    {
                                        clinf.number_of_checked++;
                                    }
                                }
                            }
                        }
                        double newGiniValue = GiniSplitCalc(leftClassInf, rightClassInf);
                        if (newGiniValue > giniValue)
                        {
                            giniValue            = newGiniValue;
                            index_of_parametr    = index;
                            best_value_for_split = variables[j];
                            _param = param;
                        }
                        for (int i = 0; i < leftClassInf.Length; i++)
                        {
                            leftClassInf[i].number_of_checked  = 0;
                            rightClassInf[i].number_of_checked = 0;
                        }
                    }
                }
            }
        }